Debian Codegraph @

3rdparty/xspublic/xstypes/xsversion.h

raw
1
2 // Copyright (c) 2003-2019 Xsens Technologies B.V. or subsidiaries worldwide.
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification,
6 // are permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice,
9 // this list of conditions, and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions, and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution.
14 //
15 // 3. Neither the names of the copyright holders nor the names of their contributors
16 // may be used to endorse or promote products derived from this software without
17 // specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 // THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24 // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR
26 // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS
28 // SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES
29 // OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE
30 // ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES.
31 //
32
33 #ifndef XSVERSION_H
34 #define XSVERSION_H
35
36 #include "xstypesconfig.h"
37 #include "xssimpleversion.h"
38 #include "xsstring.h"
39
40 #undef minor
41 #undef major
42
43 typedef struct XsVersion XsVersion;
44
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 #ifndef __cplusplus
49 #define XSVERSION_INITIALIZER { 0, 0, 0, 0, 0, XsString_INITIALIZER }
50 #endif
51
52 XSTYPES_DLL_API int XsVersion_empty(const XsVersion* thisPtr);
53 XSTYPES_DLL_API void XsVersion_toString(const XsVersion* thisPtr, XsString* version);
54 XSTYPES_DLL_API void XsVersion_fromString(XsVersion* thisPtr, const XsString* version);
55 XSTYPES_DLL_API void XsVersion_fromSimpleVersion(XsVersion* thisPtr, const XsSimpleVersion* simpleVersion);
56 XSTYPES_DLL_API void XsVersion_toSimpleVersion(const XsVersion* thisPtr, XsSimpleVersion* simpleVersion);
57 XSTYPES_DLL_API void XsVersion_toSimpleString(const XsVersion* thisPtr, XsString* version);
58
59 #ifdef __cplusplus
60 } // extern "C"
61 #endif
62
63 struct XsVersion {
64 #ifdef __cplusplus
65 //! \brief Constructs a version object using the supplied parameters or an empty version object if no parameters are given.
66 explicit XsVersion(int maj, int min, int rev, int build, const XsString& extra)
67 : m_major(maj)
68 , m_minor(min)
69 , m_revision(rev)
70 , m_build(build)
71 , m_reposVersion(0)
72 , m_extra(extra)
73 {}
74
75 //! \brief Constructs a version object using the supplied parameters or an empty version object if no parameters are given.
76 explicit XsVersion(int maj = 0, int min = 0, int rev = 0, int build = 0, int reposVersion = 0, const XsString& extra = XsString())
77 : m_major(maj)
78 , m_minor(min)
79 , m_revision(rev)
80 , m_build(build)
81 , m_reposVersion(reposVersion)
82 , m_extra(extra)
83 {}
84
85 //! \brief Constructs a version object based upon the version contained by \a vString.
86 explicit XsVersion(const XsString& vString)
87 {
88 XsVersion_fromString(this, &vString);
89 }
90
91 //! \brief Constructs a version object based upon the version contained by \a simpleVersion.
92 explicit XsVersion(const XsSimpleVersion& simpleVersion)
93 {
94 XsVersion_fromSimpleVersion(this, &simpleVersion);
95 }
96
97 //! \brief Constructs a version object based upon the \a other object
98 XsVersion(const XsVersion& other)
99 : m_major(other.m_major)
100 , m_minor(other.m_minor)
101 , m_revision(other.m_revision)
102 , m_build(other.m_build)
103 , m_reposVersion(other.m_reposVersion)
104 , m_extra(other.m_extra)
105 {}
106
107 //! \brief Assign the version from the \a other object
108 XsVersion& operator = (const XsVersion& other)
109 {
110 m_major = other.m_major;
111 m_minor = other.m_minor;
112 m_revision = other.m_revision;
113 m_build = other.m_build;
114 m_reposVersion = other.m_reposVersion;
115 m_extra = other.m_extra;
116 return *this;
117 }
118
119 /*! \brief Test if the \a other version is equal to this. The comparison involves the entire object.*/
120 inline bool isEqual (const XsVersion& other) const
121 {
122 return (*this == other) && (m_build == other.m_build) && (m_extra == other.m_extra) && (m_reposVersion == other.m_reposVersion);
123 }
124
125 /*! \brief Test if the \a other version is equal to this. The comparison involves only the version numbers (major, minor and revision). */
126 inline bool operator == (const XsVersion& other) const
127 {
128 if (m_major == other.m_major && m_minor == other.m_minor && m_revision == other.m_revision)
129 return true;
130
131 return false;
132 }
133
134 /*! \brief Test if the \a other version is NOT equal to this. The comparison involves only the version numbers (major, minor and revision). */
135 inline bool operator != (const XsVersion& other) const
136 {
137 return !(*this == other);
138 }
139
140 /*! \brief Test if the \a other version is lower than this. The comparison involves only the version numbers (major, minor and revision). */
141 inline bool operator < (const XsVersion& other) const
142 {
143 if (m_major < other.m_major)
144 return true;
145 else if (m_major > other.m_major)
146 return false;
147 else
148 {
149 if (m_minor < other.m_minor)
150 return true;
151 else if (m_minor > other.m_minor)
152 return false;
153 else
154 {
155 if (m_revision < other.m_revision)
156 return true;
157 else
158 return false;
159 }
160 }
161 }
162
163 /*! \brief Test if the \a other version is lower or equal than this. The comparison involves only the version numbers (major, minor and revision). */
164 inline bool operator <= (const XsVersion& other) const
165 {
166 return (*this == other) || (*this < other);
167 }
168
169 /*! \brief Test if the \a other version is higher than this. The comparison involves only the version numbers (major, minor and revision). */
170 inline bool operator > (const XsVersion& other) const
171 {
172 return !(*this <= other);
173 }
174
175 /*! \brief Test if the \a other version is higher or equal than this. The comparison involves only the version numbers (major, minor and revision). */
176 inline bool operator >= (const XsVersion& other) const
177 {
178 return (*this == other) || (*this > other);
179 }
180
181 //! \brief \copybrief XsVersion_empty
182 inline bool empty() const
183 {
184 return 0 != XsVersion_empty(this);
185 }
186
187 //! \brief \copybrief XsVersion_toString
188 inline XsString toString() const
189 {
190 XsString tmp;
191 XsVersion_toString(this, &tmp);
192 return tmp;
193 }
194
195 //! \brief \copybrief XsVersion_toSimpleString
196 inline XsString toSimpleString() const
197 {
198 XsString tmp;
199 XsVersion_toSimpleString(this, &tmp);
200 return tmp;
201 }
202
203 //! \brief \copybrief XsVersion_toSimpleVersion
204 inline XsSimpleVersion toSimpleVersion() const
205 {
206 XsSimpleVersion result;
207 XsVersion_toSimpleVersion(this, &result);
208 return result;
209 }
210
211 //! \brief Return the \e major part of the version
212 inline int major() const { return m_major; }
213 //! \brief Return the \e minor part of the version
214 inline int minor() const { return m_minor; }
215 //! \brief Return the \e revision part of the version
216 inline int revision() const { return m_revision; }
217 //! \brief Return the \e build number used for this build
218 inline int build() const { return m_build; }
219 //! \brief Return the \e source revision used for this build
220 inline int reposVersion() const { return m_reposVersion;}
221 //! \brief Return the extra part of the version. This may contain custom version details such as 'beta' or 'Mk4' to indicate the readiness and purpose of this version of the object.
222 inline const XsString& extra() const { return m_extra; }
223
224 //! \brief Set the \e major part of the version
225 inline void setMajor(int major) { m_major = major; }
226 //! \brief Set the \e minor part of the version
227 inline void setMinor(int minor) { m_minor = minor; }
228 //! \brief Set the \e revision part of the version
229 inline void setRevision(int revision) { m_revision = revision; }
230 //! \brief Set the \e build part of the version
231 inline void setBuild(int build) { m_build = build; }
232 //! \brief Set the \e reposVersion part of the version
233 inline void setReposVersion(int reposVersion) { m_reposVersion = reposVersion; }
234 //! \brief Set the \e extra part of the version. This may contain custom version details such as 'beta' or 'Mk4' to indicate the readiness and purpose of this version of the object.
235 inline void setExtra(const XsString& extra) { m_extra = extra; }
236
237 private:
238 #endif
239
240 int m_major; //!< The major part of the version number
241 int m_minor; //!< The minor part of the version number
242 int m_revision; //!< The revision number of the version
243 int m_build; //!< The build number for this build
244 int m_reposVersion; //!< The source revision used for this build
245 XsString m_extra; //!< Storage for some extra information about the version
246 };
247
248 #endif