|
Lines 297-302
TimeUnit<N> Min (TimeUnit<N> const &ta,
|
Link Here
|
|---|
|
| 297 |
HighPrecision b = tb.GetHighPrecision (); |
297 |
HighPrecision b = tb.GetHighPrecision (); |
| 298 |
return TimeUnit<N> (Max (a, b)); |
298 |
return TimeUnit<N> (Max (a, b)); |
| 299 |
} |
299 |
} |
|
|
300 |
|
| 301 |
// Explicit instatiation of the TimeUnit template for N=1, with a few |
| 302 |
// additional methods that should not be available for N!=1 |
| 303 |
|
| 304 |
template <> |
| 305 |
class TimeUnit<1> |
| 306 |
{ |
| 307 |
// -*- New methods -*- |
| 308 |
public: |
| 309 |
|
| 310 |
/** |
| 311 |
* \returns an approximation in seconds of the time stored in this |
| 312 |
* instance. |
| 313 |
*/ |
| 314 |
double GetSeconds (void) const; |
| 315 |
/** |
| 316 |
* \returns an approximation in milliseconds of the time stored in this |
| 317 |
* instance. |
| 318 |
*/ |
| 319 |
int32_t GetMilliSeconds (void) const; |
| 320 |
/** |
| 321 |
* \returns an approximation in microseconds of the time stored in this |
| 322 |
* instance. |
| 323 |
*/ |
| 324 |
int64_t GetMicroSeconds (void) const; |
| 325 |
/** |
| 326 |
* \returns an approximation in nanoseconds of the time stored in this |
| 327 |
* instance. |
| 328 |
*/ |
| 329 |
int64_t GetNanoSeconds (void) const; |
| 330 |
|
| 331 |
// -*- The rest is the the same as in the generic template class -*- |
| 332 |
public: |
| 333 |
TimeUnit () |
| 334 |
: m_data () |
| 335 |
{} |
| 336 |
TimeUnit (TimeUnit const &o) |
| 337 |
: m_data (o.m_data) {} |
| 338 |
TimeUnit operator = (TimeUnit const &o) { |
| 339 |
m_data = o.m_data; |
| 340 |
return *this; |
| 341 |
} |
| 342 |
TimeUnit (HighPrecision data) |
| 343 |
: m_data (data) {} |
| 344 |
bool IsZero (void) const { |
| 345 |
return m_data.Compare (HighPrecision::Zero ()) == 0; |
| 346 |
} |
| 347 |
bool IsNegative (void) const { |
| 348 |
return m_data.Compare (HighPrecision::Zero ()) <= 0; |
| 349 |
} |
| 350 |
bool IsPositive (void) const { |
| 351 |
return m_data.Compare (HighPrecision::Zero ()) >= 0; |
| 352 |
} |
| 353 |
bool IsStrictlyNegative (void) const { |
| 354 |
return m_data.Compare (HighPrecision::Zero ()) < 0; |
| 355 |
} |
| 356 |
bool IsStrictlyPositive (void) const { |
| 357 |
return m_data.Compare (HighPrecision::Zero ()) > 0; |
| 358 |
} |
| 359 |
HighPrecision const &GetHighPrecision (void) const { |
| 360 |
return m_data; |
| 361 |
} |
| 362 |
HighPrecision *PeekHighPrecision (void) { |
| 363 |
return &m_data; |
| 364 |
} |
| 365 |
private: |
| 366 |
HighPrecision m_data; |
| 367 |
}; |
| 300 |
|
368 |
|
| 301 |
/** |
369 |
/** |
| 302 |
* \brief keep track of seconds. |
370 |
* \brief keep track of seconds. |
|
Lines 323-356
TimeUnit<N> Min (TimeUnit<N> const &ta,
|
Link Here
|
|---|
|
| 323 |
* - \ref ns3-Time-Max ns3::Max |
391 |
* - \ref ns3-Time-Max ns3::Max |
| 324 |
* - \ref ns3-Time-Min ns3::Min |
392 |
* - \ref ns3-Time-Min ns3::Min |
| 325 |
*/ |
393 |
*/ |
| 326 |
class Time : public TimeUnit<1> |
394 |
typedef TimeUnit<1> Time; |
| 327 |
{ |
395 |
|
| 328 |
public: |
|
|
| 329 |
Time (); |
| 330 |
Time (TimeUnit<1> time); |
| 331 |
Time (HighPrecision const& value); |
| 332 |
|
| 333 |
/** |
| 334 |
* \returns an approximation in seconds of the time stored in this |
| 335 |
* instance. |
| 336 |
*/ |
| 337 |
double GetSeconds (void) const; |
| 338 |
/** |
| 339 |
* \returns an approximation in milliseconds of the time stored in this |
| 340 |
* instance. |
| 341 |
*/ |
| 342 |
int32_t GetMilliSeconds (void) const; |
| 343 |
/** |
| 344 |
* \returns an approximation in microseconds of the time stored in this |
| 345 |
* instance. |
| 346 |
*/ |
| 347 |
int64_t GetMicroSeconds (void) const; |
| 348 |
/** |
| 349 |
* \returns an approximation in nanoseconds of the time stored in this |
| 350 |
* instance. |
| 351 |
*/ |
| 352 |
int64_t GetNanoSeconds (void) const; |
| 353 |
}; |
| 354 |
|
396 |
|
| 355 |
std::ostream& operator<< (std::ostream& os, Time const& time); |
397 |
std::ostream& operator<< (std::ostream& os, Time const& time); |
| 356 |
|
398 |
|
|
Lines 408-413
Time NanoSeconds (uint64_t ns);
|
Link Here
|
|---|
|
| 408 |
* \endcode |
450 |
* \endcode |
| 409 |
*/ |
451 |
*/ |
| 410 |
Time Now (void); |
452 |
Time Now (void); |
|
|
453 |
|
| 454 |
|
| 455 |
// Explicit instatiation of the TimeUnit template for N=0, with a few |
| 456 |
// additional methods that should not be available for N != 0 |
| 457 |
template <> |
| 458 |
class TimeUnit<0> |
| 459 |
{ |
| 460 |
// -*- New methods -*- |
| 461 |
public: |
| 462 |
double GetDouble (void) const; |
| 463 |
TimeUnit<0> (double scalar); |
| 464 |
|
| 465 |
// -*- The rest is the the same as in the generic template class -*- |
| 466 |
public: |
| 467 |
TimeUnit () |
| 468 |
: m_data () |
| 469 |
{}; |
| 470 |
TimeUnit (TimeUnit const &o) |
| 471 |
: m_data (o.m_data) {} |
| 472 |
TimeUnit operator = (TimeUnit const &o) { |
| 473 |
m_data = o.m_data; |
| 474 |
return *this; |
| 475 |
} |
| 476 |
TimeUnit (HighPrecision data) |
| 477 |
: m_data (data) {} |
| 478 |
bool IsZero (void) const { |
| 479 |
return m_data.Compare (HighPrecision::Zero ()) == 0; |
| 480 |
} |
| 481 |
bool IsNegative (void) const { |
| 482 |
return m_data.Compare (HighPrecision::Zero ()) <= 0; |
| 483 |
} |
| 484 |
bool IsPositive (void) const { |
| 485 |
return m_data.Compare (HighPrecision::Zero ()) >= 0; |
| 486 |
} |
| 487 |
bool IsStrictlyNegative (void) const { |
| 488 |
return m_data.Compare (HighPrecision::Zero ()) < 0; |
| 489 |
} |
| 490 |
bool IsStrictlyPositive (void) const { |
| 491 |
return m_data.Compare (HighPrecision::Zero ()) > 0; |
| 492 |
} |
| 493 |
HighPrecision const &GetHighPrecision (void) const { |
| 494 |
return m_data; |
| 495 |
} |
| 496 |
HighPrecision *PeekHighPrecision (void) { |
| 497 |
return &m_data; |
| 498 |
} |
| 499 |
private: |
| 500 |
HighPrecision m_data; |
| 501 |
}; |
| 411 |
|
502 |
|
| 412 |
/** |
503 |
/** |
| 413 |
* \brief hold scalar values |
504 |
* \brief hold scalar values |
|
|
| 424 |
* std::cout << s1.GetDouble () << std::endl; |
515 |
* std::cout << s1.GetDouble () << std::endl; |
| 425 |
* \endcode |
516 |
* \endcode |
| 426 |
*/ |
517 |
*/ |
| 427 |
class Scalar : public TimeUnit<0> |
518 |
typedef TimeUnit<0> Scalar; |
| 428 |
{ |
|
|
| 429 |
public: |
| 430 |
Scalar (); |
| 431 |
Scalar (double scalar); |
| 432 |
Scalar (TimeUnit<0> scalar); |
| 433 |
double GetDouble (void) const; |
| 434 |
}; |
| 435 |
|
519 |
|
| 436 |
typedef TimeUnit<-1> TimeInvert; |
520 |
typedef TimeUnit<-1> TimeInvert; |
| 437 |
typedef TimeUnit<2> TimeSquare; |
521 |
typedef TimeUnit<2> TimeSquare; |