1 /*
2 	OpenLieroX
3 
4 	version parsing
5 
6 	file created 29-02-2008 by albert
7 	code under LGPL
8 */
9 
10 #ifndef __VERSION_H__
11 #define __VERSION_H__
12 
13 #include <string>
14 #include "StringUtils.h" // for itoa
15 
16 struct Version;
17 extern const char* const fullGameName;
GetFullGameName()18 inline const char* GetFullGameName() { return fullGameName; }
19 const char* GetGameName();
20 const Version& GetGameVersion();
21 
22 
23 struct Version {
VersionVersion24 	Version() { reset(); }
VersionVersion25 	Version(const std::string& versionStr) { setByString(versionStr); }
26 
resetVersion27 	void reset() { gamename = "LieroX"; num = 0; subnum = 56; subsubnum = 0; revnum = 0; releasetype = RT_NORMAL; }
28 	void setByString(const std::string& versionStr);
29 	std::string asString() const;
30 	std::string asHumanString() const;
31 	std::string releaseType() const;
32 
33 	bool isBanned() const;
34 
35 	int num; // 0
36 	int subnum; // 57
37 	int subsubnum; // 3 (Beta-version)
38 	int revnum; // 1007 (SVN)
39 	enum Releasetype {
40 		// HINT: keep in this order to allow direct comparsion here
41 		RT_UNKNOWN, RT_ALPHA, RT_BETA, RT_RC, RT_NORMAL
42 	} releasetype;
43 	std::string gamename; // OpenLieroX
44 
45 };
46 
47 
48 // The following functions are declared inline because they are used very often.
49 
50 // For comparision, we ignore the following: revnum, gamename
51 // That means, a special revision of a baseversion should not change the behaviour (and it's only for debugging).
52 // And another game like Hirudo should keep the same version-counting. We can start Hirudo at version 1.0 or 0.99.
53 
54 inline bool operator<(const Version& ver1, const Version& ver2) {
55 	if(ver1.num != ver2.num) return ver1.num < ver2.num;
56 	if(ver1.subnum != ver2.subnum) return ver1.subnum < ver2.subnum;
57 	if(ver1.releasetype != ver2.releasetype) return ver1.releasetype < ver2.releasetype;
58 	if(ver1.subsubnum != ver2.subsubnum) return ver1.subsubnum < ver2.subsubnum;
59 	return false;
60 }
61 
62 inline bool operator==(const Version& ver1, const Version& ver2) {
63 	return
64 	ver1.num == ver2.num &&
65 	ver1.subnum == ver2.subnum &&
66 	ver1.releasetype == ver2.releasetype &&
67 	ver1.subsubnum == ver2.subsubnum;
68 }
69 
70 inline bool operator>(const Version& ver1, const Version& ver2) { return ver2 < ver1; }
71 inline bool operator<=(const Version& ver1, const Version& ver2) { return ver1 < ver2 || ver1 == ver2; }
72 inline bool operator>=(const Version& ver1, const Version& ver2) { return ver2 < ver1 || ver1 == ver2; }
73 inline bool operator!=(const Version& ver1, const Version& ver2) { return ! (ver1 == ver2); }
74 
OLXBetaVersion(int betaversion)75 inline Version OLXBetaVersion(int betaversion) {
76 	Version v;
77 	v.gamename = fullGameName;
78 	v.num = 0;
79 	v.subnum = 57;
80 	v.subsubnum = betaversion;
81 	v.releasetype = Version::RT_BETA;
82 	return v;
83 }
84 
OLXBetaVersion(int num,int subnum,int betaversion)85 inline Version OLXBetaVersion(int num, int subnum, int betaversion) {
86 	Version v;
87 	v.gamename = fullGameName;
88 	v.num = num;
89 	v.subnum = subnum;
90 	v.subsubnum = betaversion;
91 	v.releasetype = Version::RT_BETA;
92 	return v;
93 }
94 
OLXRcVersion(int num,int subnum,int rcversion)95 inline Version OLXRcVersion(int num, int subnum, int rcversion) {
96 	Version v;
97 	v.gamename = fullGameName;
98 	v.num = num;
99 	v.subnum = subnum;
100 	v.subsubnum = rcversion;
101 	v.releasetype = Version::RT_RC;
102 	return v;
103 }
104 
105 inline Version OLXVersion(int num, int subnum, int subsubnum = 0) {
106 	Version v;
107 	v.gamename = fullGameName;
108 	v.num = num;
109 	v.subnum = subnum;
110 	v.subsubnum = subsubnum;
111 	v.releasetype = Version::RT_NORMAL;
112 	return v;
113 }
114 
115 #endif
116