52 return g_markingMutex;
60 static bool firstTime =
true;
94 std::string::size_type n = s.find_first_not_of (
"+-0123456789.");
95 if (n != std::string::npos)
97 std::istringstream iss;
98 iss.str (s.substr (0, n));
101 std::string trailer = s.substr (n, std::string::npos);
102 if (trailer == std::string (
"s"))
106 else if (trailer == std::string (
"ms"))
110 else if (trailer == std::string (
"us"))
114 else if (trailer == std::string (
"ns"))
118 else if (trailer == std::string (
"ps"))
122 else if (trailer == std::string (
"fs"))
126 else if (trailer == std::string (
"min"))
130 else if (trailer == std::string (
"h"))
134 else if (trailer == std::string (
"d"))
138 else if (trailer == std::string (
"y"))
150 std::istringstream iss;
165 Time::SetDefaultNsResolution (void)
196 const int8_t power [
LAST] = { 17, 17, 17, 16, 15, 12, 9, 6, 3, 0 };
197 const int32_t coefficient [
LAST] = { 315360, 864, 36, 6, 1, 1, 1, 1, 1, 1 };
200 int shift = power[i] - power[(int)unit];
202 if (coefficient[i] > coefficient[(
int) unit])
204 quotient = coefficient[i] / coefficient[(int) unit];
205 NS_ASSERT (quotient * coefficient[(
int) unit] == coefficient[i]);
207 else if (coefficient[i] < coefficient[(
int) unit])
209 quotient = coefficient[(int) unit] / coefficient[i];
210 NS_ASSERT (quotient * coefficient[i] == coefficient[(
int) unit]);
212 NS_LOG_DEBUG (
"SetResolution for unit " << (
int) unit <<
" loop iteration " << i
213 <<
" has shift " << shift <<
" has quotient " << quotient);
214 int64_t factor =
static_cast<int64_t
> (std::pow (10, std::fabs (shift)) * quotient);
215 double realFactor = std::pow (10, (
double) shift)
216 *
static_cast<double> (coefficient[i]) / coefficient[(
int) unit];
217 NS_LOG_DEBUG (
"SetResolution factor " << factor <<
" real factor " << realFactor);
222 if (shift == 0 && quotient == 1)
225 info->
timeTo = int64x64_t (1);
229 else if (realFactor > 1)
231 info->
timeFrom = int64x64_t (factor);
232 info->
timeTo = int64x64_t::Invert (factor);
239 info->
timeFrom = int64x64_t::Invert (factor);
240 info->
timeTo = int64x64_t (factor);
245 resolution->
unit = unit;
293 std::pair< MarkedTimes::iterator, bool> ret;
298 if (ret.second ==
false)
318 "Time object " << time <<
320 " times (should be 1)." );
325 NS_LOG_WARN (
"unexpected result erasing " << time <<
"!");
345 "No MarkedTimes registry. "
346 "Time::SetResolution () called more than once?");
352 Time *
const tp = *it;
353 if ( ! ( (tp->
m_data == std::numeric_limits<int64_t>::min ())
354 || (tp->
m_data == std::numeric_limits<int64_t>::max ())
421 unit =
"unreachable";
426 std::ios_base::fmtflags ff = os.flags ();
437 os << v <<
".0" << unit;
451 Ptr<const AttributeChecker>
458 Checker (
const Time minValue,
const Time maxValue)
459 : m_minValue (minValue),
460 m_maxValue (maxValue) {}
468 return v->
Get () >= m_minValue && v->
Get () <= m_maxValue;
470 virtual std::string GetValueTypeName (
void)
const {
472 return "ns3::TimeValue";
474 virtual bool HasUnderlyingTypeInformation (
void)
const {
478 virtual std::string GetUnderlyingTypeInformation (
void)
const {
480 std::ostringstream oss;
481 oss <<
"Time" <<
" " << m_minValue <<
":" << m_maxValue;
486 return ns3::Create<TimeValue> ();
492 if (src == 0 || dst == 0)
501 } *checker =
new Checker (min, max);
static struct Resolution * PeekResolution(void)
std::istream & operator>>(std::istream &is, Angles &a)
initialize a struct Angles from input
Represent the type of an attribute.
keep track of time values and allow control of global simulation resolution
smart pointer class similar to boost::intrusive_ptr
#define NS_LOG_FUNCTION(parameters)
Hold a value for an Attribute.
int64_t ToInteger(enum Unit timeUnit) const
#define NS_ASSERT(condition)
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
static Time FromDouble(double value, enum Unit timeUnit)
struct Information info[LAST]
Conversion info from current unit.
NS_LOG_COMPONENT_DEFINE("Time")
static enum Unit GetResolution(void)
hold 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_LOGIC(msg)
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
SystemMutex & GetMarkingMutex()
Get mutex for critical sections around modification of Time::g_markingTimes.
A class which provides a relatively platform-independent Mutual Exclusion thread synchronization prim...
#define NS_ASSERT_MSG(condition, message)
ATTRIBUTE_VALUE_IMPLEMENT(RandomVariable)
static void Mark(Time *const time)
Record a Time instance with the MarkedTimes.
#define NS_ABORT_MSG(msg)
Abnormal program termination.
#define NS_LOG_DEBUG(msg)
enum Time::Unit unit
Current time unit.
static void SetResolution(enum Unit resolution)
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
static void Clear(Time *const time)
Remove a Time instance from the MarkedTimes, called by ~Time()
#define NS_LOG_ERROR(msg)
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.