OnixS C++ FIX Engine  4.2.0
API Documentation
TimeSpan.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 part
13 * of this source code or associated reference material to any other location for further reproduction
14 * or redistribution, and any amendments to this copyright notice, are expressly prohibited.
15 *
16 * Any reproduction or redistribution for sale or hiring of the Software not in accordance with
17 * the terms of the Agreement is a violation of copyright law.
18 */
19 
20 #pragma once
21 
22 #include <string>
23 
24 #include <OnixS/FIXEngine/ABI.h>
26 
27 #define ONIXS_MINMAX_ABUSER
28 
29 namespace OnixS {
30 namespace FIX {
31 typedef UInt32 Amount;
33 
34 typedef Int32 Interval;
36 
37 typedef Interval Days;
38 typedef Interval Hours;
39 typedef Interval Minutes;
40 typedef Interval Seconds;
41 
42 typedef Interval Milliseconds;
43 typedef Interval Microseconds;
44 typedef Interval Nanoseconds;
45 typedef HugeInterval Picoseconds;
46 
47 typedef HugeInterval TotalSeconds;
48 typedef HugeInterval TotalMilliseconds;
49 typedef HugeInterval TotalMicroseconds;
50 typedef HugeInterval TotalNanoseconds;
51 typedef HugeInterval TotalPicoseconds;
52 
53 /// Time related constants.
55  static const Hours HoursPerDay;
56  static const Minutes MinutesPerHour;
57 
58  static const Seconds SecondsPerMinute;
59  static const Seconds SecondsPerHour;
60  static const Seconds SecondsPerDay;
61 
62  static const Milliseconds MillisecondsPerSecond;
63  static const Microseconds MicrosecondsPerSecond;
64  static const Nanoseconds NanosecondsPerSecond;
65 
66  static const Picoseconds PicosecondsPerNanosecond;
67  static const Picoseconds PicosecondsPerMicrosecond;
68  static const Picoseconds PicosecondsPerMillisecond;
69  static const Picoseconds PicosecondsPerSecond;
70 };
71 
72 /// Collection of time span formats supported.
74  enum Enum {
75  /// Indicates time span in "HH:MM:SS" format.
77 
78  /// Indicates time span in "HH:MM:SS.sss" format.
80 
81  /// Indicates time span in "HH:MM:SS.ssssss" format.
83 
84  /// Indicates time span in "HH:MM:SS.sssssssss" format.
86 
87  /// Indicates time span in "HH:MM:SS.ssssssssssss" format.
88  HHMMSSPsec
89  };
90 };
91 
92 /// Time span related functionality.
94 {
95 public:
96  /// Constructs uninitialized instance.
97  TimeSpan();
98 
99  /// Initializes TimeSpan from seconds and nanoseconds.
100  TimeSpan(
101  TotalSeconds seconds,
102  Nanoseconds nanoseconds);
103 
104  /// Initializes TimeSpan from seconds and picoseconds.
105  TimeSpan(
106  TotalSeconds seconds,
107  Picoseconds picoseconds);
108 
109  /// Initializes TimeSpan from hours, minutes and seconds.
110  TimeSpan(
111  Hours hours,
112  Minutes minutes,
113  Seconds seconds);
114 
115  /// Initializes TimeSpan from days, hours, minutes, seconds and nanoseconds.
116  TimeSpan(
117  Days days,
118  Hours hours,
119  Minutes minutes,
120  Seconds seconds,
121  Nanoseconds nanoseconds);
122 
123  /// Initializes TimeSpan from days, hours, minutes, seconds and picoseconds.
124  TimeSpan(
125  Days days,
126  Hours hours,
127  Minutes minutes,
128  Seconds seconds,
129  Picoseconds picooseconds);
130 
131  /// Initializes TimeSpan from other instance.
132  TimeSpan(const TimeSpan & other);
133 
134  /// Total number of seconds.
135  TotalSeconds totalSeconds() const;
136 
137  /// Current days.
138  Days days() const;
139 
140  /// Current hours.
141  Hours hours() const;
142 
143  /// Current minutes.
144  Minutes minutes() const;
145 
146  /// Current seconds.
147  Seconds seconds() const;
148 
149  /// Current milliseconds.
150  Milliseconds milliseconds() const;
151 
152  /// Current microseconds.
153  Microseconds microseconds() const;
154 
155  /// Current nanoseconds.
156  Nanoseconds nanoseconds() const;
157 
158  /// Current nanoseconds.
159  Picoseconds picoseconds() const;
160 
161  /// Current absolute time span.
162  TimeSpan absolute() const;
163 
164  /// Compares instance with another one.
165  bool operator == (const TimeSpan &) const;
166 
167  /// Compares instance with another one.
168  bool operator != (const TimeSpan &) const;
169 
170  /// Tests whether instance is less than another one.
171  bool operator < (const TimeSpan &) const;
172 
173  /// Increases instance by another one
174  TimeSpan & operator += (const TimeSpan &);
175 
176  /// Decreases instance by another one
177  TimeSpan & operator -= (const TimeSpan &);
178 
179  /// Assigns current time span from other instance.
180  TimeSpan & operator = (const TimeSpan &);
181 
182  /// Minimum value of the time span
183  static TimeSpan min ONIXS_MINMAX_ABUSER();
184 
185  /// Maximum value of the time span
186  static TimeSpan max ONIXS_MINMAX_ABUSER();
187 
188  /// Zero value of the time span
189  static TimeSpan zero();
190 
191  /// Returns time span text presentation in requested
192  /// format ("HH:MM:SS.sssssssss" by default).
193  std::string toString(TimeSpanFormat::Enum = TimeSpanFormat::HHMMSSNsec) const;
194  void toString(std::string &, TimeSpanFormat::Enum = TimeSpanFormat::HHMMSSNsec) const;
195 
196  /// Parses time span from its text presentation
197  static
198  TimeSpan
199  parse(const std::string &);
200 
201 protected:
202  friend class TimeManager;
203 
204  TotalSeconds seconds_;
205  Picoseconds picoseconds_;
206 
207  void normalize();
208 };
209 
210 inline
211 TotalSeconds
213 {
214  return seconds_;
215 }
216 
217 inline
218 Picoseconds
220 {
221  return picoseconds_;
222 }
223 
225 {
226 public:
227  DaySpan(Days days);
228 };
229 
230 /// Hour time span presentation.
232 {
233 public:
234  HourSpan(Hours hours);
235 };
236 
237 /// Minute time span presentation.
239 {
240 public:
241  MinuteSpan(Minutes minutes);
242 };
243 
244 /// Second time span presentation.
246 {
247 public:
248  SecondSpan(TotalSeconds seconds);
249 };
250 
251 /// Millisecond time span presentation.
253 {
254 public:
256  TotalMilliseconds milliseconds);
257 };
258 
259 /// Microsecond time span presentation.
261 {
262 public:
264  TotalMicroseconds microseconds);
265 };
266 
267 /// Nanosecond time span presentation.
269 {
270 public:
272  TotalNanoseconds nanoseconds);
273 };
274 
275 /// Picosecond time span presentation.
277 {
278 public:
280  TotalPicoseconds picoseconds);
281 };
282 }
283 }
284 
Indicates time span in "HH:MM:SS.ssssss" format.
Definition: TimeSpan.h:82
TotalSeconds seconds_
Definition: TimeSpan.h:204
Interval Days
Definition: TimeSpan.h:37
Minute time span presentation.
Definition: TimeSpan.h:238
Interval Milliseconds
Definition: TimeSpan.h:42
static const Nanoseconds NanosecondsPerSecond
Definition: TimeSpan.h:64
static const Seconds SecondsPerHour
Definition: TimeSpan.h:59
Collection of time span formats supported.
Definition: TimeSpan.h:73
Second time span presentation.
Definition: TimeSpan.h:245
Picosecond time span presentation.
Definition: TimeSpan.h:276
int Int32
Definition: Numeric.h:32
static const Picoseconds PicosecondsPerNanosecond
Definition: TimeSpan.h:66
HugeInterval Picoseconds
Definition: TimeSpan.h:45
Time related constants.
Definition: TimeSpan.h:54
Indicates time span in "HH:MM:SS" format.
Definition: TimeSpan.h:76
static const Seconds SecondsPerDay
Definition: TimeSpan.h:60
static const Picoseconds PicosecondsPerMicrosecond
Definition: TimeSpan.h:67
HugeInterval TotalMilliseconds
Definition: TimeSpan.h:48
UInt32 Amount
Definition: TimeSpan.h:31
bool operator!=(const FieldValueRef &ref, const std::string &str)
Interval Microseconds
Definition: TimeSpan.h:43
TotalSeconds totalSeconds() const
Total number of seconds.
Definition: TimeSpan.h:212
Nanosecond time span presentation.
Definition: TimeSpan.h:268
static const Hours HoursPerDay
Definition: TimeSpan.h:55
HugeInterval TotalSeconds
Definition: TimeSpan.h:47
static const Picoseconds PicosecondsPerSecond
Definition: TimeSpan.h:69
Int32 Interval
Definition: TimeSpan.h:34
HugeInterval TotalPicoseconds
Definition: TimeSpan.h:51
Interval Hours
Definition: TimeSpan.h:38
static const Minutes MinutesPerHour
Definition: TimeSpan.h:56
#define ONIXS_FIXENGINE_API
Definition: ABI.h:45
Interval Minutes
Definition: TimeSpan.h:39
static const Milliseconds MillisecondsPerSecond
Definition: TimeSpan.h:62
static const Microseconds MicrosecondsPerSecond
Definition: TimeSpan.h:63
Interval Nanoseconds
Definition: TimeSpan.h:44
Indicates time span in "HH:MM:SS.sssssssss" format.
Definition: TimeSpan.h:85
#define ONIXS_MINMAX_ABUSER
Definition: TimeSpan.h:27
UInt64 HugeAmount
Definition: TimeSpan.h:32
Microsecond time span presentation.
Definition: TimeSpan.h:260
HugeInterval TotalMicroseconds
Definition: TimeSpan.h:49
static const Picoseconds PicosecondsPerMillisecond
Definition: TimeSpan.h:68
static const Seconds SecondsPerMinute
Definition: TimeSpan.h:58
unsigned long long UInt64
Definition: Numeric.h:36
Hour time span presentation.
Definition: TimeSpan.h:231
bool operator==(const FieldValueRef &ref, const std::string &str)
Time span related functionality.
Definition: TimeSpan.h:93
Millisecond time span presentation.
Definition: TimeSpan.h:252
Picoseconds picoseconds() const
Current nanoseconds.
Definition: TimeSpan.h:219
long long Int64
Definition: Numeric.h:35
HugeInterval TotalNanoseconds
Definition: TimeSpan.h:50
Int64 HugeInterval
Definition: TimeSpan.h:35
unsigned int UInt32
Definition: Numeric.h:33
Interval Seconds
Definition: TimeSpan.h:40
Indicates time span in "HH:MM:SS.sss" format.
Definition: TimeSpan.h:79
Picoseconds picoseconds_
Definition: TimeSpan.h:205