Photon C++ Client API  5.0.7.3
Public Member Functions | Related Functions | List of all members
JTime Class Reference
Inheritance diagram for JTime:
Inheritance graph
[legend]
Collaboration diagram for JTime:
Collaboration graph
[legend]

Public Member Functions

 JTime (int time=GETTIMEMS())
 
 ~JTime (void)
 
 JTime (const JTime &toCopy)
 
JTimeoperator= (const JTime &toCopy)
 
JTimeoperator= (int time)
 
JTimeoperator+= (const JTime &time)
 
JTimeoperator+= (int time)
 
JTimeoperator-= (const JTime &time)
 
JTimeoperator-= (int time)
 
bool operator< (const JTime &time) const
 
bool operator> (const JTime &time) const
 
bool operator<= (const JTime &time) const
 
bool operator>= (const JTime &time) const
 
bool operator== (const JTime &time) const
 
bool operator!= (const JTime &time) const
 
 operator int (void) const
 
bool overflowed (const JTime &time) const
 
virtual JStringtoString (JString &retStr, bool withTypes=false) const
 
virtual JStringtoString (JString &retStr, bool withTypes=false) const=0
 
JString toString (bool withTypes=false) const
 
- Public Member Functions inherited from Base
virtual ~Base (void)=0
 
- Public Member Functions inherited from LoggingBase< Base >
virtual ~LoggingBase (void)=0
 
- Public Member Functions inherited from ToString
virtual ~ToString (void)
 
virtual JString typeToString (void) const
 
JString toString (bool withTypes=false) const
 

Related Functions

(Note that these are not member functions.)

int & operator+= (int &Lsh, const JTime &Rsh)
 
int & operator-= (int &Lsh, const JTime &Rsh)
 
JTime operator+ (const JTime &Lsh, const JTime &Rsh)
 
JTime operator+ (const JTime &Lsh, int Rsh)
 
JTime operator+ (int Lsh, const JTime &Rsh)
 
JTime operator- (const JTime &Lsh, const JTime &Rsh)
 
JTime operator- (const JTime &Lsh, int Rsh)
 
JTime operator- (int Lsh, const JTime &Rsh)
 
bool operator== (const JTime &Lsh, int Rsh)
 
bool operator== (int Lsh, const JTime &Rsh)
 
bool operator!= (const JTime &Lsh, int Rsh)
 
bool operator!= (int Lsh, const JTime &Rsh)
 
bool operator< (const JTime &Lsh, int Rsh)
 
bool operator< (int Lsh, const JTime &Rsh)
 
bool operator> (const JTime &Lsh, int Rsh)
 
bool operator> (int Lsh, const JTime &Rsh)
 
bool operator<= (const JTime &Lsh, int Rsh)
 
bool operator<= (int Lsh, const JTime &Rsh)
 
bool operator>= (const JTime &Lsh, int Rsh)
 
bool operator>= (int Lsh, const JTime &Rsh)
 

Additional Inherited Members

- Static Public Member Functions inherited from LoggingBase< Base >
static void setListener (const BaseListener *pBaseListener)
 
static int getDebugOutputLevel (void)
 
static bool setDebugOutputLevel (int debugLevel)
 
static const LogFormatOptionsgetLogFormatOptions (void)
 
static void setLogFormatOptions (const LogFormatOptions &options)
 

Detailed Description

The JTime 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. JTime approaches this issue by introducing an overflow threshold of 24 hours. If time a is bigger than time b, but not bigger than time b + 24 hours, than and only than, JTime 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

◆ JTime() [1/2]

JTime ( int  time = GETTIMEMS())

Constructor: Creates an JTime instance.

Parameters
timethe time in milliseconds to initialize the instance with - defaults to the current timestamp at the time of the call as returned by GETTIMEMS()

◆ ~JTime()

~JTime ( void  )

Destructor.

◆ JTime() [2/2]

JTime ( const JTime toCopy)

Copy-Constructor: Creates a new JTime instance from a deep copy of the argument instance.

Parameters
toCopythe JTime instance to make a copy from

Member Function Documentation

◆ operator=() [1/2]

JTime & operator= ( const JTime toCopy)

operator=.

Makes a deep copy of its right operand into its left operand.

This overwrites old data in the left operand.

◆ operator=() [2/2]

JTime & operator= ( int  time)

operator=.

Makes a deep copy of its right operand into its left operand.

This overwrites old data in the left operand.

◆ operator+=() [1/2]

JTime & operator+= ( const JTime time)

operator+=.

Adds the right time to the left time.

◆ operator+=() [2/2]

JTime & operator+= ( int  time)

operator+=.

Adds the right time to the left time.

◆ operator-=() [1/2]

JTime & operator-= ( const JTime time)

operator-=.

Subtracts the right time from the left time.

◆ operator-=() [2/2]

JTime & operator-= ( int  time)

operator-=.

Subtracts the right time from the left time.

◆ operator<()

bool operator< ( const JTime time) const

operator<.

Remarks
An JTime 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 JTime time) const

operator>.

Remarks
An JTime 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 JTime time) const

operator<=.

Remarks
An JTime 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 JTime time) const

