libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gimbal_version.h
Go to the documentation of this file.
1/*! \file
2 * \brief GblVersion type, utlities and query functions
3 * \ingroup utils
4 *
5 * This file contains the GblVersion typedef and its associated API.
6 * A GblVersion is a 32-bit unsigned integer, encoded as:
7 *
8 * |Bits |24-31|9-23 |0-8 |
9 * |--------|-----|-----|-----|
10 * |\b Field|Major|Minor|Patch|
11 *
12 * \note
13 * Since it's just an unsigned integer, two versions can directly
14 * be compared to one-another for version checks.
15 *
16 * \todo
17 * - implement fuzzy comparison: GblVersion_compare(version, ">=3.23.0")
18 * - registered GblType?
19 *
20 * \author 2023 Falco Girgis
21 * \copyright MIT License
22 */
23#ifndef GIMBAL_VERSION_H
24#define GIMBAL_VERSION_H
25
26#include "../core/gimbal_result.h"
27
28/*! \name Bitfields
29 * \brief Bitfield positions and masks
30 * @{
31 */
32#define GBL_VERSION_MAJOR_BITPOS 24u //!< Bit position of the MAJOR field
33#define GBL_VERSION_MAJOR_MASK 0xff //!< Bit mask of the MAJOR field
34
35#define GBL_VERSION_MINOR_BITPOS 8u //!< Bit position of the MINOR field
36#define GBL_VERSION_MINOR_MASK 0xffff //!< Bit mask of the MINOR field
37
38#define GBL_VERSION_PATCH_BITPOS 0u //!< Bit position of the PATCH field
39#define GBL_VERSION_PATCH_MASK 0xff //!< Bit mask of the PATCH field
40//! @}
41
42//!Size required for a string buffer to hold a version, used with GblVersion_string()
43 #define GBL_VERSION_STRING_SIZE (2 * 3 + 5 + 2 + 1)
44
45/*! \name Compile-Time Versioning
46 * \brief Macros for compile-time encoding
47 * @{
48 */
49//! Encodes a GblVersion from its constituents
50#define GBL_VERSION_MAKE(major, minor, patch) GBL_VERSION_MAKE_(major, minor, patch)
51//! Creates a compile-time stringified version from its constituents
52#define GBL_VERSION_STRING(major, minor, patch) GBL_VERSION_STRING_(major, minor, patch)
53//! @}
54
55#define GBL_SELF_TYPE GblVersion
56
58
59/*! 32-bit unsigned integer representing a packed version in the form (MAJOR.MINOR.PATCH)
60 * \ingroup utils
61 */
62typedef uint32_t GblVersion;
63
64/*! \name Creation
65 * \brief Methods for creating and encoding
66 * @{
67 */
68//! Creates and returns a GblVersion from its packed constituent values
70 uint16_t minor,
71 uint8_t patch) GBL_NOEXCEPT;
72//! Parses and returns a GblVersion from an encoded version string in the format "MAJOR.MINOR.PATCH"
74//! @}
75
76//! Stringifies a GblVersion, storing it within \p pBuffer and returning \p pBuffer
78
79/*! \name Field Extraction
80 * \brief Methods for getting field values
81 * @{
82 */
83//! Extracts the 8-bit MAJOR version number field
85//! Extracts the 16-bit MINOR version number field
87//! Extracts the 8-bit PATCH version number field
89//! @}
90
91/*! \name Field Encoding
92 * \brief Methods for setting field values
93 * @{
94 */
95//! Sets the 8-bit MAJOR version number field to \p major
97//! Sets the 16-bit MINOR version number field to \p minor
99//! Sets the 8-bit PATCH version number field to \p patch
101//! @}
102
104
105//! \cond
106#define GBL_VERSION_MAKE_(major, minor, patch)
107 ((uint32_t)((major & (uint8_t)GBL_VERSION_MAJOR_MASK)
109 (uint32_t)((minor & (uint16_t)GBL_VERSION_MINOR_MASK)
111 (uint32_t)((patch & (uint8_t)GBL_VERSION_PATCH_MASK)
113
114#define GBL_VERSION_STRING_(major, minor, patch)
115 GBL_STRINGIFY(major) "."
116 GBL_STRINGIFY(minor) "."
117 GBL_STRINGIFY(patch)
118//! \endcond
119
120#undef GBL_SELF_TYPE
121
122#endif // GIMBAL_VERSION_H
#define GBL_NOEXCEPT
#define GBL_DECLS_BEGIN
#define GBL_EXPORT
#define GBL_VSELF
#define GBL_STRINGIFY(a)
void GblVersion_setPatch(GblVersion *pSelf, uint8_t patch)
Sets the 8-bit PATCH version number field to patch.
#define GBL_VERSION_MINOR_BITPOS
Bit position of the MINOR field.
void GblVersion_setMinor(GblVersion *pSelf, uint16_t minor)
Sets the 16-bit MINOR version number field to minor.
uint16_t GblVersion_minor(GblVersion self)
Extracts the 16-bit MINOR version number field.
#define GBL_VERSION_MINOR_MASK
Bit mask of the MINOR field.
GblVersion GblVersion_parse(const char *pString)
Parses and returns a GblVersion from an encoded version string in the format "MAJOR....
#define GBL_VERSION_PATCH_MASK
Bit mask of the PATCH field.
char * GblVersion_string(GblVersion self, char *pBuffer)
Stringifies a GblVersion, storing it within pBuffer and returning pBuffer.
#define GBL_VERSION_MAJOR_BITPOS
Bit position of the MAJOR field.
#define GBL_VERSION_MAJOR_MASK
Bit mask of the MAJOR field.
uint8_t GblVersion_patch(GblVersion self)
Extracts the 8-bit PATCH version number field.
GblVersion GblVersion_make(uint8_t major, uint16_t minor, uint8_t patch)
Creates and returns a GblVersion from its packed constituent values.
#define GBL_VERSION_PATCH_BITPOS
Bit position of the PATCH field.
void GblVersion_setMajor(GblVersion *pSelf, uint8_t major)
Sets the 8-bit MAJOR version number field to major.
uint8_t GblVersion_major(GblVersion self)
Extracts the 8-bit MAJOR version number field.
uint32_t GblVersion
32-bit unsigned integer representing a packed version in the form (MAJOR.MINOR.PATCH)