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 20250101
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#define A_VERSION_4(major, minor, third, extra) {major, minor, third, extra, {'.', 0, 0, 0}}
53/* clang-format on */
54
55#if defined(__cplusplus)
56namespace a
57{
58typedef a_version version;
59} /* namespace a */
60extern "C" {
61#endif /* __cplusplus */
62
64A_EXTERN unsigned int const a_version_major;
66A_EXTERN unsigned int const a_version_minor;
68A_EXTERN unsigned int const a_version_patch;
70A_EXTERN a_u32 const a_version_tweak;
71
82A_EXTERN int a_version_check(unsigned int major, unsigned int minor, unsigned int patch);
83#define A_VERSION_CHECK() a_version_check(A_VERSION_MAJOR, A_VERSION_MINOR, A_VERSION_PATCH)
84
92A_EXTERN unsigned int a_version_tostr(a_version const *ctx, void *pdata, a_size nbyte);
93
100A_EXTERN unsigned int a_version_parse(a_version *ctx, char const *ver);
101
111A_EXTERN int a_version_cmp(a_version const *lhs, a_version const *rhs);
112
119A_EXTERN a_bool a_version_lt(a_version const *lhs, a_version const *rhs);
120
127A_EXTERN a_bool a_version_gt(a_version const *lhs, a_version const *rhs);
128
135A_EXTERN a_bool a_version_le(a_version const *lhs, a_version const *rhs);
136
143A_EXTERN a_bool a_version_ge(a_version const *lhs, a_version const *rhs);
144
151A_EXTERN a_bool a_version_eq(a_version const *lhs, a_version const *rhs);
152
159A_EXTERN a_bool a_version_ne(a_version const *lhs, a_version const *rhs);
160
166A_EXTERN void a_version_set_alpha(a_version *ctx, char const *alpha);
167
173A_EXTERN void a_version_alpha(a_version const *ctx, char alpha[5]);
174
175#if defined(__cplusplus)
176} /* extern "C" */
177#endif /* __cplusplus */
178
183{
184 unsigned int major;
185 unsigned int minor;
186 unsigned int third;
187 unsigned int extra;
188 char alpha_[4];
189#if defined(__cplusplus)
190 A_INLINE void alpha(char str[5]) const
191 {
192 a_version_alpha(this, str);
193 }
194 A_INLINE void set_alpha(char const *str)
195 {
196 a_version_set_alpha(this, str);
197 }
198 A_INLINE unsigned int parse(char const *ver)
199 {
200 return a_version_parse(this, ver);
201 }
202 A_INLINE unsigned int tostr(void *p, a_size n) const
203 {
204 return a_version_tostr(this, p, n);
205 }
206 A_INLINE bool operator<(a_version const &ver) const
207 {
208 return a_version_lt(this, &ver);
209 }
210 A_INLINE bool operator>(a_version const &ver) const
211 {
212 return a_version_gt(this, &ver);
213 }
214 A_INLINE bool operator<=(a_version const &ver) const
215 {
216 return a_version_le(this, &ver);
217 }
218 A_INLINE bool operator>=(a_version const &ver) const
219 {
220 return a_version_ge(this, &ver);
221 }
222 A_INLINE bool operator==(a_version const &ver) const
223 {
224 return a_version_eq(this, &ver);
225 }
226 A_INLINE bool operator!=(a_version const &ver) const
227 {
228 return a_version_ne(this, &ver);
229 }
230 A_INLINE int cmp(a_version const &ver) const
231 {
232 return a_version_cmp(this, &ver);
233 }
234#endif /* __cplusplus */
235};
236
238
239#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:70
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:64
unsigned int const a_version_minor
Definition version.h:66
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:68
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:183
unsigned int extra
Definition version.h:187
char alpha_[4]
Definition version.h:188
unsigned int minor
Definition version.h:185
unsigned int major
Definition version.h:184
unsigned int third
Definition version.h:186