OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4RoundResultsPlayers Class Reference

#include <C4RoundResults.h>

Public Member Functions

 C4RoundResultsPlayers ()
 
 C4RoundResultsPlayers (const C4RoundResultsPlayers &cpy)
 
 ~C4RoundResultsPlayers ()
 
void Clear ()
 
void CompileFunc (StdCompiler *pComp)
 
C4RoundResultsPlayerGetByIndex (int32_t idx) const
 
C4RoundResultsPlayerGetByID (int32_t id) const
 
int32_t GetCount () const
 
void Add (C4RoundResultsPlayer *pNewPlayer)
 
C4RoundResultsPlayerGetCreateByID (int32_t id)
 
bool operator== (const C4RoundResultsPlayers &cmp)
 
C4RoundResultsPlayersoperator= (const C4RoundResultsPlayers &cpy)
 

Detailed Description

Definition at line 93 of file C4RoundResults.h.

Constructor & Destructor Documentation

C4RoundResultsPlayers::C4RoundResultsPlayers ( )
inline

Definition at line 101 of file C4RoundResults.h.

101 : ppPlayers(nullptr), iPlayerCount(0), iPlayerCapacity(0) {}
C4RoundResultsPlayers::C4RoundResultsPlayers ( const C4RoundResultsPlayers cpy)
inline

Definition at line 102 of file C4RoundResults.h.

102 : ppPlayers(nullptr), iPlayerCount(0), iPlayerCapacity(0) { *this=cpy; }
C4RoundResultsPlayers::~C4RoundResultsPlayers ( )
inline

Definition at line 103 of file C4RoundResults.h.

References Clear().

103 { Clear(); }

Here is the call graph for this function:

Member Function Documentation

void C4RoundResultsPlayers::Add ( C4RoundResultsPlayer pNewPlayer)

Definition at line 198 of file C4RoundResults.cpp.

Referenced by GetCreateByID(), and operator=().

199 {
200  assert(pNewPlayer);
201  if (iPlayerCount == iPlayerCapacity) GrowList(4);
202  ppPlayers[iPlayerCount++] = pNewPlayer;
203 }

Here is the caller graph for this function:

void C4RoundResultsPlayers::Clear ( )

Definition at line 139 of file C4RoundResults.cpp.

Referenced by C4RoundResults::Clear(), CompileFunc(), operator=(), and ~C4RoundResultsPlayers().

140 {
141  while (iPlayerCount) delete ppPlayers[--iPlayerCount];
142  delete [] ppPlayers;
143  ppPlayers = nullptr;
144  iPlayerCapacity = 0;
145 }

Here is the caller graph for this function:

void C4RoundResultsPlayers::CompileFunc ( StdCompiler pComp)

Definition at line 147 of file C4RoundResults.cpp.

References C4MaxPlayer, Clear(), StdCompiler::excCorrupt(), StdCompiler::isDeserializer(), mkArrayAdaptMap(), mkNamingAdapt(), StdCompiler::Value(), and ZeroMem().

148 {
149  bool deserializing = pComp->isDeserializer();
150  if (deserializing) Clear();
151  int32_t iTemp = iPlayerCount;
152  pComp->Value(mkNamingCountAdapt<int32_t>(iTemp, "Player"));
153  if (iTemp < 0 || iTemp > C4MaxPlayer)
154  { pComp->excCorrupt("player count out of range"); return; }
155  // Grow list, if necessary
156  if (deserializing && iTemp > iPlayerCapacity)
157  {
158  GrowList(iTemp - iPlayerCapacity);
159  iPlayerCount = iTemp;
160  ZeroMem(ppPlayers, sizeof(*ppPlayers) * iPlayerCount);
161  }
162  // Compile
163  pComp->Value(mkNamingAdapt(mkArrayAdaptMap(ppPlayers, iPlayerCount, mkPtrAdaptNoNull<C4RoundResultsPlayer>), "Player"));
164  // Force specialization
165  mkPtrAdaptNoNull<C4RoundResultsPlayer>(*ppPlayers);
166 }
void excCorrupt(const char *szMessage,...)
Definition: StdCompiler.h:259
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:93
void Value(const T &rStruct)
Definition: StdCompiler.h:171
const int32_t C4MaxPlayer
Definition: C4Player.h:39
virtual bool isDeserializer()
Definition: StdCompiler.h:63
std::enable_if< std::is_pod< T >::value >::type ZeroMem(T *lpMem, size_t dwSize)
Definition: Standard.h:63
StdArrayAdapt< T, M > mkArrayAdaptMap(T *pArray, int iSize, M &&map)
Definition: StdAdaptors.h:314

