55 return g_markingMutex;
63 static bool firstTime =
true;
97 std::string::size_type n = s.find_first_not_of (
"+-0123456789.");
98 if (n != std::string::npos)
100 std::istringstream iss;
101 iss.str (s.substr (0, n));
104 std::string trailer = s.substr (n, std::string::npos);
105 if (trailer == std::string (
"s"))
109 else if (trailer == std::string (
"ms"))
113 else if (trailer == std::string (
"us"))
117 else if (trailer == std::string (
"ns"))
121 else if (trailer == std::string (
"ps"))
125 else if (trailer == std::string (
"fs"))
129 else if (trailer == std::string (
"min"))
133 else if (trailer == std::string (
"h"))
137 else if (trailer == std::string (
"d"))
141 else if (trailer == std::string (
"y"))
153 std::istringstream iss;
168 Time::SetDefaultNsResolution (void)
199 const int8_t power [
LAST] = { 17, 17, 17, 16, 15, 12, 9, 6, 3, 0 };
200 const int32_t coefficient [
LAST] = { 315360, 864, 36, 6, 1, 1, 1, 1, 1, 1 };
203 int shift = power[i] - power[(int)unit];
205 if (coefficient[i] > coefficient[(
int) unit])
207 quotient = coefficient[i] / coefficient[(int) unit];
208 NS_ASSERT (quotient * coefficient[(
int) unit] == coefficient[i]);
210 else if (coefficient[i] < coefficient[(
int) unit])
212 quotient = coefficient[(int) unit] / coefficient[i];
213 NS_ASSERT (quotient * coefficient[i] == coefficient[(
int) unit]);
215 NS_LOG_DEBUG (
"SetResolution for unit " << (
int) unit <<
" loop iteration " << i
216 <<
" has shift " << shift <<
" has quotient " << quotient);
217 int64_t factor =
static_cast<int64_t
> (std::pow (10, std::fabs (shift)) * quotient);
218 double realFactor = std::pow (10, (
double) shift)
219 *
static_cast<double> (coefficient[i]) / coefficient[(
int) unit];
220 NS_LOG_DEBUG (
"SetResolution factor " << factor <<
" real factor " << realFactor);
225 if (shift == 0 && quotient == 1)
232 else if (realFactor > 1)
248 resolution->
unit = unit;
296 std::pair< MarkedTimes::iterator, bool> ret;
301 if (ret.second ==
false)
321 "Time object " << time <<
323 " times (should be 1)." );
328 NS_LOG_WARN (
"unexpected result erasing " << time <<
"!");
348 "No MarkedTimes registry. "
349 "Time::SetResolution () called more than once?");
355 Time *
const tp = *it;
356 if ( ! ( (tp->
m_data == std::numeric_limits<int64_t>::min ())
357 || (tp->
m_data == std::numeric_limits<int64_t>::max ())
407 case Time::Y: unit =
"y";
break;
408 case Time::D: unit =
"d";
break;
409 case Time::H: unit =
"h";
break;
411 case Time::S: unit =
"s";
break;
421 unit =
"unreachable";
443 Ptr<const AttributeChecker>
450 Checker (
const Time minValue,
const Time maxValue)
451 : m_minValue (minValue),
452 m_maxValue (maxValue) {}
460 return v->
Get () >= m_minValue && v->
Get () <= m_maxValue;
462 virtual std::string GetValueTypeName (
void)
const {
464 return "ns3::TimeValue";
466 virtual bool HasUnderlyingTypeInformation (
void)
const {
470 virtual std::string GetUnderlyingTypeInformation (
void)
const {
472 std::ostringstream oss;
473 oss <<
"Time" <<
" " << m_minValue <<
":" << m_maxValue;
478 return ns3::Create<TimeValue> ();
484 if (src == 0 || dst == 0)
493 } *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)
Abnormal program termination.
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...
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
int64x64_t To(enum Unit unit) const
Get the Time value expressed in a particular 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.
static enum Unit GetResolution(void)
Attribute for objects of type ns3::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.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
SystemMutex & GetMarkingMutex()
prefix all trace prints with simulation time
Time()
Default constructor, with value 0.
A class which provides a relatively platform-independent Mutual Exclusion thread synchronization prim...
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
ATTRIBUTE_VALUE_IMPLEMENT(RandomVariable)
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.
TimeWithUnit As(const enum Unit unit) const
Attach a unit to a Time, to facilitate output in a specific unit.
#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)
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)
int64_t m_data
Virtual time value, in the current unit.