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
5
6#ifndef LIBA_VERSION_H
7#define LIBA_VERSION_H
8
9#include "a.h"
10
16
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 20250131
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
46/* clang-format off */
47#define A_VERSION_4(major, minor, third, extra) {major, minor, third, extra, {'.', 0, 0, 0}}
48/* clang-format on */
49#define A_VERSION_3(major, minor, third) A_VERSION_4(major, minor, third, 0)
50#define A_VERSION_2(major, minor) A_VERSION_3(major, minor, 0)
51#define A_VERSION_1(major) A_VERSION_2(major, 0)
52#define A_VERSION_0() A_VERSION_1(0)
53
54typedef struct a_version a_version;
55
56#if defined(__cplusplus)
57namespace a
58{
59typedef a_version version;
60} /* namespace a */
61extern "C" {
62#endif /* __cplusplus */
63
65A_EXTERN unsigned int const a_version_major;
67A_EXTERN unsigned int const a_version_minor;
69A_EXTERN unsigned int const a_version_patch;
71A_EXTERN a_u32 const a_version_tweak;
72
83A_EXTERN int a_version_check(unsigned int major, unsigned int minor, unsigned int patch);
84#define A_VERSION_CHECK() a_version_check(A_VERSION_MAJOR, A_VERSION_MINOR, A_VERSION_PATCH)
85
93A_EXTERN unsigned int a_version_tostr(a_version const *ctx, void *pdata, a_size nbyte);
94
101A_EXTERN unsigned int a_version_parse(a_version *ctx, char const *ver);
102
112A_EXTERN int a_version_cmp(a_version const *lhs, a_version const *rhs);
113
120A_EXTERN a_bool a_version_lt(a_version const *lhs, a_version const *rhs);
121
128A_EXTERN a_bool a_version_gt(a_version const *lhs, a_version const *rhs);
129
136A_EXTERN a_bool a_version_le(a_version const *lhs, a_version const *rhs);
137
144A_EXTERN a_bool a_version_ge(a_version const *lhs, a_version const *rhs);
145
152A_EXTERN a_bool a_version_eq(a_version const *lhs, a_version const *rhs);
153
160A_EXTERN a_bool a_version_ne(a_version const *lhs, a_version const *rhs);
161
167A_EXTERN void a_version_set_alpha(a_version *ctx, char const *alpha);
168
174A_EXTERN void a_version_alpha(a_version const *ctx, char alpha[5]);
175
176#if defined(__cplusplus)
177} /* extern "C" */
178#endif /* __cplusplus */
179
184{
185 unsigned int major;
186 unsigned int minor;
187 unsigned int third;
188 unsigned int extra;
189 char alpha_[4];
190#if defined(__cplusplus)
191 A_INLINE void alpha(char str[5]) const
192 {
193 a_version_alpha(this, str);
194 }
195 A_INLINE void set_alpha(char const *str)
196 {
197 a_version_set_alpha(this, str);
198 }
199 A_INLINE unsigned int parse(char const *ver)
200 {
201 return a_version_parse(this, ver);
202 }
203 A_INLINE unsigned int tostr(void *p, a_size n) const
204 {
205 return a_version_tostr(this, p, n);
206 }
207 A_INLINE bool operator<(a_version const &ver) const
208 {
209 return a_version_lt(this, &ver);
210 }
211 A_INLINE bool operator>(a_version const &ver) const
212 {
213 return a_version_gt(this, &ver);
214 }
215 A_INLINE bool operator<=(a_version const &ver) const
216 {
217 return a_version_le(this, &ver);
218 }
219 A_INLINE bool operator>=(a_version const &ver) const
220 {
221 return a_version_ge(this, &ver);
222 }
223 A_INLINE bool operator==(a_version const &ver) const
224 {
225 return a_version_eq(this, &ver);
226 }
227 A_INLINE bool operator!=(a_version const &ver) const
228 {
229 return a_version_ne(this, &ver);
230 }
231 A_INLINE int cmp(a_version const &ver) const
232 {
233 return a_version_cmp(this, &ver);
234 }
235#endif /* __cplusplus */
236};
237
239
240#endif /* a/version.h */
algorithm library
int a_version_check(unsigned int major, unsigned int minor, unsigned int patch)
algorithm library version check
a_u32 const a_version_tweak
Definition version.h:71
unsigned int a_version_parse(a_version *ctx, char const *ver)
parse version string to version
unsigned int a_version_tostr(a_version const *ctx, void *pdata, a_size nbyte)
convert version to string
unsigned int const a_version_major
Definition version.h:65
unsigned int const a_version_minor
Definition version.h:67
a_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
int a_version_cmp(a_version const *lhs, a_version const *rhs)
compare the version lhs with the version rhs
a_bool a_version_ge(a_version const *lhs, a_version const *rhs)
version lhs is greater than or equal to version rhs
a_bool a_version_gt(a_version const *lhs, a_version const *rhs)
version lhs is greater than version rhs
void a_version_alpha(a_version const *ctx, char alpha[5])
get alphabet for version
a_bool a_version_ne(a_version const *lhs, a_version const *rhs)
version lhs is not equal to version rhs
a_bool a_version_lt(a_version const *lhs, a_version const *rhs)
version lhs is less than version rhs
unsigned int const a_version_patch
Definition version.h:69
a_bool a_version_le(a_version const *lhs, a_version const *rhs)
version lhs is less than or equal to version rhs
bool a_bool
type, capable of holding one of the two values: 1 and 0
Definition a.h:320
unsigned long a_u32
unsigned integer type with width of exactly 32 bits
Definition a.h:538
size_t a_size
unsigned integer type returned by the sizeof operator
Definition a.h:823
instance structure for version
Definition version.h:184
unsigned int extra
Definition version.h:188
char alpha_[4]
Definition version.h:189
unsigned int minor
Definition version.h:186
unsigned int major
Definition version.h:185
unsigned int third
Definition version.h:187