1 | // tVersion.cpp  |
2 | //  |
3 | // Version string parser to extract major, minor, and rev fro the header.  |
4 | //  |
5 | // Copyright (c) 2020 Tristan Grimmer.  |
6 | // Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby  |
7 | // granted, provided that the above copyright notice and this permission notice appear in all copies.  |
8 | //  |
9 | // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL  |
10 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,  |
11 | // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN  |
12 | // AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR  |
13 | // PERFORMANCE OF THIS SOFTWARE.  |
14 |   |
15 | #include <Foundation/tVersion.cmake.h>  |
16 | #include <Foundation/tString.h>  |
17 |   |
18 |   |
19 | namespace tVersion  |
20 | {  |
21 | // Any break in binary compatibility must increment the major number, although non-breaking major improvements may  |
22 | // also justify a major version update.  |
23 | int Major = 0;  |
24 |   |
25 | // Minor version increments on non-breaking fixes and improvements to the current major version. When the major  |
26 | // version increments, the minor version resets to 0.  |
27 | int Minor = 0;  |
28 |   |
29 | // The revision number is for minor bug fixes and the like. It Resets to 0 when the minor version increments.  |
30 | int Revision = 0;  |
31 | bool Parsed = false;  |
32 | }  |
33 |   |
34 |   |
35 | tVersion::Parser::Parser(const char* verStr)  |
36 | {  |
37 | if (Parsed)  |
38 | return;  |
39 |   |
40 | tList<tStringItem> components;  |
41 | tStd::tExplode(components, tString(verStr), '.');  |
42 |   |
43 | tStringItem* comp = components.First(); Major = comp->GetAsInt(10);  |
44 | comp = comp->Next(); Minor = comp->GetAsInt(10);  |
45 | comp = comp->Next(); Revision = comp->GetAsInt(10);  |
46 | Parsed = true;  |
47 | }  |
48 | |