💾 Archived View for gmi.noulin.net › gitRepositories › version › file › version.h.gmi captured on 2024-07-09 at 03:05:07. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2023-01-29)
-=-=-=-=-=-=-
version.h (6974B)
1 #pragma once 2 3 /* Libsheepy documentation: http://spartatek.se/libsheepy/ */ 4 5 #define validO(obj, versionString) (obj)->f->valid(obj, versionString) 6 // parseO reused from libsheepyObject.h 7 #define parseStrictO(obj, versionString) (obj)->f->parseStrict(obj, versionString) 8 #define eqO equalO 9 #define eqSO(obj, version) (obj)->f->equalS(obj, version) 10 #define eqSSO(obj, v1, v2) (obj)->f->equalSS(obj, v1, v2) 11 #define cmpO(obj, versionObj) (obj)->f->cmp(obj, versionObj) 12 #define cmpSO(obj, version) (obj)->f->cmpS(obj, version) 13 #define cmpSSO(obj, v1, v2) (obj)->f->cmpSS(obj, v1, v2) 14 #define incrO(obj, level) (obj)->f->incr(obj, level) 15 #define vsortO(obj, varray) (obj)->f->sort(obj, varray) 16 #define satisfiesO(obj, vrange) (obj)->f->satisfies(obj, vrange) 17 #define toJsonO(obj) (obj)->f->toJson(obj) 18 #define toJsonStrO(obj) (obj)->f->toJsonStr(obj) 19 #define fromJsonO(obj, json) (obj)->f->fromJson(obj, json) 20 #define fromJsonStrO(obj, json) (obj)->f->fromJsonStr(obj, json) 21 22 // inc level parameter 23 enum {releaseVer, majorVer, minorVer, patchVer}; 24 25 /* Class version */ 26 typ struct version versiont; 27 28 /* for object inheriting version, cast to version to be able to use this class functions and generics*/ 29 #define cVersion(self) ( (versiont*) self ) 30 31 typ void (*freeVersionFt) (versiont *self); 32 typ void (*terminateVersionFt) (versiont **self); 33 typ char* (*toStringVersionFt) (versiont *self); 34 typ versiont* (*duplicateVersionFt) (versiont *self); 35 typ void (*smashVersionFt) (versiont **self); 36 37 /** 38 * free version 39 */ 40 typ void (*finishVersionFt) (versiont **self); 41 42 typ const char* (*helpVersionFt) (versiont *self); 43 44 /** 45 * log version string 46 */ 47 typ void (*logVersionFt) (versiont *self); 48 49 /** 50 * valid returns true when v is an incomplete version that can be made into a strictly valid version 51 */ 52 typ bool (*validVersionFt) (versiont *self, const char *v); 53 54 /** 55 * parse the version string and store result in self 56 * Versions are in the format: 57 * Release.Major.minor.patch.others-prerelease+build 58 */ 59 typ bool (*parseVersionFt) (versiont *self, const char *v); 60 /** 61 * true if v version string is strictly valid. 62 * - v starts with release number 63 * - all version numbers are correctly separated 64 * - v doesn't end with a separator 65 */ 66 typ bool (*parseStrictVersionFt)(versiont *self, const char *v); 67 /** 68 * keep only characters in 69 * .-+0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ* 70 * Other characters are stripped 71 */ 72 typ bool (*cleanVersionFt) (versiont *self, char *v); 73 /** 74 * true when ver is equal to self 75 */ 76 typ bool (*equalVersionFt) (versiont *self, versiont *ver); 77 /** 78 * true when v version string is equal to self 79 */ 80 typ bool (*equalSVersionFt) (versiont *self, const char *v); 81 /** 82 * true when v1 and v2 version strings are equal 83 */ 84 typ bool (*equalSSVersionFt) (versiont *self, const char *v1, const char *v2); 85 /** 86 * compare versions 87 * \return 88 * -1 when self < ver 89 * 0 when self == ver 90 * 1 when self > ver 91 */ 92 typ int (*cmpVersionFt) (versiont *self, versiont *ver); 93 /** 94 * compare versions 95 * \return 96 * -1 when self < v 97 * 0 when self == v 98 * 1 when self > v 99 */ 100 typ int (*cmpSVersionFt) (versiont *self, const char *v); 101 /** 102 * compare versions 103 * \return 104 * -1 when v1 < v2 105 * 0 when v1 == v2 106 * 1 when v1 > v2 107 */ 108 typ int (*cmpSSVersionFt) (versiont *self, const char *v1, const char *v2); 109 /** 110 * increase one of the main component 111 * level values are defined in the enum above: releaseVer, majorVer, minorVer, patchVer 112 * Example: 113 * incrO(v, patchVer); 114 */ 115 typ bool (*incrVersionFt) (versiont *self, u32 level); 116 /** 117 * sort an array of version strings 118 * \return 119 * sorted version strings 120 */ 121 typ smallArrayt* (*sortVersionFt) (versiont *self, smallArrayt *vlist); 122 /** 123 * true when self in the range defined by vrange 124 * vrange format is defined in the readme 125 */ 126 typ bool (*satisfiesVersionFt) (versiont *self, const char *vrange); 127 /** 128 * return a json object representing self 129 */ 130 typ smallJsont* (*toJsonVersionFt) (versiont *self); 131 /** 132 * return a json string representing self 133 */ 134 typ char* (*toJsonStrVersionFt) (versiont *self); 135 /** 136 * set version from json object 137 */ 138 typ bool (*fromJsonVersionFt) (versiont *self, smallJsont *json); 139 /** 140 * set version from json string 141 */ 142 typ bool (*fromJsonStrVersionFt)(versiont *self, const char *json); 143 144 /** 145 * class functions 146 * allocated once for all objects 147 * 148 * freed with finalizeVersion 149 */ 150 151 /** 152 * use this define in child classes and add the new function after this class functions 153 * 154 * in this define, add the methods after <finishVersionFt finish;> 155 * 156 * Example: 157 * #define RINGFUNCTIONST \n * VERSIONFUNCTIONST; \n * setSizeRingFt setSize 158 */ 159 #define VERSIONFUNCTIONST \ 160 helpVersionFt help;\ 161 logVersionFt log;\ 162 validVersionFt valid;\ 163 parseVersionFt parse;\ 164 parseStrictVersionFt parseStrict;\ 165 cleanVersionFt clean;\ 166 equalVersionFt equal;\ 167 equalSVersionFt equalS;\ 168 equalSSVersionFt equalSS;\ 169 cmpVersionFt cmp;\ 170 cmpSVersionFt cmpS;\ 171 cmpSSVersionFt cmpSS;\ 172 incrVersionFt incr;\ 173 sortVersionFt sort;\ 174 satisfiesVersionFt satisfies;\ 175 toJsonVersionFt toJson;\ 176 toJsonStrVersionFt toJsonStr;\ 177 fromJsonVersionFt fromJson;\ 178 fromJsonStrVersionFt fromJsonStr 179 180 typ struct { 181 freeVersionFt free; 182 terminateVersionFt terminate; 183 toStringVersionFt toString; 184 duplicateVersionFt duplicate; 185 smashVersionFt smash; 186 finishVersionFt finish; 187 VERSIONFUNCTIONST; 188 } versionFunctionst; 189 190 /** 191 * class 192 */ 193 struct version { 194 const char *type; 195 versionFunctionst *f; 196 197 char *originalVer; 198 199 bool empty; 200 /** main components are release.major.minor.patch. The parser sets the component count found in the given string */ 201 u8 mainComponentCount; 202 u64 release; 203 u64 major; 204 u64 minor; 205 u64 patch; 206 smallArrayt others; 207 smallArrayt prerelease; 208 smallArrayt build; 209 }; 210 211 /* version */ 212 213 #define createVersion(obj) ;versiont obj; initiateVersion(&obj) 214 #define createAllocateVersion(obj) ;versiont *obj; initiateAllocateVersion(&obj) 215 216 void initiateVersion(versiont *self); 217 void initiateAllocateVersion(versiont **self); 218 void finalizeVersion(void); 219 220 /* initialize class methods, call registerMethodsVersion from classes inheriting this class */ 221 void registerMethodsVersion(versionFunctionst *f); 222 223 versiont* allocVersion(const char *v); 224 225 /* end class version*/ 226 // vim: set expandtab ts=2 sw=2: 227 228 #define isVersionCompiledWithCurrentLisheepyVersion checkLibsheepyVersionVersion(LIBSHEEPY_VERSION) 229 bool checkLibsheepyVersionVersion(const char *currentLibsheepyVersion);