57 return g_markingMutex;
65 static bool firstTime =
true;
99 std::string::size_type
n = s.find_first_not_of (
"+-0123456789.eE");
100 if (
n != std::string::npos)
102 std::istringstream iss;
103 iss.str (s.substr (0,
n));
106 std::string trailer = s.substr (
n, std::string::npos);
107 if (trailer == std::string (
"s"))
111 else if (trailer == std::string (
"ms"))
115 else if (trailer == std::string (
"us"))
119 else if (trailer == std::string (
"ns"))
123 else if (trailer == std::string (
"ps"))
127 else if (trailer == std::string (
"fs"))
131 else if (trailer == std::string (
"min"))
135 else if (trailer == std::string (
"h"))
139 else if (trailer == std::string (
"d"))
143 else if (trailer == std::string (
"y"))
155 std::istringstream iss;
170 Time::SetDefaultNsResolution (void)
201 const int8_t power [
LAST] = { 17, 17, 17, 16, 15, 12, 9, 6, 3, 0 };
202 const int32_t coefficient [
LAST] = { 315360, 864, 36, 6, 1, 1, 1, 1, 1, 1 };
205 int shift = power[i] - power[(int)unit];
207 if (coefficient[i] > coefficient[(
int) unit])
209 quotient = coefficient[i] / coefficient[(int) unit];
210 NS_ASSERT (quotient * coefficient[(
int) unit] == coefficient[i]);
212 else if (coefficient[i] < coefficient[(
int) unit])
214 quotient = coefficient[(int) unit] / coefficient[i];
215 NS_ASSERT (quotient * coefficient[i] == coefficient[(
int) unit]);
217 NS_LOG_DEBUG (
"SetResolution for unit " << (
int) unit <<
" loop iteration " << i
218 <<
" has shift " << shift <<
" has quotient " << quotient);
219 int64_t factor =
static_cast<int64_t
> (std::pow (10, std::fabs (shift)) * quotient);
220 double realFactor = std::pow (10, (
double) shift)
221 *
static_cast<double> (coefficient[i]) / coefficient[(
int) unit];
222 NS_LOG_DEBUG (
"SetResolution factor " << factor <<
" real factor " << realFactor);
227 if (shift == 0 && quotient == 1)
234 else if (realFactor > 1)
250 resolution->
unit = unit;
298 std::pair< MarkedTimes::iterator, bool> ret;
303 if (ret.second ==
false)
323 "Time object " << time <<
325 " times (should be 1)." );
330 NS_LOG_WARN (
"unexpected result erasing " << time <<
"!");
350 "No MarkedTimes registry. " 351 "Time::SetResolution () called more than once?");
357 Time *
const tp = *it;
409 case Time::Y: unit =
"y";
break;
410 case Time::D: unit =
"d";
break;
411 case Time::H: unit =
"h";
break;
413 case Time::S: unit =
"s";
break;
423 unit =
"unreachable";
452 Checker (
const Time minValue,
const Time maxValue)
453 : m_minValue (minValue),
454 m_maxValue (maxValue) {}
462 return v->
Get () >= m_minValue && v->
Get () <= m_maxValue;
464 virtual std::string GetValueTypeName (
void)
const {
466 return "ns3::TimeValue";
468 virtual bool HasUnderlyingTypeInformation (
void)
const {
472 virtual std::string GetUnderlyingTypeInformation (
void)
const {
474 std::ostringstream oss;
475 oss <<
"Time" <<
" " << m_minValue <<
":" << m_maxValue;
480 return ns3::Create<TimeValue> ();
486 if (src == 0 || dst == 0)
495 } *checker =
new Checker (
min,
max);
static struct Resolution * PeekResolution(void)
Get the current Resolution.
std::istream & operator>>(std::istream &is, Angles &a)
initialize a struct Angles from input
Represent the type of an attribute.
Simulation virtual time values and global simulation resolution.
Smart pointer class similar to boost::intrusive_ptr.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
A Time with attached unit, to facilitate output in that unit.
int64_t ToInteger(enum Unit unit) const
Get the Time value expressed in a particular unit.
Hold a value for an Attribute.
High precision numerical type, implementing Q64.64 fixed precision.
static int64x64_t Invert(const uint64_t v)
Compute the inverse of an integer value.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
TimeWithUnit As(const enum Unit unit) const
Attach a unit to a Time, to facilitate output in a specific unit.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
struct Information info[LAST]
Conversion info from current unit.
#define ATTRIBUTE_VALUE_IMPLEMENT(type)
Define the class methods belonging to attribute value class typeValue for class type.
System-independent mutex primitive, ns3::SystemMutex, and ns3::CriticalSection.
static enum Unit GetResolution(void)
AttributeValue implementation for Time.
Current time unit, and conversion info.
static bool StaticInit()
Function to force static initialization of Time.
A class which provides a simple way to implement a Critical Section.
Unit
The unit to use to interpret a number representing time.
static void ConvertTimes(const enum Unit unit)
Convert existing Times to the new unit.
#define NS_LOG_COMPONENT_DEFINE_MASK(name, mask)
Define a logging component with a mask.
Declaration of classes ns3::Time and ns3::TimeWithUnit, and the TimeValue implementation classes...
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
SystemMutex & GetMarkingMutex()
Prefix all trace prints with simulation time.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< T > Create(void)
Create class instances by constructors with varying numbers of arguments and return them by Ptr...
Time()
Default constructor, with value 0.
A class which provides a relatively platform-independent Mutual Exclusion thread synchronization prim...
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
static Time FromDouble(double value, enum Unit unit)
Create a Time equal to value in unit unit.
static void Mark(Time *const time)
Record a Time instance with the MarkedTimes.
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
enum Time::Unit unit
Current time unit.
Time::Unit m_unit
The unit to use in output.
static void SetResolution(enum Unit resolution)
int64x64_t To(enum Unit unit) const
Get the Time value expressed in a particular unit.
static void Clear(Time *const time)
Remove a Time instance from the MarkedTimes, called by ~Time().
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
std::set< Time *> MarkedTimes
Record all instances of Time, so we can rescale them when the resolution changes. ...
static MarkedTimes * g_markingTimes
Record of outstanding Time objects which will need conversion when the resolution is set...
static void ClearMarkedTimes()
Remove all MarkedTimes.
Ptr< T > Copy(Ptr< T > object)
Return a deep copy of a Ptr.
int64_t m_data
Virtual time value, in the current unit.
NS_ABORT_x macro definitions.