OpenClonk
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 #include <utility>
23 
25 {
26  ValidatedStdCopyStrBuf<C4InVal::VAL_NameAllowEmpty> sEngineName; // status only - not used for comparison
27  int32_t iVer[2];
28 
29  C4GameVersion(const char *szEngine=C4ENGINENAME, int32_t iVer1=C4XVER1, int32_t iVer2=C4XVER2)
30  { Set(szEngine, iVer1, iVer2); }
31  void Set(const char *szEngine=C4ENGINENAME, int32_t iVer1=C4XVER1, int32_t iVer2=C4XVER2)
32  { sEngineName.CopyValidated(szEngine); iVer[0]=iVer1; iVer[1]=iVer2; }
34  { return FormatString("%s %d.%d", sEngineName.getData(), (int)iVer[0], (int)iVer[1]); }
35  bool operator == (const C4GameVersion &rCmp) const
36  { return iVer[0]==rCmp.iVer[0] && iVer[1]==rCmp.iVer[1]; }
37 
38  void CompileFunc(StdCompiler *pComp, bool fEngineName)
39  {
40  if (fEngineName)
41  {
42  pComp->Value(mkDefaultAdapt(sEngineName, ""));
43  pComp->Separator();
44  }
45  else if (pComp->isDeserializer())
46  sEngineName = "";
47  pComp->Value(mkArrayAdapt(iVer,2,0));
48  }
49 };
50 
51 // helper
52 inline int CompareVersion(int iVer1, int iVer2,
53  int iRVer1 = C4XVER1, int iRVer2 = C4XVER2)
54 {
55  auto ver = std::make_pair(iVer1, iVer2);
56  auto rVer = std::make_pair(iRVer1, iRVer2);
57 
58  if (ver < rVer) return -1;
59  if (ver > rVer) return 1;
60  return 0;
61 }
62 
63 #endif // C4GAMEVERSION_H
int CompareVersion(int iVer1, int iVer2, int iRVer1=C4XVER1, int iRVer2=C4XVER2)
Definition: C4GameVersion.h:52
StdDefaultAdapt< T, D > mkDefaultAdapt(T &&rValue, const D &rDefault)
Definition: StdAdaptors.h:64
StdArrayAdapt< T > mkArrayAdapt(T *pArray, int iSize)
Definition: StdAdaptors.h:336
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270
virtual bool Separator(Sep eSep=SEP_SEP)
Definition: StdCompiler.h:119
void Value(const T &rStruct)
Definition: StdCompiler.h:161
virtual bool isDeserializer()
Definition: StdCompiler.h:53
const char * getData() const
Definition: StdBuf.h:442
int32_t iVer[2]
Definition: C4GameVersion.h:27
ValidatedStdCopyStrBuf< C4InVal::VAL_NameAllowEmpty > sEngineName
Definition: C4GameVersion.h:26
void Set(const char *szEngine=C4ENGINENAME, int32_t iVer1=C4XVER1, int32_t iVer2=C4XVER2)
Definition: C4GameVersion.h:31
void CompileFunc(StdCompiler *pComp, bool fEngineName)
Definition: C4GameVersion.h:38
StdStrBuf GetString() const
Definition: C4GameVersion.h:33
C4GameVersion(const char *szEngine=C4ENGINENAME, int32_t iVer1=C4XVER1, int32_t iVer2=C4XVER2)
Definition: C4GameVersion.h:29
bool operator==(const C4GameVersion &rCmp) const
Definition: C4GameVersion.h:35
void CopyValidated(const char *szFromVal)