OnixS Eurex ETI Handler C++ library 9.29.0
Users' manual and API documentation
Loading...
Searching...
No Matches
Time.h
Go to the documentation of this file.
1/*
2 * Copyright Onix Solutions Limited [OnixS]. All rights reserved.
3 *
4 * This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law
5 * and international copyright treaties.
6 *
7 * Access to and use of the software is governed by the terms of the applicable ONIXS Software
8 * Services Agreement (the Agreement) and Customer end user license agreements granting
9 * a non-assignable, non-transferable and non-exclusive license to use the software
10 * for it's own data processing purposes under the terms defined in the Agreement.
11 *
12 * Except as otherwise granted within the terms of the Agreement, copying or reproduction of any
13 * part of this source code or associated reference material to any other location for further
14 * reproduction or redistribution, and any amendments to this copyright notice, are expressly
15 * prohibited.
16 *
17 * Any reproduction or redistribution for sale or hiring of the Software not in accordance with
18 * the terms of the Agreement is a violation of copyright law.
19 */
20
21#pragma once
22
23#if defined(__linux__) || defined(__APPLE__)
24# include <sys/time.h>
25# include <unistd.h>
26#endif
27
29#include "OnixS/Eurex/Trading/Export.h"
30
31#include <iosfwd>
32#include <string>
33
34namespace OnixS { namespace Eurex { namespace Trading {
35
36#if defined(_WIN32)
37
38typedef unsigned __int64 AbsoluteHighResolutionTimeImpl;
39
40typedef __int64 RelativeHighResolutionTimeImpl;
41
42#elif defined(__linux__) || defined(__APPLE__)
43
44typedef timeval AbsoluteHighResolutionTimeImpl;
45
47typedef timeval RelativeHighResolutionTimeImpl;
48#else
49
50# error High resolution time services are not defined for a given platform.
51
52#endif
54typedef AbsoluteHighResolutionTimeImpl Timestamp;
55
57struct ONIXS_EUREX_ETI_EXPORT HighResolutionTimeFields
58{
59 unsigned short year;
60 unsigned short month;
61 unsigned short day;
62
63 unsigned short hour;
64 unsigned short minute;
65 unsigned short seconds;
66
67 unsigned int microseconds;
68
71
73 void fromAbsolute(const AbsoluteHighResolutionTimeImpl&);
74
76 void toAbsolute(AbsoluteHighResolutionTimeImpl*) const;
77
79 void fromString(const std::string&);
80
82 std::string toString() const;
83};
84
85typedef long long HighResolutionTimeSpan;
86
88class ONIXS_EUREX_ETI_EXPORT HighResolutionTime
89{
90public:
93
96
99
102
104 bool isValid() const;
105
108
110 std::string toString() const;
111
113 void setToNow();
114
116 bool operator==(const HighResolutionTime&) const;
117
119 bool operator!=(const HighResolutionTime&) const;
120
123
126
129
131 static HighResolutionTime parse(const std::string& time);
132
133protected:
134 friend struct TimestampHelpers;
135
137 static HighResolutionTime createFromRelative(RelativeHighResolutionTimeImpl value);
138#if defined(__linux__) || defined(__APPLE__)
140 static HighResolutionTime createFromAbsolute(AbsoluteHighResolutionTimeImpl value);
141#endif
142
143private:
144 enum ValueKind
145 {
146 Invalid,
147 Absolute,
148 Relative
149 };
150
151 union Value
152 {
153 AbsoluteHighResolutionTimeImpl asAbsolute;
154 RelativeHighResolutionTimeImpl asRelative;
155 };
156
157 Value value_;
158 ValueKind kind_;
159
160 HighResolutionTime(ValueKind kind);
161};
162
164{
165 return !(Invalid == kind_);
166}
167
168ONIXS_EUREX_ETI_EXPORT std::ostream& operator<<(std::ostream&, const HighResolutionTime&);
169
170}}} // namespace OnixS::Eurex::Trading
Miscellaneous time traits.
Definition Time.h:89
bool operator==(const HighResolutionTime &) const
Compares two timestamps for equality.
static HighResolutionTime parse(const std::string &time)
Returns time from its string presentation.
std::string toString() const
Returns canonical presentation of time.
void setToNow()
Updates to current time.
HighResolutionTimeSpan operator-(const HighResolutionTime &) const
Returns difference between two times in microseconds.
bool isValid() const
Indicates whether the instance is valid time.
Definition Time.h:163
static HighResolutionTime createFromRelative(RelativeHighResolutionTimeImpl value)
Returns time created from relative value.
HighResolutionTime & operator=(const HighResolutionTime &)
Reinitializes from the other instance.
HighResolutionTime(const HighResolutionTimeFields &)
Initializes from the given set of time attributes.
HighResolutionTime(const HighResolutionTime &)
Initializes from the other instance.
HighResolutionTime(UInt64)
Initializes from given number of milliseconds since Jan 1st, 1970, 00:00:00 GMT.
static HighResolutionTime now()
Returns current time.
void getFields(HighResolutionTimeFields *fields) const
Extracts details like year, month, seconds, etc.
bool operator!=(const HighResolutionTime &) const
Compares two timestamps for inequality.
HighResolutionTime()
Initializes as not valid.
std::ostream & operator<<(std::ostream &, const ConnectionStateChange &)
Make it printable to formatted C++ I/O streams.
long long HighResolutionTimeSpan
Definition Time.h:85
AbsoluteHighResolutionTimeImpl Timestamp
Alias for raw timestamps.
Definition Time.h:54
unsigned long long UInt64
Definition Defines.h:46
Fields of HighResolutionTime.
Definition Time.h:58
void fromAbsolute(const AbsoluteHighResolutionTimeImpl &)
From absolute.
void fromString(const std::string &)
Parse from string.
std::string toString() const
Returns string representation.
void toAbsolute(AbsoluteHighResolutionTimeImpl *) const
To absolute.