Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Version.h
Go to the documentation of this file.
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Foundation_Common_Version_h_
5#define _Stroika_Foundation_Common_Version_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9#include <compare>
10#include <cstdint>
11
14
15/**
16 * \file
17 *
18 * \note Code-Status: <a href="Code-Status.md#Beta">Beta</a>
19 *
20 * TODO:
21 * @todo Better document/enforce limits on range of values for version#. Note - we have some extra bits because
22 * verStage only requires 3 (so 8+8+3+8_1 used, leaving 4).
23 *
24 * @todo RETHINK MAPPING TO FULL_VERSION_NUMBER type? VersionStage only needs 3 bits (??)
25 * But maybe useful compat with windows format?
26 *
27 * @todo Consider if explicit Version(Binary32BitFullVersionType) CTOR should be FromBinary32BitFullVersionType
28 */
29
31
32 /**
33 */
34 enum class VersionStage {
36 Alpha = kStroika_Version_Stage_Alpha,
37 Beta = kStroika_Version_Stage_Beta,
38 ReleaseCandidate = kStroika_Version_Stage_ReleaseCandidate,
39 Release = kStroika_Version_Stage_Release,
40
41 Stroika_Define_Enum_Bounds (Dev, Release)
42 };
43
44 /**
45 * In Stroika, we represent a version# as (higher sort order priority first):
46 * MAJOR (uint8_t)
47 * MINOR (uint8_t)
48 * VersionStage
49 * VERSION-SubStage (uint8_t)
50 * finalBuild(bool)
51 *
52 * We provide support to automatically map this notion to a 32-bit version# which Microsoft uses.
53 * Note - this mapping is not totally 1-1, and doesn't correspond to any documented version# strategy defined
54 * by MSFT (as near as I can tell they have none - its just 4 bytes for them).
55 *
56 * @see Stroika_Make_FULL_VERSION for the mapping
57 *
58 * \note <a href="Design-Overview.md#Comparisons">Comparisons</a>:
59 * o static_assert (totally_ordered<Version>);
60 */
61 struct Version {
62 public:
63 static constexpr uint16_t kMaxVersionSubStage = (1 << 12) - 1;
64
65 public:
66 /**
67 * \pre verSubStage <= kMaxVersionSubStage
68 */
69 constexpr Version ();
70 constexpr explicit Version (Binary32BitFullVersionType fullVersionNumber);
71 constexpr Version (uint8_t majorVer, uint8_t minorVer, VersionStage verStage, uint16_t verSubStage, bool finalBuild = true);
72
73 public:
74 /**
75 * FromWin32Version4DoTString may throw if it detects an ill-formatted version string.
76 */
77 static Version FromWin32Version4DotString (const Characters::String& win32Version4DotString);
78
79 public:
80 /**
81 * FromPrettyVersionString may throw if it detects an ill-formatted version string.
82 */
83 static Version FromPrettyVersionString (const Characters::String& prettyVersionString);
84
85 public:
86 uint8_t fMajorVer; // 8 bits
87 uint8_t fMinorVer; // 8 bits
88 VersionStage fVerStage; // 3 bits
89 uint16_t fVerSubStage; // 12 bits
90 bool fFinalBuild; // 1 bit
91
92 public:
93 /**
94 */
95 nonvirtual constexpr Binary32BitFullVersionType AsFullVersionNum () const;
96
97 public:
98 /**
99 */
100 nonvirtual Characters::String AsWin32Version4DotString () const;
101
102 public:
103 /**
104 */
105 nonvirtual Characters::String AsPrettyVersionString () const;
106
107 public:
108 /**
109 * Returns "1.0" for example.
110 */
111 nonvirtual Characters::String AsMajorMinorString () const;
112
113 public:
114 /**
115 * @see Characters::ToString ();
116 */
117 nonvirtual Characters::String ToString () const;
118
119 public:
120 /**
121 */
122 constexpr bool operator== (const Version& rhs) const;
123
124 public:
125 /**
126 */
127 constexpr strong_ordering operator<=> (const Version& rhs) const;
128 };
129 static_assert (totally_ordered<Version>);
130
131}
132
133/*
134 ********************************************************************************
135 ***************************** Implementation Details ***************************
136 ********************************************************************************
137 */
138#include "Version.inl"
139
140#endif /*_Stroika_Foundation_Common_Version_h_*/
#define Stroika_Define_Enum_Bounds(FIRST_ITEM, LAST_ITEM)
#define kStroika_Version_Stage_Dev
Definition VersionDefs.h:68
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition String.h:201
static Version FromPrettyVersionString(const Characters::String &prettyVersionString)
Definition Version.cpp:52
nonvirtual Characters::String ToString() const
Definition Version.inl:43
nonvirtual Characters::String AsMajorMinorString() const
Definition Version.cpp:171
static Version FromWin32Version4DotString(const Characters::String &win32Version4DotString)
Definition Version.cpp:23