release 0.1.6
[liba.git] / include / a / version.h
blobe584bfa3afa11d3969c6013c439e22aa103f691b
1 /*!
2 @file version.h
3 @brief algorithm library version
4 */
6 #ifndef LIBA_VERSION_H
7 #define LIBA_VERSION_H
9 #include "a.h"
11 /*!
12 @ingroup A
13 @addtogroup A_VERSION algorithm library version
17 /*! algorithm library version major */
18 #ifndef A_VERSION_MAJOR
19 #define A_VERSION_MAJOR 0
20 #endif /* A_VERSION_MAJOR */
21 #undef major
23 /*! algorithm library version minor */
24 #ifndef A_VERSION_MINOR
25 #define A_VERSION_MINOR 1
26 #endif /* A_VERSION_MINOR */
27 #undef minor
29 /*! algorithm library version patch */
30 #ifndef A_VERSION_PATCH
31 #define A_VERSION_PATCH 6
32 #endif /* A_VERSION_PATCH */
33 #undef patch
35 /*! algorithm library version tweak */
36 #ifndef A_VERSION_TWEAK
37 #define A_VERSION_TWEAK 20240229
38 #endif /* A_VERSION_TWEAK */
40 #define A_VERSION_TOSTR(X) A_CAST_1(X)
41 /*! algorithm library version string */
42 #ifndef A_VERSION
43 #define A_VERSION A_VERSION_TOSTR(A_VERSION_MAJOR) "." A_VERSION_TOSTR(A_VERSION_MINOR) "." A_VERSION_TOSTR(A_VERSION_PATCH)
44 #endif /* A_VERSION */
46 typedef struct a_version a_version;
47 // clang-format off
48 #if defined(__cplusplus)
49 #define A_VERSION_C(major, minor, third) {major, minor, third, 0}
50 #define A_VERSION_EX(major, minor, third, extra) {major, minor, third, extra}
51 #else /* !__cplusplus */
52 #define A_VERSION_C(major, minor, third) (a_version){major, minor, third, 0}
53 #define A_VERSION_EX(major, minor, third, extra) (a_version){major, minor, third, extra}
54 #endif /* __cplusplus */
55 // clang-format on
57 #if defined(__cplusplus)
58 namespace a
60 typedef a_version version;
61 } /* namespace a */
62 extern "C" {
63 #endif /* __cplusplus */
65 /*! algorithm library version major */
66 A_EXTERN unsigned int const a_version_major;
67 /*! algorithm library version minor */
68 A_EXTERN unsigned int const a_version_minor;
69 /*! algorithm library version patch */
70 A_EXTERN unsigned int const a_version_patch;
71 /*! algorithm library version tweak */
72 A_EXTERN a_u32 const a_version_tweak;
74 /*!
75 @brief algorithm library version check
76 @param[in] major required major number
77 @param[in] minor required minor number
78 @param[in] patch required patch number
79 @return result of comparison
80 @retval <0 library version is higher than required version
81 @retval >0 library version is lower than required version
82 @retval 0 library version is equal to required version
84 A_EXTERN int a_version_check(unsigned int major, unsigned int minor, unsigned int patch);
85 #define a_version_check() a_version_check(A_VERSION_MAJOR, A_VERSION_MINOR, A_VERSION_PATCH)
87 /*!
88 @brief compare the version lhs with the version rhs
89 @param[in] lhs version structure to be compared
90 @param[in] rhs version structure to be compared
91 @return relationship between the versions
92 @retval <0 version lhs < version rhs
93 @retval >0 version lhs > version rhs
94 @retval 0 version lhs == version rhs
96 A_EXTERN int a_version_cmp(a_version const *lhs, a_version const *rhs);
98 /*!
99 @brief version lhs is less than version rhs
100 @param[in] lhs operand on the left
101 @param[in] rhs operand on the right
102 @return result of comparison
104 A_EXTERN a_bool a_version_lt(a_version const *lhs, a_version const *rhs);
107 @brief version lhs is greater than version rhs
108 @param[in] lhs operand on the left
109 @param[in] rhs operand on the right
110 @return result of comparison
112 A_EXTERN a_bool a_version_gt(a_version const *lhs, a_version const *rhs);
115 @brief version lhs is less than or equal to version rhs
116 @param[in] lhs operand on the left
117 @param[in] rhs operand on the right
118 @return result of comparison
120 A_EXTERN a_bool a_version_le(a_version const *lhs, a_version const *rhs);
123 @brief version lhs is greater than or equal to version rhs
124 @param[in] lhs operand on the left
125 @param[in] rhs operand on the right
126 @return result of comparison
128 A_EXTERN a_bool a_version_ge(a_version const *lhs, a_version const *rhs);
131 @brief version lhs is equal to version rhs
132 @param[in] lhs operand on the left
133 @param[in] rhs operand on the right
134 @return result of comparison
136 A_EXTERN a_bool a_version_eq(a_version const *lhs, a_version const *rhs);
139 @brief version lhs is not equal to version rhs
140 @param[in] lhs operand on the left
141 @param[in] rhs operand on the right
142 @return result of comparison
144 A_EXTERN a_bool a_version_ne(a_version const *lhs, a_version const *rhs);
147 @brief algorithm library version parse
148 @param[in,out] ctx points to an instance structure for version
149 @param[in] ver version string to be parsed
150 @return number of parsed characters
152 A_EXTERN unsigned int a_version_parse(a_version *ctx, char const *ver);
154 #if defined(__cplusplus)
155 } /* extern "C" */
156 #endif /* __cplusplus */
159 @brief instance structure for version
161 struct a_version
163 unsigned int major; //!< major number
164 unsigned int minor; //!< minor number
165 unsigned int third; //!< third number
166 unsigned int extra; //!< extra number
167 #if defined(__cplusplus)
168 A_INLINE int cmp(a_version const &ver) const
170 return a_version_cmp(this, &ver);
172 A_INLINE bool operator<(a_version const &ver) const
174 return a_version_lt(this, &ver);
176 A_INLINE bool operator>(a_version const &ver) const
178 return a_version_gt(this, &ver);
180 A_INLINE bool operator<=(a_version const &ver) const
182 return a_version_le(this, &ver);
184 A_INLINE bool operator>=(a_version const &ver) const
186 return a_version_ge(this, &ver);
188 A_INLINE bool operator==(a_version const &ver) const
190 return a_version_eq(this, &ver);
192 A_INLINE bool operator!=(a_version const &ver) const
194 return a_version_ne(this, &ver);
196 A_INLINE unsigned int parse(char const *ver)
198 return a_version_parse(this, ver);
200 /*! algorithm library version major */
201 A_PUBLIC static unsigned int const MAJOR;
202 /*! algorithm library version minor */
203 A_PUBLIC static unsigned int const MINOR;
204 /*! algorithm library version patch */
205 A_PUBLIC static unsigned int const PATCH;
206 /*! algorithm library version tweak */
207 A_PUBLIC static a_u32 const TWEAK;
208 #endif /* __cplusplus */
211 /*! @} A_VERSION */
213 #endif /* a/version.h */