~ubuntu-branches/ubuntu/trusty/log4shib/trusty

« back to all changes in this revision

Viewing changes to include/log4shib/TimeStamp.hh

  • Committer: Package Import Robot
  • Author(s): Russ Allbery
  • Date: 2012-06-05 21:20:25 UTC
  • Revision ID: package-import@ubuntu.com-20120605212025-uyigtav7dqwvnf41
Tags: upstream-1.0.4
ImportĀ upstreamĀ versionĀ 1.0.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
10
#ifndef _LOG4SHIB_TIMESTAMP_HH
 
11
#define _LOG4SHIB_TIMESTAMP_HH
 
12
 
 
13
#include <log4shib/Portability.hh>
 
14
 
 
15
namespace log4shib {
 
16
 
 
17
    /**
 
18
     * A simple TimeStamp abstraction
 
19
     **/
 
20
    class LOG4SHIB_EXPORT TimeStamp {
 
21
        public:
 
22
        /**
 
23
           Constructs a TimeStamp representing 'now'.
 
24
        **/
 
25
        TimeStamp();
 
26
 
 
27
        /**
 
28
           Constructs a TimeStamp representing the given offset since the
 
29
           epoch ( 00:00:00 1970/1/1 UTC).
 
30
        **/
 
31
        TimeStamp(unsigned int seconds, unsigned int microSeconds = 0);
 
32
 
 
33
        /**
 
34
           Returns the 'seconds' part of the TimeStamp.
 
35
        **/
 
36
        inline int getSeconds() const {
 
37
            return _seconds;
 
38
        };
 
39
 
 
40
        /** 
 
41
           Returns the 'subseconds' part of the TimeStamp in milliseconds,
 
42
           getMilliSeconds() == getMicroSeconds() / 1000. 
 
43
        **/
 
44
        inline int getMilliSeconds() const {
 
45
            return _microSeconds / 1000;
 
46
        };
 
47
 
 
48
        /**
 
49
           Returns the subsecond part of the TimeStamp in microseconds.
 
50
           The actual precision of this value depends on the platform and
 
51
           may be in the order of milliseconds rather than microseconds.
 
52
         **/
 
53
        inline int getMicroSeconds() const {
 
54
            return _microSeconds;
 
55
        };
 
56
 
 
57
        /**
 
58
           Returns a TimeStamp representing the time at which the application
 
59
           started.
 
60
        **/
 
61
        static inline const TimeStamp& getStartTime() {
 
62
            return _startStamp;
 
63
        };
 
64
 
 
65
        protected:
 
66
        static TimeStamp _startStamp;
 
67
 
 
68
        int _seconds;
 
69
        int _microSeconds;
 
70
    };
 
71
}
 
72
 
 
73
#endif // _LOG4SHIB_TIMESTAMP_HH
 
74