File: version.h

package info (click to toggle)
libopenmpt 0.4.3-1%2Bdeb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,724 kB
  • sloc: cpp: 99,820; sh: 4,503; ansic: 3,449; makefile: 480
file content (236 lines) | stat: -rw-r--r-- 6,956 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/*
 * version.h
 * ---------
 * Purpose: OpenMPT version handling.
 * Notes  : (currently none)
 * Authors: OpenMPT Devs
 * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
 */


#pragma once

#include "BuildSettings.h"

#include "FlagSet.h"


OPENMPT_NAMESPACE_BEGIN


class Version
{

private:

	uint32 m_Version; // e.g. 0x01170208

public:

	enum class Field
	{
		Major,
		Minor,
		Patch,
		Test,
	};

public:

	static Version Current() noexcept;

public:

	MPT_CONSTEXPR11_FUN Version() noexcept
		: m_Version(0)
	{}

	explicit MPT_CONSTEXPR11_FUN Version(uint32 version) noexcept
		: m_Version(version)
	{}

	explicit MPT_CONSTEXPR11_FUN Version(uint8 v1, uint8 v2, uint8 v3, uint8 v4) noexcept
		: m_Version((static_cast<uint32>(v1) << 24) | (static_cast<uint32>(v2) << 16) | (static_cast<uint32>(v3) << 8) | (static_cast<uint32>(v4) << 0))
	{}

public:

	mpt::ustring ToUString() const; // e.g "1.17.02.08"

	// Returns numerical version value from given version string.
	static Version Parse(const mpt::ustring &s);

public:

	explicit MPT_CONSTEXPR11_FUN operator bool () const noexcept
	{
		return m_Version != 0;
	}
	MPT_CONSTEXPR11_FUN bool operator ! () const noexcept
	{
		return m_Version == 0;
	}

	MPT_CONSTEXPR11_FUN uint32 GetRawVersion() const noexcept
	{
		return m_Version;
	}

	MPT_FORCEINLINE Version Masked(uint32 mask) const noexcept
	{
		return Version(m_Version & mask);
	}

	MPT_CONSTEXPR11_FUN uint8 GetField(Field field) const noexcept
	{
		return
			(field == Field::Major) ? static_cast<uint8>((m_Version >> 24) & 0xffu) :
			(field == Field::Minor) ? static_cast<uint8>((m_Version >> 16) & 0xffu) :
			(field == Field::Patch) ? static_cast<uint8>((m_Version >>  8) & 0xffu) :
			(field == Field::Test ) ? static_cast<uint8>((m_Version >>  0) & 0xffu) :
			0u;
	}

	// Return a version without build number (the last number in the version).
	// The current versioning scheme uses this number only for test builds, and it should be 00 for official builds,
	// So sometimes it might be wanted to do comparisons without the build number.
	Version WithoutTestNumber() const noexcept;

	Version WithoutPatchOrTestNumbers() const noexcept;

public:

	// Return a OpenMPT version string suitable for file format tags 
	mpt::ustring GetOpenMPTVersionString() const; // e.g. "OpenMPT 1.17.02.08"

	// Returns true if a given version number is from a test build, false if it's a release build.
	bool IsTestVersion() const noexcept;

};

MPT_CONSTEXPR11_FUN bool operator == (const Version &a, const Version &b) noexcept
{
	return a.GetRawVersion() == b.GetRawVersion();
}
MPT_CONSTEXPR11_FUN bool operator != (const Version &a, const Version &b) noexcept
{
	return a.GetRawVersion() != b.GetRawVersion();
}
MPT_CONSTEXPR11_FUN bool operator <= (const Version &a, const Version &b) noexcept
{
	return a.GetRawVersion() <= b.GetRawVersion();
}
MPT_CONSTEXPR11_FUN bool operator >= (const Version &a, const Version &b) noexcept
{
	return a.GetRawVersion() >= b.GetRawVersion();
}
MPT_CONSTEXPR11_FUN bool operator < (const Version &a, const Version &b) noexcept
{
	return a.GetRawVersion() < b.GetRawVersion();
}
MPT_CONSTEXPR11_FUN bool operator > (const Version &a, const Version &b) noexcept
{
	return a.GetRawVersion() > b.GetRawVersion();
}


