Photon C++ Client API
4.1.12.2
|
Public Member Functions | |
EGTime (int time) | |
~EGTime (void) | |
EGTime (const EGTime &toCopy) | |
EGTime & | operator= (const EGTime &toCopy) |
EGTime & | operator= (const int &time) |
const EGTime & | operator+= (const EGTime &time) |
const EGTime & | operator-= (const EGTime &time) |
EGTime | operator+ (const EGTime &time) |
EGTime | operator- (const EGTime &time) |
bool | operator< (const EGTime &time) const |
bool | operator> (const EGTime &time) const |
bool | operator<= (const EGTime &time) const |
bool | operator>= (const EGTime &time) const |
bool | operator== (const EGTime &time) const |
bool | operator!= (const EGTime &time) const |
bool | overflowed (const EGTime &time) const |
JString & | toString (JString &retStr, bool withTypes=false) const |
Public Member Functions inherited from Base | |
virtual | ~Base (void) |
Public Member Functions inherited from ToString | |
virtual | ~ToString (void) |
virtual JString | typeToString (void) const |
JString | toString (bool withTypes=false) const |
Additional Inherited Members | |
Static Public Member Functions inherited from Base | |
static void | setListener (const BaseListener *baseListener) |
static int | getDebugOutputLevel (void) |
static bool | setDebugOutputLevel (int debugLevel) |
static const LogFormatOptions & | getLogFormatOptions (void) |
static void | setLogFormatOptions (const LogFormatOptions &options) |
Detailed Description
The EGTime class is a container class for millisecond timestamps, which accounts for overflows when comparing two instances against each other.
The intended usage of this class is to compare 32 bit integer millisecond timestamps, which only differ in relatively small amounts of ms (a few seconds up to at max a few hours) from each other. 32bit timestamps have the advantage over 64 bit ones, that they need less bytes to store their information, which is of critical value in some situations. However 32 bit milliseconds timestamps overflow every about 49 days. Arithmetical calculations don't react well to those overflows for unsigned integers, but they continue to work fine for signed integers. However when comparing two timestamps, one from shortly before an overflow, one from shortly after, even signed integers won't work: the timestamp INT_MIN is one millisecond LATER than INT_MAX, but when comparing these two as integers, INT_MIN is smaller than INT_MAX. EGTime approaches this issue by introducing an overflow threshold of 24 hours. If time a is bigger than time, but not bigger than time b + 24 hours, than and only than, EGTime will also consider it as bigger. This way code like if(timestamp1 < timestamp2) will also work, when between these two timestamps an overflow has happened. The downside is, that this class won't work when comparing 2 timestamps, that differ by more than 24 hours.
Constructor & Destructor Documentation
§ EGTime() [1/2]
EGTime | ( | int | time | ) |
Constructor: Creates an EGTime instance.
- Parameters
-
time the time in milliseconds to initialize the instance with
§ ~EGTime()
~EGTime | ( | void | ) |
Destructor.
§ EGTime() [2/2]
Member Function Documentation
§ operator=() [1/2]
operator=.
Makes a deep copy of its right operand into its left operand.
This overwrites old data in the left operand.
§ operator=() [2/2]
EGTime & operator= | ( | const int & | time | ) |
operator=.
Makes a deep copy of its right operand into its left operand.
This overwrites old data in the left operand.
§ operator+=()
§ operator-=()
operator-=.
Subtracts the right time from the left time.
§ operator+()
operator+.
Adds the right time to the left time and returns the result as a new EGTime instance.
§ operator-()
operator-=.
Subtracts the right time from the left time and returns the result as a new EGTime instance.
§ operator<()
bool operator< | ( | const EGTime & | time | ) | const |
operator<.
- Remarks
- An EGTime instance is considered smaller than another one, if its payload is either smaller or more than 24 hours bigger than the other ones payload.
- Returns
- true, if the left operand is smaller than the right operand, false otherwise.
§ operator>()
bool operator> | ( | const EGTime & | time | ) | const |
operator>.
- Remarks
- An EGTime instance is considered bigger than another one, if its payload is either bigger or more than 24 hours smaller than the other ones payload.
- Returns
- true, if the left operand is bigger than the right operand, false otherwise.
§ operator<=()
bool operator<= | ( | const EGTime & | time | ) | const |
operator<=.
- Remarks
- An EGTime instance is considered smaller than another one, if its payload is either smaller or more than 24 hours bigger than the other ones payload.
- Returns
- true, if the left operand is smaller than or equal to the right operand, false otherwise.
§ operator>=()
bool operator>= | ( | const EGTime & | time | ) | const |
operator>=.
- Remarks
- An EGTime instance is considered bigger than another one, if its payload is either bigger or more than 24 hours smaller than the other ones payload.
- Returns
- true, if the left operand is bigger than or equal to the right operand, false otherwise.
§ operator==()
bool operator== | ( | const EGTime & | time | ) | const |
operator==.
- Returns
- true, if both instances have equal values, false otherwise.
§ operator!=()
bool operator!= | ( | const EGTime & | time | ) | const |
operator==.
- Returns
- false, if both instances have equal values, true otherwise.
§ overflowed()
bool overflowed | ( | const EGTime & | time | ) | const |
- Returns
- true, if the values of both instances differ by more than 24 hours, false otherwise.
§ toString()
- Remarks
- The cost of this function depends a lot on implementation details of the implementing subclasses, but for container classes this function can become quite expensive, if the instance contains huge amounts of data, as its cost for many container class implementations increases disproportionately high to the size of the payload.
- Parameters
-
retStr reference to a string, to store the return-value in; the information, which is generated by this function, will be attached at the end of any eventually existing previous content of the string withTypes set to true, to include type information in the generated string
- Returns
- a JString representation of the instance and its contents for debugging purposes.
Implements ToString.