|
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 |
// \class TimeUnit<1> |
| 304 |
|
| 305 |
template <> |
| 306 |
class TimeUnit<1> |
| 307 |
{ |
| 308 |
// -*- New methods -*- |
| 309 |
public: |
| 310 |
|
| 311 |
/** |
| 312 |
* \returns an approximation in seconds of the time stored in this |
| 313 |
* instance. |
| 314 |
*/ |
| 315 |
double GetSeconds (void) const; |
| 316 |
/** |
| 317 |
* \returns an approximation in milliseconds of the time stored in this |
| 318 |
* instance. |
| 319 |
*/ |
| 320 |
int32_t GetMilliSeconds (void) const; |
| 321 |
/** |
| 322 |
* \returns an approximation in microseconds of the time stored in this |
| 323 |
* instance. |
| 324 |
*/ |
| 325 |
int64_t GetMicroSeconds (void) const; |
| 326 |
/** |
| 327 |
* \returns an approximation in nanoseconds of the time stored in this |
| 328 |
* instance. |
| 329 |
*/ |
| 330 |
int64_t GetNanoSeconds (void) const; |
| 331 |
|
| 332 |
// -*- The rest is the the same as in the generic template class -*- |
| 333 |
public: |
| 334 |
TimeUnit () |
| 335 |
: m_data () |
| 336 |
{} |
| 337 |
TimeUnit (TimeUnit const &o) |
| 338 |
: m_data (o.m_data) {} |
| 339 |
TimeUnit operator = (TimeUnit const &o) { |
| 340 |
m_data = o.m_data; |
| 341 |
return *this; |
| 342 |
} |
| 343 |
TimeUnit (HighPrecision data) |
| 344 |
: m_data (data) {} |
| 345 |
bool IsZero (void) const { |
| 346 |
return m_data.Compare (HighPrecision::Zero ()) == 0; |
| 347 |
} |
| 348 |
bool IsNegative (void) const { |
| 349 |
return m_data.Compare (HighPrecision::Zero ()) <= 0; |
| 350 |
} |
| 351 |
bool IsPositive (void) const { |
| 352 |
return m_data.Compare (HighPrecision::Zero ()) >= 0; |
| 353 |
} |
| 354 |
bool IsStrictlyNegative (void) const { |
| 355 |
return m_data.Compare (HighPrecision::Zero ()) < 0; |
| 356 |
} |
| 357 |
bool IsStrictlyPositive (void) const { |
| 358 |
return m_data.Compare (HighPrecision::Zero ()) > 0; |
| 359 |
} |
| 360 |
HighPrecision const &GetHighPrecision (void) const { |
| 361 |
return m_data; |
| 362 |
} |
| 363 |
HighPrecision *PeekHighPrecision (void) { |
| 364 |
return &m_data; |
| 365 |
} |
| 366 |
private: |
| 367 |
HighPrecision m_data; |
| 368 |
}; |
| 300 |
|
369 |
|
| 301 |
/** |
370 |
/** |
| 302 |
* \brief keep track of seconds. |
371 |
* \brief keep track of seconds. |
|
Lines 322-356
TimeUnit<N> Min (TimeUnit<N> const &ta,
|
Link Here
|
|---|
|
| 322 |
* - \ref ns3-Time-Abs ns3::Abs |
391 |
* - \ref ns3-Time-Abs ns3::Abs |
| 323 |
* - \ref ns3-Time-Max ns3::Max |
392 |
* - \ref ns3-Time-Max ns3::Max |
| 324 |
* - \ref ns3-Time-Min ns3::Min |
393 |
* - \ref ns3-Time-Min ns3::Min |
| 325 |
*/ |
394 |
* |
| 326 |
class Time : public TimeUnit<1> |
395 |
* The Time class has the following additional methods not available in |
| 327 |
{ |
396 |
* the generic TimeUnit template: |
| 328 |
public: |
397 |
* |
| 329 |
Time (); |
398 |
* \code |
| 330 |
Time (TimeUnit<1> time); |
399 |
* double GetSeconds (void) const; |
| 331 |
Time (HighPrecision const& value); |
400 |
* \endcode |
| 332 |
|
401 |
* returns an approximation in seconds of the time stored in this |
| 333 |
/** |
402 |
* instance. |
| 334 |
* \returns an approximation in seconds of the time stored in this |
403 |
* |
| 335 |
* instance. |
404 |
* \code |
| 336 |
*/ |
405 |
* int32_t GetMilliSeconds (void) const; |
| 337 |
double GetSeconds (void) const; |
406 |
* \endcode |
| 338 |
/** |
407 |
* returns an approximation in milliseconds of the time stored in this |
| 339 |
* \returns an approximation in milliseconds of the time stored in this |
408 |
* instance. |
| 340 |
* instance. |
409 |
* |
| 341 |
*/ |
410 |
* \code |
| 342 |
int32_t GetMilliSeconds (void) const; |
411 |
* int64_t GetMicroSeconds (void) const; |
| 343 |
/** |
412 |
* \endcode |
| 344 |
* \returns an approximation in microseconds of the time stored in this |
413 |
* returns an approximation in microseconds of the time stored in this |
| 345 |
* instance. |
414 |
* instance. |
| 346 |
*/ |
415 |
* |
| 347 |
int64_t GetMicroSeconds (void) const; |
416 |
* \code |
| 348 |
/** |
417 |
* int64_t GetNanoSeconds (void) const; |
| 349 |
* \returns an approximation in nanoseconds of the time stored in this |
418 |
* \endcode |
| 350 |
* instance. |
419 |
* returns an approximation in nanoseconds of the time stored in this |
| 351 |
*/ |
420 |
* instance. |
| 352 |
int64_t GetNanoSeconds (void) const; |
421 |
*/ |
| 353 |
}; |
422 |
typedef TimeUnit<1> Time; |
|
|
423 |
|
| 354 |
|
424 |
|
| 355 |
std::ostream& operator<< (std::ostream& os, Time const& time); |
425 |
std::ostream& operator<< (std::ostream& os, Time const& time); |
| 356 |
|
426 |
|
|
Lines 408-413
Time NanoSeconds (uint64_t ns);
|
Link Here
|
|---|
|
| 408 |
* \endcode |
478 |
* \endcode |
| 409 |
*/ |
479 |
*/ |
| 410 |
Time Now (void); |
480 |
Time Now (void); |
|
|
481 |
|
| 482 |
|
| 483 |
// Explicit instatiation of the TimeUnit template for N=0, with a few |
| 484 |
// additional methods that should not be available for N != 0 |
| 485 |
template <> |
| 486 |
class TimeUnit<0> |
| 487 |
{ |
| 488 |
// -*- New methods -*- |
| 489 |
public: |
| 490 |
double GetDouble (void) const; |
| 491 |
TimeUnit<0> (double scalar); |
| 492 |
|
| 493 |
// -*- The rest is the the same as in the generic template class -*- |
| 494 |
public: |
| 495 |
TimeUnit () |
| 496 |
: m_data () |
| 497 |
{}; |
| 498 |
TimeUnit (TimeUnit const &o) |
| 499 |
: m_data (o.m_data) {} |
| 500 |
TimeUnit operator = (TimeUnit const &o) { |
| 501 |
m_data = o.m_data; |
| 502 |
return *this; |
| 503 |
} |
| 504 |
TimeUnit (HighPrecision data) |
| 505 |
: m_data (data) {} |
| 506 |
bool IsZero (void) const { |
| 507 |
return m_data.Compare (HighPrecision::Zero ()) == 0; |
| 508 |
} |
| 509 |
bool IsNegative (void) const { |
| 510 |
return m_data.Compare (HighPrecision::Zero ()) <= 0; |
| 511 |
} |
| 512 |
bool IsPositive (void) const { |
| 513 |
return m_data.Compare (HighPrecision::Zero ()) >= 0; |
| 514 |
} |
| 515 |
bool IsStrictlyNegative (void) const { |
| 516 |
return m_data.Compare (HighPrecision::Zero ()) < 0; |
| 517 |
} |
| 518 |
bool IsStrictlyPositive (void) const { |
| 519 |
return m_data.Compare (HighPrecision::Zero ()) > 0; |
| 520 |
} |
| 521 |
HighPrecision const &GetHighPrecision (void) const { |
| 522 |
return m_data; |
| 523 |
} |
| 524 |
HighPrecision *PeekHighPrecision (void) { |
| 525 |
return &m_data; |
| 526 |
} |
| 527 |
private: |
| 528 |
HighPrecision m_data; |
| 529 |
}; |
| 411 |
|
530 |
|
| 412 |
/** |
531 |
/** |
| 413 |
* \brief hold scalar values |
532 |
* \brief hold scalar values |
|
|
| 423 |
* Scalar s1 = Seconds (15.0) / Seconds (10.0); |
542 |
* Scalar s1 = Seconds (15.0) / Seconds (10.0); |
| 424 |
* std::cout << s1.GetDouble () << std::endl; |
543 |
* std::cout << s1.GetDouble () << std::endl; |
| 425 |
* \endcode |
544 |
* \endcode |
| 426 |
*/ |
545 |
* |
| 427 |
class Scalar : public TimeUnit<0> |
546 |
* The Scalar class has the following additional methods not available in |
| 428 |
{ |
547 |
* the generic TimeUnit template: |
| 429 |
public: |
548 |
* \code |
| 430 |
Scalar (); |
549 |
* double GetDouble (void) const; |
| 431 |
Scalar (double scalar); |
550 |
* \endcode |
| 432 |
Scalar (TimeUnit<0> scalar); |
551 |
* returns the C double contained in the Scalar instance |
| 433 |
double GetDouble (void) const; |
552 |
* |
| 434 |
}; |
553 |
* \code |
|
|
554 |
* Scalar(double scalar); |
| 555 |
* \endcode |
| 556 |
* Constructs a Scalar instance from a C double. |
| 557 |
*/ |
| 558 |
typedef TimeUnit<0> Scalar; |
| 435 |
|
559 |
|
| 436 |
typedef TimeUnit<-1> TimeInvert; |
560 |
typedef TimeUnit<-1> TimeInvert; |
| 437 |
typedef TimeUnit<2> TimeSquare; |
561 |
typedef TimeUnit<2> TimeSquare; |