69 for (
auto u =
static_cast<int> (
Time::Y); u !=
static_cast<int> (
Time::LAST); ++u)
100 return g_markingMutex;
108 static bool firstTime =
true;
142 std::string::size_type
n = s.find_first_not_of (
"+-0123456789.eE");
143 if (
n != std::string::npos)
145 std::istringstream iss;
146 iss.str (s.substr (0,
n));
149 std::string trailer = s.substr (
n, std::string::npos);
150 if (trailer == std::string (
"s"))
154 else if (trailer == std::string (
"ms"))
158 else if (trailer == std::string (
"us"))
162 else if (trailer == std::string (
"ns"))
166 else if (trailer == std::string (
"ps"))
170 else if (trailer == std::string (
"fs"))
174 else if (trailer == std::string (
"min"))
178 else if (trailer == std::string (
"h"))
182 else if (trailer == std::string (
"d"))
186 else if (trailer == std::string (
"y"))
198 std::istringstream iss;
213 Time::SetDefaultNsResolution (void)
216 struct Resolution resolution;
257 NS_LOG_DEBUG (
"SetResolution for unit " << (
int) unit <<
258 " loop iteration " << i <<
259 " has shift " << shift <<
" has quotient " << quotient);
260 int64_t factor =
static_cast<int64_t
> (std::pow (10, std::fabs (shift)) * quotient);
261 double realFactor = std::pow (10, (
double) shift)
263 NS_LOG_DEBUG (
"SetResolution factor " << factor <<
" real factor " << realFactor);
268 if (shift == 0 && quotient == 1)
275 else if (realFactor > 1)
291 resolution->
unit = unit;
339 std::pair< MarkedTimes::iterator, bool> ret;
344 if (ret.second ==
false)
364 "Time object " << time <<
366 " times (should be 1)." );
371 NS_LOG_WARN (
"unexpected result erasing " << time <<
"!");
391 "No MarkedTimes registry. "
392 "Time::SetResolution () called more than once?");
398 Time *
const tp = *it;
471 case Time::Y: label =
"y";
break;
472 case Time::D: label =
"d";
break;
473 case Time::H: label =
"h";
break;
475 case Time::S: label =
"s";
break;
487 label =
"unreachable";
499 std::ios_base::fmtflags ff = os.flags ();
501 os << std::showpos << std::right << v << label;
504 if (!(ff & std::ios_base::showpos))
506 os << std::noshowpos;
508 if (ff & std::ios_base::left)
512 else if (ff & std::ios_base::internal)
539 Checker (
const Time minValue,
const Time maxValue)
540 : m_minValue (minValue),
541 m_maxValue (maxValue)
551 return v->
Get () >= m_minValue && v->
Get () <= m_maxValue;
553 virtual std::string GetValueTypeName (
void)
const
556 return "ns3::TimeValue";
558 virtual bool HasUnderlyingTypeInformation (
void)
const
563 virtual std::string GetUnderlyingTypeInformation (
void)
const
566 std::ostringstream oss;
567 oss <<
"Time" <<
" " << m_minValue <<
":" << m_maxValue;
573 return ns3::Create<TimeValue> ();
580 if (src == 0 || dst == 0)
589 } *checker =
new Checker (
min,
max);
NS_ABORT_x macro definitions.
Represent the type of an attribute.
Hold a value for an Attribute.
A class which provides a simple way to implement a Critical Section.
Smart pointer class similar to boost::intrusive_ptr.
A class which provides a relatively platform-independent Mutual Exclusion thread synchronization prim...
Simulation virtual time values and global simulation resolution.
static enum Unit GetResolution(void)
double ToDouble(enum Unit unit) const
Get the Time value expressed in a particular unit.
static void ClearMarkedTimes()
Remove all MarkedTimes.
int64_t GetTimeStep(void) const
Get the raw time value, in the current resolution unit.
int64_t ToInteger(enum Unit unit) const
Get the Time value expressed in a particular unit.
static Time FromDouble(double value, enum Unit unit)
Create a Time equal to value in unit unit.
static bool StaticInit()
Function to force static initialization of Time.
static void Clear(Time *const time)
Remove a Time instance from the MarkedTimes, called by ~Time().
Unit
The unit to use to interpret a number representing time.
@ AUTO
auto-scale output when using Time::As()
@ LAST
marker for last normal value
Time()
Default constructor, with value 0.
static struct Resolution * PeekResolution(void)
Get the current Resolution.
static MarkedTimes * g_markingTimes
Record of outstanding Time objects which will need conversion when the resolution is set.
int64_t m_data
Virtual time value, in the current unit.
static void Mark(Time *const time)
Record a Time instance with the MarkedTimes.
static void ConvertTimes(const enum Unit unit)
Convert existing Times to the new unit.
static void SetResolution(enum Unit resolution)
TimeWithUnit As(const enum Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
std::set< Time * > MarkedTimes
Record all instances of Time, so we can rescale them when the resolution changes.
SystemMutex & GetMarkingMutex()
AttributeValue implementation for Time.
A Time with attached unit, to facilitate output in that unit.
Time::Unit m_unit
The unit to use in output.
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,...
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
#define ATTRIBUTE_VALUE_IMPLEMENT(type)
Define the class methods belonging to attribute value class typeValue for class type.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
#define NS_LOG_COMPONENT_DEFINE_MASK(name, mask)
Define a logging component with a mask.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Ptr< T > Create(Ts... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
const long double * UNIT_VALUE
Value of each unit, in terms of the smallest defined unit.
const int32_t UNIT_COEFF[Time::LAST]
Scaling coefficient, relative to smallest unit.
const int8_t UNIT_POWER[Time::LAST]
Scaling coefficients, exponents, and look up table for unit.
long double * InitUnitValue(void)
Initializer for UNIT_VALUE.
long double Scale(Time::Unit u)
Scale a unit to the smallest unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double max(double x, double y)
double min(double x, double y)
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Ptr< T > Copy(Ptr< T > object)
Return a deep copy of a Ptr.
@ LOG_PREFIX_TIME
Prefix all trace prints with simulation time.
std::istream & operator>>(std::istream &is, Angles &a)
std::ostream & operator<<(std::ostream &os, const Angles &a)
Declaration of classes ns3::Time and ns3::TimeWithUnit, and the TimeValue implementation classes.
Current time unit, and conversion info.
struct Information info[LAST]
Conversion info from current unit.
enum Time::Unit unit
Current time unit.
System-independent mutex primitive, ns3::SystemMutex, and ns3::CriticalSection.