TimeStamp.hh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * TimeStamp.hh
  3. *
  4. * Copyright 2001, LifeLine Networks BV (www.lifeline.nl). All rights reserved.
  5. * Copyright 2001, Bastiaan Bakker. All rights reserved.
  6. *
  7. * See the COPYING file for the terms of usage and distribution.
  8. */
  9. #ifndef _LOG4CPP_TIMESTAMP_HH
  10. #define _LOG4CPP_TIMESTAMP_HH
  11. #include <log4cpp/Portability.hh>
  12. LOG4CPP_NS_BEGIN
  13. /**
  14. * A simple TimeStamp abstraction
  15. **/
  16. class LOG4CPP_EXPORT TimeStamp {
  17. public:
  18. /**
  19. Constructs a TimeStamp representing 'now'.
  20. **/
  21. TimeStamp();
  22. /**
  23. Constructs a TimeStamp representing the given offset since the
  24. epoch ( 00:00:00 1970/1/1 UTC).
  25. **/
  26. TimeStamp(unsigned int seconds, unsigned int microSeconds = 0);
  27. /**
  28. Returns the 'seconds' part of the TimeStamp.
  29. **/
  30. inline int getSeconds() const {
  31. return _seconds;
  32. };
  33. /**
  34. Returns the 'subseconds' part of the TimeStamp in milliseconds,
  35. getMilliSeconds() == getMicroSeconds() / 1000.
  36. **/
  37. inline int getMilliSeconds() const {
  38. return _microSeconds / 1000;
  39. };
  40. /**
  41. Returns the subsecond part of the TimeStamp in microseconds.
  42. The actual precision of this value depends on the platform and
  43. may be in the order of milliseconds rather than microseconds.
  44. **/
  45. inline int getMicroSeconds() const {
  46. return _microSeconds;
  47. };
  48. /**
  49. Returns a TimeStamp representing the time at which the application
  50. started.
  51. **/
  52. static inline const TimeStamp& getStartTime() {
  53. return _startStamp;
  54. };
  55. protected:
  56. static TimeStamp _startStamp;
  57. int _seconds;
  58. int _microSeconds;
  59. };
  60. LOG4CPP_NS_END
  61. #endif // _LOG4CPP_TIMESTAMP_HH