OnixS C++ CME MDP Conflated UDP Handler  1.1.2
API documentation
Version.h
Go to the documentation of this file.
1 // Copyright Onix Solutions Limited [OnixS]. All rights reserved.
2 //
3 // This software owned by Onix Solutions Limited [OnixS] and is
4 // protected by copyright law and international copyright treaties.
5 //
6 // Access to and use of the software is governed by the terms of the applicable
7 // OnixS Software Services Agreement (the Agreement) and Customer end user license
8 // agreements granting a non-assignable, non-transferable and non-exclusive license
9 // to use the software for it's own data processing purposes under the terms defined
10 // in the Agreement.
11 //
12 // Except as otherwise granted within the terms of the Agreement, copying or
13 // reproduction of any part of this source code or associated reference material
14 // to any other location for further reproduction or redistribution, and any
15 // amendments to this copyright notice, are expressly prohibited.
16 //
17 // Any reproduction or redistribution for sale or hiring of the Software not in
18 // accordance with the terms of the Agreement is a violation of copyright law.
19 //
20 
21 #pragma once
22 
23 #include <string>
24 
27 
29 
30 /// Alias for the version numeric component.
32 
33 /// Identifies version of the product.
34 ///
35 /// Provides access to single components
36 /// which compound whole version, comparing
37 /// and serialization/deserialization facilities.
39 {
40  VersionComponent major_;
41  VersionComponent minor_;
42  VersionComponent patch_;
43 
44 public:
45  /// Alias for the numeric component.
46  typedef
49 
50  /// Initializes the instance from the given components.
52  Component major,
53  Component minor,
54  Component patch)
55  : major_(major)
56  , minor_(minor)
57  , patch_(patch)
58  {
59  }
60 
61  /// Initializes as a copy of the other instance.
63  const Version& other)
64  : major_(other.major_)
65  , minor_(other.minor_)
66  , patch_(other.patch_)
67  {
68  }
69 
70  /// 'major' component of the version.
71  Component (major)() const
72  {
73  return major_;
74  }
75 
76  /// 'minor' component of the version.
77  Component (minor)() const
78  {
79  return minor_;
80  }
81 
82  /// 'patch' component of the version.
83  Component patch() const
84  {
85  return patch_;
86  }
87 
88  /// Re-initializes the instance
89  /// as a copy of the other one.
90  Version&
91  operator =(
92  const Version& other)
93  {
94  major_ = other.major_;
95  minor_ = other.minor_;
96  patch_ = other.patch_;
97 
98  return *this;
99  }
100 
101  /// Identifies the current version of the product.
103  static Version current();
104 };
105 
106 /// Checks the given two instances for equality.
107 inline
108 bool
110  const Version& left,
111  const Version& right)
112 {
113  return
114  (
115  (left.major)() == (right.major)() &&
116  (left.minor)() == (right.minor)() &&
117  left.patch() == right.patch()
118  );
119 }
120 
121 /// Checks the given two instances for inequality.
122 inline
123 bool
125  const Version& left,
126  const Version& right)
127 {
128  return !(left == right);
129 }
130 
131 /// Establishes the order
132 /// between the given instances.
133 inline
134 bool
136  const Version& left,
137  const Version& right)
138 {
139  return (
140  (left.major)() < (right.major)()
141  || (
142  (left.major)() == (right.major)()
143  &&
144  (left.minor)() < (right.minor)())
145  || (
146  (left.major)() == (right.major)()
147  &&
148  (left.minor)() == (right.minor)()
149  &&
150  left.patch() < right.patch())
151  );
152 }
153 
154 /// Establishes the order
155 /// between the given instances.
156 inline
157 bool
159  const Version& left,
160  const Version& right)
161 {
162  return (right < left);
163 }
164 
165 /// Extracts version from point-separated presentation.
166 /// Updates version parameter if buffer is parsed successfully.
167 ONIXS_CONFLATEDUDP_EXPORTED
168 bool
169 fromStr(
170  const Char*,
171  size_t,
172  Version&);
173 
174 /// Appends point-separated presentation of version to given string.
175 ONIXS_CONFLATEDUDP_EXPORTED
176 void
177 toStr(
178  std::string&,
179  const Version&);
180 
181 /// Serializes Version instance into point-separated presentation.
182 inline
183 std::string
185  const Version& version)
186 {
187  std::string str;
188 
189  toStr(str, version);
190 
191  return str;
192 }
193 
bool operator<(const Version &left, const Version &right)
Definition: Version.h:135
Version(const Version &other)
Initializes as a copy of the other instance.
Definition: Version.h:62
Component() major() const
&#39;major&#39; component of the version.
Definition: Version.h:71
#define ONIXS_CONFLATEDUDP_LTWT_EXPORTED
Definition: Bootstrap.h:103
Component() minor() const
&#39;minor&#39; component of the version.
Definition: Version.h:77
Component patch() const
&#39;patch&#39; component of the version.
Definition: Version.h:83
bool operator!=(const Version &left, const Version &right)
Checks the given two instances for inequality.
Definition: Version.h:124
char Char
Character type alias.
Definition: String.h:36
std::string toStr(const Version &version)
Serializes Version instance into point-separated presentation.
Definition: Version.h:184
bool operator==(const Version &left, const Version &right)
Checks the given two instances for equality.
Definition: Version.h:109
ONIXS_CONFLATEDUDP_EXPORTED bool fromStr(const Char *, size_t, Version &)
#define ONIXS_CONFLATEDUDP_NAMESPACE_END
Definition: Bootstrap.h:157
UInt16 UInt16
uInt16.
Definition: Fields.h:257
bool operator>(const Version &left, const Version &right)
Definition: Version.h:158
VersionComponent Component
Alias for the numeric component.
Definition: Version.h:48
UInt16 VersionComponent
Alias for the version numeric component.
Definition: Version.h:31
#define ONIXS_CONFLATEDUDP_LTWT_CLASS
Definition: Bootstrap.h:95
#define ONIXS_CONFLATEDUDP_NAMESPACE_BEGIN
Definition: Bootstrap.h:153
Version(Component major, Component minor, Component patch)
Initializes the instance from the given components.
Definition: Version.h:51