OnixS C++ EuroTLX GTP Market Data Handler  1.4.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 
23 
24 #include <string>
25 
26 
27 namespace OnixS
28 {
29  namespace EuroTLX
30  {
31  namespace MarketData
32  {
33  namespace GTP
34  {
35  /// Time span formats supported.
36  struct ONIXS_EUROTLX_GTP_API TimeSpanFormats
37  {
38  enum Enum
39  {
40  /// HH:MM:SS.
42 
43  /// HH:MM:SS.sss.
45 
46  /// HH:MM:SS.sssssssss.
47  SDHHMMSSnsec
48  };
49  };
50 
51  /// Time span format.
53 
54  /// Represents time interval. Used primarily to
55  /// present time-only stamps and to measure time
56  /// intervals between two timestamps.
57  class ONIXS_EUROTLX_GTP_API TimeSpan
58  {
59  public:
60  /// Initializes zero span.
61  TimeSpan();
62 
63  /// Initializes with given set of values.
64  /// Input parameters are treated as quantities,
65  /// but not as a time stamp. Therefore, there's
66  /// no requirement to fit in a certain range like
67  /// hours must fit into [0, 24) range. After
68  /// initialization time span will be normalized.
69  TimeSpan (int hours, int minutes, int seconds, int nanoseconds = 0);
70 
71  /// Initializes with given set of values.
72  /// Input parameters are treated as quantities,
73  /// but not as a time stamp. Therefore, there's
74  /// no requirement to fit in a certain range like
75  /// hours must fit into [0, 24) range. After
76  /// initialization time span will be normalized.
77  TimeSpan (int days, int hours, int minutes, int seconds, int nanoseconds);
78 
79  /// Initializes time interval from total number
80  /// seconds and its fractional (nanosecond) part.
81  TimeSpan (long long totalSeconds, int nanoseconds);
82 
83  /// Initializes as clone of other instance.
84  TimeSpan (const TimeSpan& other);
85 
86  /// Whole number of seconds in time interval.
87  long long totalSeconds() const;
88 
89  /// Days component of time interval.
90  /// Whole number of days in time interval.
91  int days() const;
92 
93  /// Hours component of time interval.
94  /// Values are in range from -23 through 23.
95  int hours() const;
96 
97  /// Minutes component of time interval.
98  /// Values are in range from -59 through 59.
99  int minutes() const;
100 
101  /// Seconds component of time interval.
102  /// Values are in range from -59 through 59.
103  int seconds() const;
104 
105  /// Milliseconds component of time interval.
106  /// Values are in range from -999 through 999.
107  int milliseconds() const;
108 
109  /// Microseconds component of time interval.
110  /// Values are in range from -999999 through 999999.
111  int microseconds() const;
112 
113  /// Nanoseconds component of time interval.
114  /// Values are in range from -999999999 through 999999999.
115  int nanoseconds() const;
116 
117  /// Compares with other instance for equality.
118  bool operator == (const TimeSpan& other) const;
119 
120  /// Compares with other instance for in-equality.
121  bool operator != (const TimeSpan& other) const;
122 
123  /// Checks whether time interval less than other one.
124  bool operator < (const TimeSpan& other) const;
125 
126  /// Checks whether time interval greater than other one.
127  bool operator > (const TimeSpan& other) const;
128 
129  /// Adds time interval to current one.
130  TimeSpan& operator += (const TimeSpan& other);
131 
132  /// Subtracts time interval from current one.
133  TimeSpan& operator -= (const TimeSpan& other);
134 
135  /// Re-assigns time interval from other one.
136  TimeSpan& operator = (const TimeSpan& other);
137 
138  /// Serializes time stamp into text presentation
139  /// using specified time-span presentation format.
140  void toString (std::string& str, TimeSpanFormat format = TimeSpanFormats::SDHHMMSSnsec) const;
141 
142  /// Serializes time stamp into text presentation
143  /// using specified time-span presentation format.
144  std::string toString (TimeSpanFormat format = TimeSpanFormats::SDHHMMSSnsec) const;
145 
146  /// De-serializes time interval from its text presentation.
147  static TimeSpan deserialize (const std::string& str);
148 
149  /// Time interval of zero length.
150  static const TimeSpan Zero;
151 
152  private:
153  long long seconds_;
154  int nanoseconds_;
155  };
156 
157  inline long long TimeSpan::totalSeconds() const
158  {
159  return seconds_;
160  }
161 
162  inline int TimeSpan::nanoseconds() const
163  {
164  return nanoseconds_;
165  }
166 
167  inline std::string TimeSpan::toString (TimeSpanFormat format) const
168  {
169  std::string str;
170 
171  toString (str, format);
172 
173  return str;
174  }
175  }
176  }
177  }
178 }
179 
180 
181 
bool operator>(const FixedPointDecimal< Mantissa, Exponent > &left, const FixedPointDecimal< Mantissa, Exponent > &right)
Compares two fixed-point decimals.
Definition: Decimal.h:166
long long totalSeconds() const
Whole number of seconds in time interval.
Definition: TimeSpan.h:157
Time span formats supported.
Definition: TimeSpan.h:36
bool operator==(const FixedPointDecimal< Mantissa, Exponent > &left, const FixedPointDecimal< Mantissa, Exponent > &right)
Compares two fixed-point decimals.
Definition: Decimal.h:139
TimeSpanFormats::Enum TimeSpanFormat
Time span format.
Definition: TimeSpan.h:52
bool operator!=(const FixedPointDecimal< Mantissa, Exponent > &left, const FixedPointDecimal< Mantissa, Exponent > &right)
Compares two fixed-point decimals.
Definition: Decimal.h:148
bool operator<(const FixedPointDecimal< Mantissa, Exponent > &left, const FixedPointDecimal< Mantissa, Exponent > &right)
Compares two fixed-point decimals.
Definition: Decimal.h:157
void toString(std::string &str, TimeSpanFormat format=TimeSpanFormats::SDHHMMSSnsec) const
static const TimeSpan Zero
Time interval of zero length.
Definition: TimeSpan.h:150