Here is the call graph for this function:

C4RoundResultsPlayer * C4RoundResultsPlayers::GetByID ( int32_t  id) const

Definition at line 176 of file C4RoundResults.cpp.

Referenced by GetCreateByID(), and C4RoundResults::GetLeaguePerformance().

177 {
178  for (int32_t idx=0; idx<iPlayerCount; ++idx)
179  if (ppPlayers[idx]->GetID() == id)
180  return ppPlayers[idx];
181  return nullptr;
182 }

Here is the caller graph for this function:

C4RoundResultsPlayer * C4RoundResultsPlayers::GetByIndex ( int32_t  idx) const

Definition at line 168 of file C4RoundResults.cpp.

Referenced by C4RoundResults::EvaluateLeague(), and operator=().

169 {
170  if (idx>=0 && idx<iPlayerCount)
171  return ppPlayers[idx];
172  else
173  return nullptr;
174 }

Here is the caller graph for this function:

int32_t C4RoundResultsPlayers::GetCount ( ) const
inline

Definition at line 115 of file C4RoundResults.h.

115 { return iPlayerCount; }
C4RoundResultsPlayer * C4RoundResultsPlayers::GetCreateByID ( int32_t  id)

Definition at line 205 of file C4RoundResults.cpp.

References Add(), GetByID(), and C4RoundResultsPlayer::SetID().

Referenced by C4RoundResults::AddCustomEvaluationString(), C4RoundResults::EvaluateLeague(), C4RoundResults::EvaluatePlayer(), and C4RoundResults::SetLeaguePerformance().

206 {
207  assert(id);
208  // find existing
209  C4RoundResultsPlayer *pPlr = GetByID(id);
210  // not found: Add new
211  if (!pPlr)
212  {
213  pPlr = new C4RoundResultsPlayer();
214  pPlr->SetID(id);
215  Add(pPlr);
216  }
217  return pPlr;
218 }
void Add(C4RoundResultsPlayer *pNewPlayer)
void SetID(int32_t idNew)
C4RoundResultsPlayer * GetByID(int32_t id) const

Here is the call graph for this function:

Here is the caller graph for this function:

C4RoundResultsPlayers & C4RoundResultsPlayers::operator= ( const C4RoundResultsPlayers cpy)

Definition at line 230 of file C4RoundResults.cpp.

References Add(), Clear(), and GetByIndex().

231 {
232  Clear();
233  C4RoundResultsPlayer *pPlr; int32_t i=0;
234  while ((pPlr = cpy.GetByIndex(i++)))
235  Add(new C4RoundResultsPlayer(*pPlr));
236  return *this;
237 }
C4RoundResultsPlayer * GetByIndex(int32_t idx) const
void Add(C4RoundResultsPlayer *pNewPlayer)

Here is the call graph for this function:

bool C4RoundResultsPlayers::operator== ( const C4RoundResultsPlayers cmp)

Definition at line 220 of file C4RoundResults.cpp.

221 {
222  if (iPlayerCount != cmp.iPlayerCount) return false;
223  for (int32_t i = 0; i < iPlayerCount; ++i)
224  if (!(*ppPlayers[i] == *cmp.ppPlayers[i]))
225  return false;
226  // equal
227  return true;
228 }

The documentation for this class was generated from the following files: