1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
/*!
@file version.h
@brief algorithm library version
*/
#ifndef LIBA_VERSION_H
#define LIBA_VERSION_H
#include "a.h"
/*!
@ingroup liba
@addtogroup a_version algorithm library version
@{
*/
/*! algorithm library version major */
#ifndef A_VERSION_MAJOR
#define A_VERSION_MAJOR 0
#endif /* A_VERSION_MAJOR */
#undef major
/*! algorithm library version minor */
#ifndef A_VERSION_MINOR
#define A_VERSION_MINOR 1
#endif /* A_VERSION_MINOR */
#undef minor
/*! algorithm library version patch */
#ifndef A_VERSION_PATCH
#define A_VERSION_PATCH 15
#endif /* A_VERSION_PATCH */
#undef patch
/*! algorithm library version tweak */
#ifndef A_VERSION_TWEAK
#define A_VERSION_TWEAK 20240930
#endif /* A_VERSION_TWEAK */
#define A_VERSION_TOSTR(X) A_CAST_1(X)
/*! algorithm library version string */
#ifndef A_VERSION
#define A_VERSION A_VERSION_TOSTR(A_VERSION_MAJOR) "." A_VERSION_TOSTR(A_VERSION_MINOR) "." A_VERSION_TOSTR(A_VERSION_PATCH)
#endif /* A_VERSION */
typedef struct a_version a_version;
#define A_VERSION_0() A_VERSION_1(0)
#define A_VERSION_1(major) A_VERSION_2(major, 0)
#define A_VERSION_2(major, minor) A_VERSION_3(major, minor, 0)
#define A_VERSION_3(major, minor, third) A_VERSION_4(major, minor, third, 0)
// clang-format off
#if defined(__cplusplus)
#define A_VERSION_4(major, minor, third, extra) {major, minor, third, extra, {'.', 0, 0, 0}}
#else /* !__cplusplus */
#define A_VERSION_4(major, minor, third, extra) (a_version){major, minor, third, extra, {'.', 0, 0, 0}}
#endif /* __cplusplus */
// clang-format on
#if defined(__cplusplus)
namespace a
{
typedef a_version version;
} /* namespace a */
extern "C" {
#endif /* __cplusplus */
/*! algorithm library version major */
A_EXTERN unsigned int const a_version_major;
/*! algorithm library version minor */
A_EXTERN unsigned int const a_version_minor;
/*! algorithm library version patch */
A_EXTERN unsigned int const a_version_patch;
/*! algorithm library version tweak */
A_EXTERN a_u32 const a_version_tweak;
/*!
@brief algorithm library version check
@param[in] major required major number
@param[in] minor required minor number
@param[in] patch required patch number
@return result of comparison
@retval <0 library version is higher than required version
@retval >0 library version is lower than required version
@retval 0 library version is equal to required version
*/
A_EXTERN int a_version_check(unsigned int major, unsigned int minor, unsigned int patch);
#define A_VERSION_CHECK() a_version_check(A_VERSION_MAJOR, A_VERSION_MINOR, A_VERSION_PATCH)
/*!
@brief convert version to string
@param[in] ctx points to an instance structure for version
@param[in] pdata points to string buffer
@param[in] nbyte length of string buffer
@return number of used characters
*/
A_EXTERN unsigned int a_version_tostr(a_version const *ctx, void *pdata, a_size nbyte);
/*!
@brief parse version string to version
@param[in,out] ctx points to an instance structure for version
@param[in] ver version string to be parsed
@return number of parsed characters
*/
A_EXTERN unsigned int a_version_parse(a_version *ctx, char const *ver);
/*!
@brief compare the version `lhs` with the version `rhs`
@param[in] lhs version structure to be compared
@param[in] rhs version structure to be compared
@return relationship between the versions
@retval <0 version `lhs` < version `rhs`
@retval >0 version `lhs` > version `rhs`
@retval 0 version `lhs` == version `rhs`
*/
A_EXTERN int a_version_cmp(a_version const *lhs, a_version const *rhs);
/*!
@brief version lhs is less than version rhs
@param[in] lhs operand on the left
@param[in] rhs operand on the right
@return result of comparison
*/
A_EXTERN a_bool a_version_lt(a_version const *lhs, a_version const *rhs);
/*!
@brief version lhs is greater than version rhs
@param[in] lhs operand on the left
@param[in] rhs operand on the right
@return result of comparison
*/
A_EXTERN a_bool a_version_gt(a_version const *lhs, a_version const *rhs);
/*!
@brief version lhs is less than or equal to version rhs
@param[in] lhs operand on the left
@param[in] rhs operand on the right
@return result of comparison
*/
A_EXTERN a_bool a_version_le(a_version const *lhs, a_version const *rhs);
/*!
@brief version lhs is greater than or equal to version rhs
@param[in] lhs operand on the left
@param[in] rhs operand on the right
@return result of comparison
*/
A_EXTERN a_bool a_version_ge(a_version const *lhs, a_version const *rhs);
/*!
@brief version lhs is equal to version rhs
@param[in] lhs operand on the left
@param[in] rhs operand on the right
@return result of comparison
*/
A_EXTERN a_bool a_version_eq(a_version const *lhs, a_version const *rhs);
/*!
@brief version lhs is not equal to version rhs
@param[in] lhs operand on the left
@param[in] rhs operand on the right
@return result of comparison
*/
A_EXTERN a_bool a_version_ne(a_version const *lhs, a_version const *rhs);
/*!
@brief set alphabet for version
@param[in,out] ctx points to an instance structure for version
@param[in] alpha new alphabet
*/
A_EXTERN void a_version_set_alpha(a_version *ctx, char const *alpha);
/*!
@brief get alphabet for version
@param[in] ctx points to an instance structure for version
@param[out] alpha string buffer, >sizeof(ctx->alpha)
*/
A_EXTERN void a_version_alpha(a_version const *ctx, char alpha[5]);
#if defined(__cplusplus)
} /* extern "C" */
#endif /* __cplusplus */
/*!
@brief instance structure for version
*/
struct a_version
{
unsigned int major; //!< major number
unsigned int minor; //!< minor number
unsigned int third; //!< third number
unsigned int extra; //!< extra number
char alpha_[4]; //!< alphabet
#if defined(__cplusplus)
A_INLINE void alpha(char str[5]) const
{
a_version_alpha(this, str);
}
A_INLINE void set_alpha(char const *str)
{
a_version_set_alpha(this, str);
}
A_INLINE unsigned int parse(char const *ver)
{
return a_version_parse(this, ver);
}
A_INLINE unsigned int tostr(void *p, a_size n) const
{
return a_version_tostr(this, p, n);
}
A_INLINE bool operator<(a_version const &ver) const
{
return a_version_lt(this, &ver);
}
A_INLINE bool operator>(a_version const &ver) const
{
return a_version_gt(this, &ver);
}
A_INLINE bool operator<=(a_version const &ver) const
{
return a_version_le(this, &ver);
}
A_INLINE bool operator>=(a_version const &ver) const
{
return a_version_ge(this, &ver);
}
A_INLINE bool operator==(a_version const &ver) const
{
return a_version_eq(this, &ver);
}
A_INLINE bool operator!=(a_version const &ver) const
{
return a_version_ne(this, &ver);
}
A_INLINE int cmp(a_version const &ver) const
{
return a_version_cmp(this, &ver);
}
#endif /* __cplusplus */
};
/*! @} a_version */
#endif /* a/version.h */