OnixS Eurex ETI Handler C++ library 9.25.0
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__)
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__)
43
44typedef timeval AbsoluteHighResolutionTimeImpl;
45
46typedef struct Nothing
47{
48} RelativeHighResolutionTimeImpl;
49#else
50
51# error High resolution time services are not defined for a given platform.
52
53#endif
55typedef AbsoluteHighResolutionTimeImpl Timestamp;
56
58struct ONIXS_EUREX_ETI_EXPORT HighResolutionTimeFields
59{
60 unsigned short year;
61 unsigned short month;
62 unsigned short day;
63
64 unsigned short hour;
65 unsigned short minute;
66 unsigned short seconds;
67
68 unsigned int microseconds;
69
72
74 void fromAbsolute(const AbsoluteHighResolutionTimeImpl&);
75
77 void toAbsolute(AbsoluteHighResolutionTimeImpl*) const;
78
80 void fromString(const std::string&);
81
83 std::string toString() const;
84};
85
86typedef long long HighResolutionTimeSpan;
87
89class ONIXS_EUREX_ETI_EXPORT HighResolutionTime
90{
91public:
94
97
100
103
105 bool isValid() const;
106
109
111 std::string toString() const;
112
114 void setToNow();
115
117 bool operator==(const HighResolutionTime&) const;
118
120 bool operator!=(const HighResolutionTime&) const;
121
124
127
130
132 static HighResolutionTime parse(const std::string& time);
133
134protected:
135 friend struct TimestampHelpers;
136#if defined(_WIN32)
138 static HighResolutionTime createFromRelative(RelativeHighResolutionTimeImpl value);
139#elif defined(__linux__)
141 static HighResolutionTime createFromAbsolute(AbsoluteHighResolutionTimeImpl value);
142#endif
143
144private:
145 enum ValueKind
146 {
147 Invalid,
148 Absolute,
149 Relative
150 };
151
152 union Value
153 {
154 AbsoluteHighResolutionTimeImpl asAbsolute;
155 RelativeHighResolutionTimeImpl asRelative;
156 };
157
158 Value value_;
159 ValueKind kind_;
160
161 HighResolutionTime(ValueKind kind);
162};
163
165{
166 return !(Invalid == kind_);
167}
168
169ONIXS_EUREX_ETI_EXPORT std::ostream& operator<<(std::ostream&, const HighResolutionTime&);
170
171}}} // namespace OnixS::Eurex::Trading
Miscellaneous time traits.
Definition Time.h:90
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:164
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:86
AbsoluteHighResolutionTimeImpl Timestamp
Alias for raw timestamps.
Definition Time.h:55
unsigned long long UInt64
Definition Defines.h:46
Fields of HighResolutionTime.
Definition Time.h:59
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.