operator>=.

Remarks
An JTime 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 JTime time) const

operator==.

Returns
true, if both instances have equal values, false otherwise.

◆ operator!=()

bool operator!= ( const JTime time) const

operator==.

Returns
false, if both instances have equal values, true otherwise.

◆ operator int()

operator int ( void  ) const

operator int.

Returns
an int representation of the instance

◆ overflowed()

bool overflowed ( const JTime time) const
Returns
true, if the values of both instances differ by more than 24 hours, false otherwise.

◆ toString() [1/3]

JString & toString ( JString retStr,
bool  withTypes = false 
) const
virtual
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
retStrreference 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
withTypesset 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.

◆ toString() [2/3]

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
retStrreference 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
withTypesset to true, to include type information in the generated string
Returns
a JString representation of the instance and its contents for debugging purposes.

◆ toString() [3/3]

JString toString

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
withTypesset to true, to include type information in the generated string
Returns
a JString representation of the instance and its contents for debugging purposes.
See also
JString

Friends And Related Function Documentation

◆ operator+=()

int & operator+= ( int &  Lsh,
const JTime Rsh 
)
related

operator+=.

Adds the right operand to the left operand.

◆ operator-=()

int & operator-= ( int &  Lsh,
const JTime Rsh 
)
related

operator-=.

Subtracts the right operand from the left operand.

◆ operator+() [1/3]

JTime operator+ ( const JTime Lsh,
const JTime Rsh 
)
related

operator+.

Adds its right operand to its left operand and returns the result as a new JTime instance.

◆ operator+() [2/3]

JTime operator+ ( const JTime Lsh,
int  Rsh 
)
related

operator+.

Adds its right operand to its left operand and returns the result as a new JTime instance.

◆ operator+() [3/3]

JTime operator+ ( int  Lsh,
const JTime Rsh 
)
related

operator+.

Adds its right operand to its left operand and returns the result as a new JTime instance.

◆ operator-() [1/3]

JTime operator- ( const JTime Lsh,
const JTime Rsh 
)
related

operator-.

Subtracts its right operand from its left operand and returns the result as a new JTime instance.

◆ operator-() [2/3]

JTime operator- ( const JTime Lsh,
int  Rsh 
)
related

operator-.

Subtracts its right operand from its left operand and returns the result as a new JTime instance.

◆ operator-() [3/3]

JTime operator- ( int  Lsh,
const JTime Rsh 
)
related

operator-.

Subtracts its right operand from its left operand and returns the result as a new JTime instance.

◆ operator==() [1/2]

bool operator== ( const JTime Lsh,
int  Rsh 
)
related

operator==.

Returns
true, if both operands are equal, false otherwise.

◆ operator==() [2/2]

bool operator== ( int  Lsh,
const JTime Rsh 
)
related

operator==.

Returns
true, if both operands are equal, false otherwise.

◆ operator!=() [1/2]

bool operator!= ( const JTime Lsh,
int  Rsh 
)
related

operator!=.

Returns
false, if both operands are equal, true otherwise.

◆ operator!=() [2/2]

bool operator!= ( int  Lsh,
const JTime Rsh 
)
related

operator!=.

Returns
false, if both operands are equal, true otherwise.

◆ operator<() [1/2]

bool operator< ( const JTime Lsh,
int  Rsh 
)
related

operator<. The return value indicates the lexicographic relation between the operands.

Returns
true, if left operand is less than right operand, false otherwise.

◆ operator<() [2/2]

bool operator< ( int  Lsh,
const JTime Rsh 
)
related

operator<. The return value indicates the lexicographic relation between the operands.

Returns
true, if left operand is less than right operand, false otherwise.

◆ operator>() [1/2]

bool operator> ( const JTime Lsh,
int  Rsh 
)
related

operator>. The return value indicates the lexicographic relation between the operands.

Returns
true, if left operand is greater than right operand, false otherwise.

◆ operator>() [2/2]

bool operator> ( int  Lsh,
const JTime Rsh 
)
related

operator>. The return value indicates the lexicographic relation between the operands.

Returns
true, if left operand is greater than right operand, false otherwise.

◆ operator<=() [1/2]

bool operator<= ( const JTime Lsh,
int  Rsh 
)
related

operator<=. The return value indicates the lexicographic relation between the operands.

Returns
true, if the left operand is less than or equal to the right operand, false otherwise.

◆ operator<=() [2/2]

bool operator<= ( int  Lsh,
const JTime Rsh 
)
related

operator<=. The return value indicates the lexicographic relation between the operands.

Returns
true, if the left operand is less than or equal to the right operand, false otherwise.

◆ operator>=() [1/2]

bool operator>= ( const JTime Lsh,
int  Rsh 
)
related

operator>=. The return value indicates the lexicographic relation between the operands.

Returns
true, if the left operand is greater than or equal to the right operand, false otherwise.

◆ operator>=() [2/2]

bool operator>= ( int  Lsh,
const JTime Rsh 
)
related

operator>=. The return value indicates the lexicographic relation between the operands.

Returns
true, if the left operand is greater than or equal to the right operand, false otherwise.