liba 0.1.15
An algorithm library based on C/C++
Loading...
Searching...
No Matches
version.h
Go to the documentation of this file.
1
6#ifndef LIBA_VERSION_H
7#define LIBA_VERSION_H
8
9#include "a.h"
10
18#ifndef A_VERSION_MAJOR
19#define A_VERSION_MAJOR 0
20#endif /* A_VERSION_MAJOR */
21#undef major
22
24#ifndef A_VERSION_MINOR
25#define A_VERSION_MINOR 1
26#endif /* A_VERSION_MINOR */
27#undef minor
28
30#ifndef A_VERSION_PATCH
31#define A_VERSION_PATCH 15
32#endif /* A_VERSION_PATCH */
33#undef patch
34
36#ifndef A_VERSION_TWEAK
37#define A_VERSION_TWEAK 20240930
38#endif /* A_VERSION_TWEAK */
39
40#define A_VERSION_TOSTR(X) A_CAST_1(X)
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 */
45
46typedef struct a_version a_version;
47#define A_VERSION_0() A_VERSION_1(0)
48#define A_VERSION_1(major) A_VERSION_2(major, 0)
49#define A_VERSION_2(major, minor) A_VERSION_3(major, minor, 0)
50#define A_VERSION_3(major, minor, third) A_VERSION_4(major, minor, third, 0)
51// clang-format off
52#if defined(__cplusplus)
53#define A_VERSION_4(major, minor, third, extra) {major, minor, third, extra, {'.', 0, 0, 0}}
54#else /* !__cplusplus */
55#define A_VERSION_4(major, minor, third, extra) (a_version){major, minor, third, extra, {'.', 0, 0, 0}}
56#endif /* __cplusplus */
57// clang-format on
58
59#if defined(__cplusplus)
60namespace a
61{
62typedef a_version version;
63} /* namespace a */
64extern "C" {
65#endif /* __cplusplus */
66
68A_EXTERN unsigned int const a_version_major;
70A_EXTERN unsigned int const a_version_minor;
72A_EXTERN unsigned int const a_version_patch;
74A_EXTERN a_u32 const a_version_tweak;
75
86A_EXTERN int a_version_check(unsigned int major, unsigned int minor, unsigned int patch);
87#define A_VERSION_CHECK() a_version_check(A_VERSION_MAJOR, A_VERSION_MINOR, A_VERSION_PATCH)
88
96A_EXTERN unsigned int a_version_tostr(a_version const *ctx, void *pdata, a_size nbyte);
97
104A_EXTERN unsigned int a_version_parse(a_version *ctx, char const *ver);
105
115A_EXTERN int a_version_cmp(a_version const *lhs, a_version const *rhs);
116
123A_EXTERN a_bool a_version_lt(a_version const *lhs, a_version const *rhs);
124
131A_EXTERN a_bool a_version_gt(a_version const *lhs, a_version const *rhs);
132
139A_EXTERN a_bool a_version_le(a_version const *lhs, a_version const *rhs);
140
147A_EXTERN a_bool a_version_ge(a_version const *lhs, a_version const *rhs);
148
155A_EXTERN a_bool a_version_eq(a_version const *lhs, a_version const *rhs);
156
163A_EXTERN a_bool a_version_ne(a_version const *lhs, a_version const *rhs);
164
170A_EXTERN void a_version_set_alpha(a_version *ctx, char const *alpha);
171
177A_EXTERN void a_version_alpha(a_version const *ctx, char alpha[5]);
178
179#if defined(__cplusplus)
180} /* extern "C" */
181#endif /* __cplusplus */
182
187{
188 unsigned int major;
189 unsigned int minor;
190 unsigned int third;
191 unsigned int extra;
192 char alpha_[4];
193#if defined(__cplusplus)
194 A_INLINE void alpha(char str[5]) const
195 {
196 a_version_alpha(this, str);
197 }
198 A_INLINE void set_alpha(char const *str)
199 {
200 a_version_set_alpha(this, str);
201 }
202 A_INLINE unsigned int parse(char const *ver)
203 {
204 return a_version_parse(this, ver);
205 }
206 A_INLINE unsigned int tostr(void *p, a_size n) const
207 {
208 return a_version_tostr(this, p, n);
209 }
210 A_INLINE bool operator<(a_version const &ver) const
211 {
212 return a_version_lt(this, &ver);
213 }
214 A_INLINE bool operator>(a_version const &ver) const
215 {
216 return a_version_gt(this, &ver);
217 }
218 A_INLINE bool operator<=(a_version const &ver) const
219 {
220 return a_version_le(this, &ver);
221 }
222 A_INLINE bool operator>=(a_version const &ver) const
223 {
224 return a_version_ge(this, &ver);
225 }
226 A_INLINE bool operator==(a_version const &ver) const
227 {
228 return a_version_eq(this, &ver);
229 }
230 A_INLINE bool operator!=(a_version const &ver) const
231 {
232 return a_version_ne(this, &ver);
233 }
234 A_INLINE int cmp(a_version const &ver) const
235 {
236 return a_version_cmp(this, &ver);
237 }
238#endif /* __cplusplus */
239};
240
243#endif /* a/version.h */
algorithm library
int a_version_check(unsigned int major, unsigned int minor, unsigned int patch)
algorithm library version check
unsigned int a_version_parse(a_version *ctx, char const *ver)
parse version string to version
unsigned int const a_version_major
Definition version.h:68
unsigned int const a_version_minor
Definition version.h:70
bool a_version_eq(a_version const *lhs, a_version const *rhs)
version lhs is equal to version rhs
void a_version_set_alpha(a_version *ctx, char const *alpha)
set alphabet for version
bool a_version_gt(a_version const *lhs, a_version const *rhs)
version lhs is greater than version rhs
int a_version_cmp(a_version const *lhs, a_version const *rhs)
compare the version lhs with the version rhs
bool a_version_ne(a_version const *lhs, a_version const *rhs)
version lhs is not equal to version rhs
void a_version_alpha(a_version const *ctx, char alpha[5])
get alphabet for version
bool a_version_le(a_version const *lhs, a_version const *rhs)
version lhs is less than or equal to version rhs
unsigned int const a_version_patch
Definition version.h:72
uint32_t const a_version_tweak
Definition version.h:74
bool a_version_lt(a_version const *lhs, a_version const *rhs)
version lhs is less than version rhs
unsigned int a_version_tostr(a_version const *ctx, void *pdata, size_t nbyte)
convert version to string
bool a_version_ge(a_version const *lhs, a_version const *rhs)
version lhs is greater than or equal to version rhs
#define a_size
Definition a.h:610
#define a_bool
Definition a.h:302
#define a_u32
Definition a.h:490
instance structure for version
Definition version.h:187
unsigned int extra
extra number
Definition version.h:191
char alpha_[4]
alphabet
Definition version.h:192
unsigned int minor
minor number
Definition version.h:189
unsigned int major
major number
Definition version.h:188
unsigned int third
third number
Definition version.h:190