Debian Codegraph @

3rdparty/xspublic/xstypes/xssimpleversion.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 XSSIMPLEVERSION_H
34 #define XSSIMPLEVERSION_H
35
36 #include "xstypesconfig.h"
37
38 #undef minor
39 #undef major
40
41 typedef struct XsSimpleVersion XsSimpleVersion;
42
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 #ifndef __cplusplus
47 #define XSSIMPLEVERSION_INITIALIZER { 0, 0, 0 }
48 #endif
49
50 XSTYPES_DLL_API int XsSimpleVersion_empty(const XsSimpleVersion* thisPtr);
51 XSTYPES_DLL_API void XsSimpleVersion_swap(XsSimpleVersion* a, XsSimpleVersion* b);
52 XSTYPES_DLL_API int XsSimpleVersion_compare(XsSimpleVersion const* a, XsSimpleVersion const* b);
53
54 #ifdef __cplusplus
55 } // extern "C"
56 #endif
57
58 struct XsSimpleVersion {
59 #ifdef __cplusplus
60 //! \brief Constructs a simple-version object using the supplied parameters or an empty version object if no parameters are given.
61 explicit XsSimpleVersion(int vmaj = 0, int vmin = 0, int vrev = 0)
62 : m_major((uint8_t) vmaj)
63 , m_minor((uint8_t) vmin)
64 , m_revision((uint8_t) vrev)
65 {}
66
67 //! \brief Constructs a simple-version object based upon the \a other object
68 XsSimpleVersion(const XsSimpleVersion& other)
69 : m_major(other.m_major)
70 , m_minor(other.m_minor)
71 , m_revision(other.m_revision)
72 {}
73
74 //! \brief Assign the simple-version from the \a other object
75 XsSimpleVersion& operator = (const XsSimpleVersion& other)
76 {
77 m_major = other.m_major;
78 m_minor = other.m_minor;
79 m_revision = other.m_revision;
80 return *this;
81 }
82
83 /*! \brief Test if the \a other simple-version is equal to this. */
84 inline bool operator == (const XsSimpleVersion& other) const
85 {
86 return !XsSimpleVersion_compare(this, &other);
87 }
88
89 /*! \brief Test if the \a other simple-version is different to this. */
90 inline bool operator != (const XsSimpleVersion& other) const
91 {
92 if (m_major != other.m_major || m_minor != other.m_minor || m_revision != other.m_revision)
93 return true;
94
95 return false;
96 }
97
98 /*! \brief Test if the \a other version is lower than this. The comparison involves only the version numbers (major, minor and revision). */
99 inline bool operator < (const XsSimpleVersion& other) const
100 {
101 if (m_major < other.m_major)
102 return true;
103 else if (m_major > other.m_major)
104 return false;
105 else
106 {
107 if (m_minor < other.m_minor)
108 return true;
109 else if (m_minor > other.m_minor)
110 return false;
111 else
112 {
113 if (m_revision < other.m_revision)
114 return true;
115 else
116 return false;
117 }
118 }
119 }
120
121 /*! \brief Test if the \a other version is lower or equal than this. */
122 inline bool operator <= (const XsSimpleVersion& other) const
123 {
124 return (*this == other) || (*this < other);
125 }
126
127 /*! \brief Test if the \a other version is higher than this. */
128 inline bool operator > (const XsSimpleVersion& other) const
129 {
130 return !(*this <= other);
131 }
132
133 /*! \brief Test if the \a other version is higher or equal than this. */
134 inline bool operator >= (const XsSimpleVersion& other) const
135 {
136 return (*this == other) || (*this > other);
137 }
138
139 //! \brief \copybrief XsSimpleVersion_empty
140 inline bool empty() const
141 {
142 return 0 != XsSimpleVersion_empty(this);
143 }
144
145 //! \brief Return the \e major part of the version
146 inline int major() const { return (int) m_major; }
147 //! \brief Return the \e minor part of the version
148 inline int minor() const { return (int) m_minor; }
149 //! \brief Return the \e revision part of the version
150 inline int revision() const { return (int) m_revision; }
151
152 private:
153 #endif
154 uint8_t m_major; //!< The major part of the version number
155 uint8_t m_minor; //!< The minor part of the version number
156 uint8_t m_revision; //!< The revision number of the version
157 };
158
159 #endif