OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4GameVersion.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
5  * Copyright (c) 2010-2016, The OpenClonk Team and contributors
6  *
7  * Distributed under the terms of the ISC license; see accompanying file
8  * "COPYING" for details.
9  *
10  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
11  * See accompanying file "TRADEMARK" for details.
12  *
13  * To redistribute this file separately, substitute the full license texts
14  * for the above references.
15  */
16 #ifndef C4GAMEVERSION_H
17 
18 #define C4GAMEVERSION_H
19 
20 #include "C4Version.h"
21 #include "lib/C4InputValidation.h"
22 
24 {
25  ValidatedStdCopyStrBuf<C4InVal::VAL_NameAllowEmpty> sEngineName; // status only - not used for comparison
26  int32_t iVer[2];
27 
28  C4GameVersion(const char *szEngine=C4ENGINENAME, int32_t iVer1=C4XVER1, int32_t iVer2=C4XVER2)
29  { Set(szEngine, iVer1, iVer2); }
30  void Set(const char *szEngine=C4ENGINENAME, int32_t iVer1=C4XVER1, int32_t iVer2=C4XVER2)
31  { sEngineName.CopyValidated(szEngine); iVer[0]=iVer1; iVer[1]=iVer2; }
33  { return FormatString("%s %d.%d", sEngineName.getData(), (int)iVer[0], (int)iVer[1]); }
34  bool operator == (const C4GameVersion &rCmp) const
35  { return iVer[0]==rCmp.iVer[0] && iVer[1]==rCmp.iVer[1]; }
36 
37  void CompileFunc(StdCompiler *pComp, bool fEngineName)
38  {
39  if (fEngineName)
40  {
41  pComp->Value(mkDefaultAdapt(sEngineName, ""));
42  pComp->Separator();
43  }
44  else if (pComp->isDeserializer())
45  sEngineName = "";
46  pComp->Value(mkArrayAdapt(iVer,2,0));
47  }
48 };
49 
50 // helper
51 inline int CompareVersion(int iVer1, int iVer2,
52  int iRVer1 = C4XVER1, int iRVer2 = C4XVER2)
53 {
54  if (iVer1 > iRVer1) return 1; if (iVer1 < iRVer1) return -1;
55  if (iVer2 > iRVer2) return 1; if (iVer2 < iRVer2) return -1;
56  return 0;
57 }
58 
59 #endif // C4GAMEVERSION_H
const char * getData() const
Definition: StdBuf.h:450
virtual bool Separator(Sep eSep=SEP_SEP)
Definition: StdCompiler.h:129
StdStrBuf GetString() const
Definition: C4GameVersion.h:32
ValidatedStdCopyStrBuf< C4InVal::VAL_NameAllowEmpty > sEngineName
Definition: C4GameVersion.h:25
int CompareVersion(int iVer1, int iVer2, int iRVer1=C4XVER1, int iRVer2=C4XVER2)
Definition: C4GameVersion.h:51
bool operator==(const C4GameVersion &rCmp) const
Definition: C4GameVersion.h:34
StdArrayAdapt< T > mkArrayAdapt(T *pArray, int iSize)
Definition: StdAdaptors.h:311
void Value(const T &rStruct)
Definition: StdCompiler.h:171
void CompileFunc(StdCompiler *pComp, bool fEngineName)
Definition: C4GameVersion.h:37
virtual bool isDeserializer()
Definition: StdCompiler.h:63
StdDefaultAdapt< T, D > mkDefaultAdapt(T &&rValue, const D &rDefault)
Definition: StdAdaptors.h:65
int32_t iVer[2]
Definition: C4GameVersion.h:26
void CopyValidated(const char *szFromVal)
C4GameVersion(const char *szEngine=C4ENGINENAME, int32_t iVer1=C4XVER1, int32_t iVer2=C4XVER2)
Definition: C4GameVersion.h:28
void Set(const char *szEngine=C4ENGINENAME, int32_t iVer1=C4XVER1, int32_t iVer2=C4XVER2)
Definition: C4GameVersion.h:30
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:277