//Creates version number from version parts that appears in version string.
//For example MAKE_VERSION_NUMERIC(1,17,02,28) gives version number of 
//version 1.17.02.28. 
#define MPT_MAKE_VERSION_NUMERIC_HELPER(prefix,v0,v1,v2,v3) Version( prefix ## v0 , prefix ## v1 , prefix ## v2 , prefix ## v3 )
#define MAKE_VERSION_NUMERIC(v0,v1,v2,v3) MPT_MAKE_VERSION_NUMERIC_HELPER(0x, v0, v1, v2, v3)



class SourceInfo
{
private:
	mpt::ustring m_Url; // svn repository url (or empty string)
	int m_Revision; // svn revision (or 0)
	bool m_IsDirty; // svn working copy is dirty (or false)
	bool m_HasMixedRevisions; // svn working copy has mixed revisions (or false)
	bool m_IsPackage; // source code originates from a packaged version of the source code
	mpt::ustring m_Date; // svn date (or empty string)
private:
	SourceInfo();
public:
	static SourceInfo Current();
public:
	const mpt::ustring & Url() const { return m_Url; }
	int Revision() const { return m_Revision; }
	bool IsDirty() const { return m_IsDirty; }
	bool HasMixedRevisions() const { return m_HasMixedRevisions; }
	bool IsPackage() const { return m_IsPackage; }
	const mpt::ustring & Date() const { return m_Date; }
public:
	mpt::ustring GetUrlWithRevision() const; // i.e. "https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@1234" or empty string
	mpt::ustring GetStateString() const; // i.e. "+dirty" or "clean"
};



namespace Build
{

	// Returns true if all conditions for an official release build are met
	bool IsReleasedBuild();

	// Return true if this is a debug build with no optimizations
	bool IsDebugBuild();

	// Return a string decribing the time of the build process (if built from a svn working copy and tsvn was available during build, otherwise it returns the time version.cpp was last rebuild which could be unreliable as it does not get rebuild every time without tsvn)
	mpt::ustring GetBuildDateString();

	// Return a string decribing some of the build features
	mpt::ustring GetBuildFeaturesString(); // e.g. " NO_VST NO_DSOUND"

	// Return a string describing the compiler version used for building.
	mpt::ustring GetBuildCompilerString(); // e.g. "Microsoft Compiler 15.00.20706.01"

	enum Strings
	{
		StringsNone         = 0,
		StringVersion       = 1<<0, // "1.23.35.45"
		StringRevision      = 1<<2, // "-r1234+"
		StringBitness       = 1<<3, // "32 bit"
		StringSourceInfo    = 1<<4, // "https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@1234 (2016-01-02) +dirty"
		StringBuildFlags    = 1<<5, // "TEST DEBUG"
		StringBuildFeatures = 1<<6, // "NO_VST NO_DSOUND"
	};
	MPT_DECLARE_ENUM(Strings)

	// Returns a versions string with the fields selected via @strings.
	mpt::ustring GetVersionString(FlagSet<Build::Strings> strings);

	// Returns a pure version string
	mpt::ustring GetVersionStringPure(); // e.g. "1.17.02.08-r1234+ 32 bit"

	// Returns a simple version string
	mpt::ustring GetVersionStringSimple(); // e.g. "1.17.02.08-r1234+ TEST"

	// Returns Version::CurrentAsString() if the build is a clean release build straight from the repository or an extended string otherwise (if built from a svn working copy and tsvn was available during build)
	mpt::ustring GetVersionStringExtended(); // e.g. "1.17.02.08-r1234+ 32 bit DEBUG"

	enum class Url
	{
		Website,
		Download,
		Forum,
		Bugtracker,
		Updates,
		TopPicks,
	};
	// Returns a URL for the respective key.
	mpt::ustring GetURL(Build::Url key);

	// Returns a multi-line string containing the full credits for the code base
	mpt::ustring GetFullCreditsString();

	// Returns the OpenMPT license text
	mpt::ustring GetLicenseString();

} //namespace Build



OPENMPT_NAMESPACE_END