Arbiter
Dependency manager library that supports decentralization
Version.h
Go to the documentation of this file.
1 #ifndef ARBITER_VERSION_H
2 #define ARBITER_VERSION_H
3 
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7 
8 #include <arbiter/Value.h>
9 
10 #include <stdbool.h>
11 #include <stddef.h>
12 
13 /**
14  * Represents a semantic version, as defined by semver.org.
15  */
16 typedef struct ArbiterSemanticVersion ArbiterSemanticVersion;
17 
18 /**
19  * Creates a semantic version with the given components.
20  *
21  * The returned version must be freed with ArbiterFree().
22  */
23 ArbiterSemanticVersion *ArbiterCreateSemanticVersion (unsigned major, unsigned minor, unsigned patch, const char *prereleaseVersion, const char *buildMetadata);
24 
25 /**
26  * Attempts to parse the given NUL-terminated string into a semantic version,
27  * returning NULL if a parse failure occurs.
28  *
29  * The returned version must be freed with ArbiterFree().
30  */
31 ArbiterSemanticVersion *ArbiterCreateSemanticVersionFromString (const char *string);
32 
33 /**
34  * Returns the major version number (X.y.z) from a semantic version.
35  */
36 unsigned ArbiterGetMajorVersion (const ArbiterSemanticVersion *version);
37 
38 /**
39  * Returns the minor version number (x.Y.z) from a semantic version.
40  */
41 unsigned ArbiterGetMinorVersion (const ArbiterSemanticVersion *version);
42 
43 /**
44  * Returns the patch version number (x.y.Z) from a semantic version.
45  */
46 unsigned ArbiterGetPatchVersion (const ArbiterSemanticVersion *version);
47 
48 /**
49  * Returns the prerelease version string from a semantic version, or NULL if
50  * there is not one associated with the version.
51  *
52  * For example, in the version `1.0.0-alpha.1`, the prerelease version string
53  * will be `alpha.1`.
54  *
55  * The returned pointer is only guaranteed to remain valid for the current
56  * scope.
57  */
58 const char *ArbiterGetPrereleaseVersion (const ArbiterSemanticVersion *version);
59 
60 /**
61  * Returns the build metadata string from a semantic version, or NULL if there
62  * is not one associated with the version.
63  *
64  * For example, in the version `1.0.0+20160814`, the build metadata string will
65  * be `20160814`.
66  *
67  * The returned pointer is only guaranteed to remain valid for the current
68  * scope.
69  */
70 const char *ArbiterGetBuildMetadata (const ArbiterSemanticVersion *version);
71 
72 /**
73  * Orders two semantic versions relative to each other.
74  *
75  * Returns -1 if `lhs` is less than `rhs`, 1 if `lhs` is greater than `rhs`, or
76  * 0 if the two versions have the same precedence (which may be the case even if
77  * their build metadata differs).
78  */
79 int ArbiterCompareVersionOrdering (const ArbiterSemanticVersion *lhs, const ArbiterSemanticVersion *rhs);
80 
81 /**
82  * Represents a "selected" version, which is a concrete choice of a real project
83  * version.
84  */
85 typedef struct ArbiterSelectedVersion ArbiterSelectedVersion;
86 
87 /**
88  * Creates a selected version which corresponds to the given semantic version.
89  *
90  * `semanticVersion` may be NULL to represent a selected version that has
91  * metadata but no semantic version component; for example, to use with
92  * ArbiterCreateRequirementUnversioned().
93  *
94  * The returned version must be freed with ArbiterFree().
95  */
96 ArbiterSelectedVersion *ArbiterCreateSelectedVersion (const ArbiterSemanticVersion *semanticVersion, ArbiterUserValue metadata);
97 
98 /**
99  * Returns the semantic version which corresponds to the given selected version,
100  * or NULL if there is no semantic version component.
101  *
102  * The returned pointer is only guaranteed to remain valid for the current
103  * scope.
104  */
105 const ArbiterSemanticVersion *ArbiterSelectedVersionSemanticVersion (const ArbiterSelectedVersion *version);
106 
107 /**
108  * Returns any metadata pointer which was provided to
109  * ArbiterCreateSelectedVersion().
110  *
111  * The returned pointer is only guaranteed to remain valid for the current
112  * scope.
113  */
114 const void *ArbiterSelectedVersionMetadata (const ArbiterSelectedVersion *version);
115 
116 /**
117  * Represents a list of selected versions.
118  */
119 typedef struct ArbiterSelectedVersionList ArbiterSelectedVersionList;
120 
121 /**
122  * Creates a version list which wraps a C array of ArbiterSelectedVersion objects.
123  *
124  * The objects in the C array can be safely freed after calling this function.
125  *
126  * The returned list must be freed with ArbiterFree().
127  */
128 ArbiterSelectedVersionList *ArbiterCreateSelectedVersionList (const ArbiterSelectedVersion * const *versions, size_t count);
129 
130 #ifdef __cplusplus
131 }
132 #endif
133 
134 #endif
const char * ArbiterGetBuildMetadata(const ArbiterSemanticVersion *version)
Returns the build metadata string from a semantic version, or NULL if there is not one associated wit...
const void * ArbiterSelectedVersionMetadata(const ArbiterSelectedVersion *version)
Returns any metadata pointer which was provided to ArbiterCreateSelectedVersion().
unsigned ArbiterGetMinorVersion(const ArbiterSemanticVersion *version)
Returns the minor version number (x.Y.z) from a semantic version.
const ArbiterSemanticVersion * ArbiterSelectedVersionSemanticVersion(const ArbiterSelectedVersion *version)
Returns the semantic version which corresponds to the given selected version, or NULL if there is no ...
unsigned ArbiterGetPatchVersion(const ArbiterSemanticVersion *version)
Returns the patch version number (x.y.Z) from a semantic version.
int ArbiterCompareVersionOrdering(const ArbiterSemanticVersion *lhs, const ArbiterSemanticVersion *rhs)
Orders two semantic versions relative to each other.
bool operator>=(const ArbiterSemanticVersion &other) const noexcept
Definition: Version.h:52
unsigned ArbiterGetMajorVersion(const ArbiterSemanticVersion *version)
Returns the major version number (X.y.z) from a semantic version.
ArbiterSelectedVersion * ArbiterCreateSelectedVersion(const ArbiterSemanticVersion *semanticVersion, ArbiterUserValue metadata)
Creates a selected version which corresponds to the given semantic version.
ArbiterSemanticVersion * ArbiterCreateSemanticVersionFromString(const char *string)
Attempts to parse the given NUL-terminated string into a semantic version, returning NULL if a parse ...
ArbiterSemanticVersion * ArbiterCreateSemanticVersion(unsigned major, unsigned minor, unsigned patch, const char *prereleaseVersion, const char *buildMetadata)
Creates a semantic version with the given components.
const char * ArbiterGetPrereleaseVersion(const ArbiterSemanticVersion *version)
Returns the prerelease version string from a semantic version, or NULL if there is not one associated...
ArbiterSelectedVersionList * ArbiterCreateSelectedVersionList(const ArbiterSelectedVersion *const *versions, size_t count)
Creates a version list which wraps a C array of ArbiterSelectedVersion objects.