OnixS C++ Tullett Prebon SURF Handler 1.6.1
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#include <OnixS/SURF/MarketData/Export.h>
24
25#include <iosfwd>
26#include <string>
27
28#if defined(__linux__)
29# include <sys/time.h>
30# include <unistd.h>
31#endif
32
33namespace OnixS { namespace SURF { namespace MarketData {
34
35#if defined(_WIN32)
36
37typedef unsigned __int64 AbsoluteHighResolutionTimeImpl;
38
39typedef __int64 RelativeHighResolutionTimeImpl;
40
41#elif defined(__linux__)
42
43typedef timeval AbsoluteHighResolutionTimeImpl;
44
45typedef struct Nothing
46{
47} RelativeHighResolutionTimeImpl;
48
49#else
50
51# error High resolution time services are not defined for a given platform.
52
53#endif
54
55struct ONIXS_TP_SURF_EXPORT HighResolutionTimeFields
56{
57 unsigned short year;
58 unsigned short month;
59 unsigned short day;
60
61 unsigned short hour;
62 unsigned short minute;
63 unsigned short seconds;
64
65 unsigned int microseconds;
66
69
71 void fromAbsolute(const AbsoluteHighResolutionTimeImpl&);
72
74 void toAbsolute(AbsoluteHighResolutionTimeImpl*) const;
75
77 void fromString(const std::string&);
78
80 std::string toString() const;
81};
82
83typedef long long HighResolutionTimeSpan;
84
86class ONIXS_TP_SURF_EXPORT HighResolutionTime
87{
88public:
91
94
97
100
102 bool isValid() const;
103
106
108 std::string toString() const;
109
111 void setToNow();
112
114 bool operator==(const HighResolutionTime&) const;
115
117 bool operator!=(const HighResolutionTime&) const;
118
121
124
127
129 static HighResolutionTime parse(const std::string& time);
130
131private:
132 enum ValueKind
133 {
134 Invalid,
135 Absolute,
136 Relative
137 };
138
139 union Value
140 {
141 AbsoluteHighResolutionTimeImpl asAbsolute;
142 RelativeHighResolutionTimeImpl asRelative;
143 };
144
145 Value value_;
146 ValueKind kind_;
147
148 HighResolutionTime(ValueKind kind);
149};
150
152{
153 return !(Invalid == kind_);
154}
155
156ONIXS_TP_SURF_EXPORT std::ostream& operator<<(std::ostream&, const HighResolutionTime&);
157
158}}} // namespace OnixS::SURF::MarketData
Miscellaneous time traits.
Definition Time.h:87
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.
HighResolutionTime(long long)
Initializes from given number of milliseconds since Jan 1st, 1970, 00:00:00 GMT.
bool isValid() const
Indicates whether the instance is valid time.
Definition Time.h:151
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.
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.
long long HighResolutionTimeSpan
Definition Time.h:83
std::ostream & operator<<(std::ostream &, const Decimal &)
void fromAbsolute(const AbsoluteHighResolutionTimeImpl &)
Reinterpret from absolute representation.
void fromString(const std::string &)
Parse from string.
std::string toString() const
Returns string representation.
void toAbsolute(AbsoluteHighResolutionTimeImpl *) const
Convert to absolute representation.