OpenClonk
C4Set< T > Class Template Reference

#include <C4StringTable.h>

Inheritance diagram for C4Set< T >:
[legend]

Public Member Functions

 C4Set ()
 
 ~C4Set ()
 
 C4Set (const C4Set &b)
 
C4Setoperator= (const C4Set &b)
 
void CompileFunc (class StdCompiler *pComp, class C4ValueNumbers *)
 
void Clear ()
 
template<typename H >
T & Get (H e) const
 
template<typename H >
bool Has (H e) const
 
unsigned int GetSize () const
 
T * Add (T const &e)
 
T * Add (T &&e)
 
template<typename H >
void Remove (H e)
 
T const * First () const
 
T const * Next (T const *p) const
 
void Swap (C4Set< T > *S2)
 
std::list< const T * > GetSortedListOfElementPointers () const
 
unsigned int Hash (C4PropList *const &e)
 

Static Public Member Functions

template<typename H >
static unsigned int Hash (const H &)
 
template<typename H >
static bool Equals (const T &, const H &)
 
static bool Equals (const T &a, const T &b)
 
static bool SortFunc (const T *p1, const T *p2)
 

Detailed Description

template<typename T>
class C4Set< T >

Definition at line 118 of file C4StringTable.h.

Constructor & Destructor Documentation

◆ C4Set() [1/2]

template<typename T >
C4Set< T >::C4Set ( )
inline

Definition at line 171 of file C4StringTable.h.

171  : Table(new T[Capacity])
172  {
173  ClearTable();
174  }

◆ ~C4Set()

template<typename T >
C4Set< T >::~C4Set ( )
inline

Definition at line 175 of file C4StringTable.h.

176  {
177  delete[] Table;
178  }

◆ C4Set() [2/2]

template<typename T >
C4Set< T >::C4Set ( const C4Set< T > &  b)
inline

Definition at line 179 of file C4StringTable.h.

179  : Capacity(0), Size(0), Table(0)
180  {
181  *this = b;
182  }
#define b

References b.

Member Function Documentation

◆ Add() [1/2]

template<typename T >
T* C4Set< T >::Add ( T &&  e)
inline

Definition at line 227 of file C4StringTable.h.

228  {
229  MaintainCapacity();
230  T * r = AddInternal(std::move(e));
231  ++Size;
232  return r;
233  }

◆ Add() [2/2]

template<typename T >
T* C4Set< T >::Add ( T const &  e)
inline

Definition at line 220 of file C4StringTable.h.

221  {
222  MaintainCapacity();
223  T * r = AddInternal(e);
224  ++Size;
225  return r;
226  }

Referenced by C4PropListNumbered::AcquireNumber(), C4PropListScript::C4PropListScript(), C4PropListNumbered::CompileFunc(), and C4PropList::SetPropertyByS().

Here is the caller graph for this function:

◆ Clear()

template<typename T >
void C4Set< T >::Clear ( )
inline

Definition at line 194 of file C4StringTable.h.

195  {
196  ClearTable();
197  Size = 0;
198  }

Referenced by C4PropList::Clear(), C4ScriptHost::Clear(), and C4ScriptHost::Preparse().

Here is the caller graph for this function:

◆ CompileFunc()

template<typename T >
void C4Set< T >::CompileFunc ( class StdCompiler pComp,
class C4ValueNumbers numbers 
)

Definition at line 418 of file C4PropList.cpp.

419 {
420  bool fNaming = pComp->hasNaming();
421  if (pComp->isDeserializer())
422  {
423  // Compiling: Empty previous
424  Clear();
425  // Read size (binary only)
426  uint32_t iSize;
427  if (!pComp->hasNaming()) pComp->Value(iSize);
428  // Read new
429  do
430  {
431  // No entries left to read?
432  if (!fNaming && !iSize--)
433  break;
434  // Read entries
435  try
436  {
437  T e;
438  // This could use the same technique StdArrayAdapt uses
439  // instead of hardcoding mkParAdapt here
440  pComp->Value(mkParAdapt(e, numbers));
441  Add(e);
442  }
443  catch (StdCompiler::NotFoundException *pEx)
444  {
445  // No value found: Stop reading loop
446  delete pEx;
447  break;
448  }
449  }
450  while (pComp->Separator(StdCompiler::SEP_SEP));
451  }
452  else
453  {
454  // Write size (binary only)
455  if (!fNaming)
456  {
457  int32_t iSize = GetSize();
458  pComp->Value(iSize);
459  }
460  // Write all entries
461  const T * p = First();
462  while (p)
463  {
464  pComp->Value(mkParAdapt(*const_cast<T *>(p), numbers));
465  p = Next(p);
466  if (p) pComp->Separator(StdCompiler::SEP_SEP);
467  }
468  }
469 }
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
Definition: StdAdaptors.h:490
int iSize
Definition: TstC4NetIO.cpp:32
T const * Next(T const *p) const
void Clear()
T * Add(T const &e)
unsigned int GetSize() const
T const * First() const

References StdCompiler::hasNaming(), StdCompiler::isDeserializer(), iSize, mkParAdapt(), StdCompiler::SEP_SEP, StdCompiler::Separator(), and StdCompiler::Value().

Here is the call graph for this function:

◆ Equals() [1/2]

template<typename T >
template<typename H >
static bool C4Set< T >::Equals ( const T &  ,
const H &   
)
static

Referenced by C4Set< T >::Get(), C4Set< T >::Has(), and C4Set< T >::Remove().

Here is the caller graph for this function:

◆ Equals() [2/2]

template<typename T >
static bool C4Set< T >::Equals ( const T &  a,
const T &  b 
)
inlinestatic

Definition at line 170 of file C4StringTable.h.

170 { return a == b; }
#define a

References a, and b.

◆ First()

template<typename T >
T const* C4Set< T >::First ( ) const
inline

Definition at line 253 of file C4StringTable.h.

253 { return Next(Table - 1); }

References C4Set< T >::Next().

Referenced by C4PropList::begin(), C4PropListNumbered::CheckPropList(), C4PropListNumbered::ClearNumberedPropLists(), C4PropListScript::ClearScriptPropLists(), C4ScriptHost::CopyPropList(), C4PropList::Denumerate(), C4PropList::EnumerateOwnFuncs(), C4PropList::GetProperties(), C4Set< T >::GetSortedListOfElementPointers(), C4PropList::GetSortedLocalProperties(), C4PropList::GetUnsortedProperties(), C4PropList::operator==(), C4PropListNumbered::ShelveNumberedPropLists(), and C4StringTable::~C4StringTable().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Get()

template<typename T >
template<typename H >
T& C4Set< T >::Get ( e) const
inline

Definition at line 199 of file C4StringTable.h.

200  {
201  unsigned int h = Hash(e);
202  T * r = &Table[h % Capacity];
203  while (*r && !Equals(*r, e))
204  {
205  r = &Table[++h % Capacity];
206  }
207  return *r;
208  }
static bool Equals(const T &, const H &)
static unsigned int Hash(const H &)

References C4Set< T >::Equals(), and C4Set< T >::Hash().

Referenced by C4PropListNumbered::AcquireNumber(), C4PropList::CompileFunc(), C4PropListNumbered::CompileFunc(), C4PropList::EnumerateOwnFuncs(), C4StringTable::FindString(), C4PropListNumbered::GetByNumber(), C4PropList::GetFunc(), C4PropList::GetPropertyArray(), C4PropList::GetPropertyBool(), C4PropList::GetPropertyByS(), C4PropList::GetPropertyInt(), C4PropList::GetPropertyP(), C4PropList::GetPropertyPropList(), C4PropList::GetPropertyStr(), and C4PropList::SetPropertyByS().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetSize()

template<typename T >
unsigned int C4Set< T >::GetSize ( ) const
inline

Definition at line 219 of file C4StringTable.h.

219 { return Size; }

Referenced by C4PropList::AppendDataString(), C4PropList::begin(), C4PropListScript::ClearScriptPropLists(), C4PropList::GetProperties(), C4PropList::operator==(), C4PropListNumbered::ResetEnumerationIndex(), C4PropListNumbered::ShelveNumberedPropLists(), C4PropList::ToJSON(), and C4StringTable::~C4StringTable().

Here is the caller graph for this function:

◆ GetSortedListOfElementPointers()

template<typename T >
std::list<const T *> C4Set< T >::GetSortedListOfElementPointers ( ) const
inline

Definition at line 279 of file C4StringTable.h.

280  {
281  // return a list of pointers to all elements in this set sorted by the standard less-than operation
282  // of the elements
283  // elements of resulting lists are guarantueed to be non-nullptr
284  // list remains valid as long as this set is not changed
285  std::list<const T *> result;
286  for (const T *p = First(); p; p = Next(p)) result.push_back(p);
287  result.sort(C4Set<T>::SortFunc);
288  return result;
289  }

References C4Set< T >::First(), and C4Set< T >::Next().

Referenced by C4PropList::AppendDataString(), C4PropList::GetSortedLocalProperties(), and C4PropList::ToJSON().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Has()

template<typename T >
template<typename H >
bool C4Set< T >::Has ( e) const
inline

Definition at line 209 of file C4StringTable.h.

210  {
211  unsigned int h = Hash(e);
212  T * r = &Table[h % Capacity];
213  while (*r && !Equals(*r, e))
214  {
215  r = &Table[++h % Capacity];
216  }
217  return !!*r;
218  }

References C4Set< T >::Equals(), and C4Set< T >::Hash().

Referenced by C4PropList::CompileFunc(), C4PropList::GetFunc(), C4PropList::GetPropertyArray(), C4PropList::GetPropertyBool(), C4PropList::GetPropertyByS(), C4PropList::GetPropertyInt(), C4PropList::GetPropertyP(), C4PropList::GetPropertyPropList(), C4PropList::GetPropertyStr(), C4PropList::HasProperty(), and C4PropList::SetPropertyByS().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Hash() [1/2]

unsigned int C4Set< C4PropList * >::Hash< C4PropList * > ( C4PropList *const &  e)

Definition at line 1063 of file C4PropList.cpp.

1064 {
1065  return C4Set<C4PropListNumbered *>::Hash(static_cast<int>(reinterpret_cast<intptr_t>(e)));
1066 }

References C4Set< T >::Hash().

Here is the call graph for this function:

◆ Hash() [2/2]

template<typename T >
template<typename H >
static unsigned int C4Set< T >::Hash ( const H &  )
static

Referenced by C4Set< T >::Get(), C4Set< T >::Has(), C4Set< T >::Hash(), and C4Set< T >::Remove().

Here is the caller graph for this function:

◆ Next()

template<typename T >
T const* C4Set< T >::Next ( T const *  p) const
inline

Definition at line 254 of file C4StringTable.h.

255  {
256  while (++p != &Table[Capacity])
257  {
258  if (*p) return p;
259  }
260  return nullptr;
261  }

Referenced by C4PropList::begin(), C4PropListNumbered::CheckPropList(), C4PropListNumbered::ClearNumberedPropLists(), C4Set< C4PropListScript * >::CompileFunc(), C4ScriptHost::CopyPropList(), C4PropList::Denumerate(), C4PropList::EnumerateOwnFuncs(), C4Set< T >::First(), C4PropList::GetProperties(), C4Set< T >::GetSortedListOfElementPointers(), C4PropList::GetSortedLocalProperties(), C4PropList::GetUnsortedProperties(), C4PropList::operator==(), C4PropListNumbered::ShelveNumberedPropLists(), and C4StringTable::~C4StringTable().

Here is the caller graph for this function:

◆ operator=()

template<typename T >
C4Set& C4Set< T >::operator= ( const C4Set< T > &  b)
inline

Definition at line 183 of file C4StringTable.h.

184  {
185  Capacity = b.Capacity;
186  Size = b.Size;
187  delete[] Table;
188  Table = new T[Capacity];
189  for (unsigned int i = 0; i < Capacity; ++i)
190  Table[i] = b.Table[i];
191  return *this;
192  }

References b.

◆ Remove()

template<typename T >
template<typename H >
void C4Set< T >::Remove ( e)
inline

Definition at line 234 of file C4StringTable.h.

235  {
236  unsigned int h = Hash(e);
237  T * r = &Table[h % Capacity];
238  while (*r && !Equals(*r, e))
239  {
240  r = &Table[++h % Capacity];
241  }
242  assert(*r);
243  *r = T{};
244  --Size;
245  // Move entries which might have collided with e
246  while (*(r = &Table[++h % Capacity]))
247  {
248  T m = *r;
249  *r = T{};
250  AddInternal(std::move(m));
251  }
252  }

References C4Set< T >::Equals(), and C4Set< T >::Hash().

Referenced by C4PropListNumbered::ClearNumber(), C4PropList::CompileFunc(), C4PropList::ResetProperty(), C4PropListNumbered::~C4PropListNumbered(), C4PropListScript::~C4PropListScript(), and C4String::~C4String().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SortFunc()

template<typename T >
static bool C4Set< T >::SortFunc ( const T *  p1,
const T *  p2 
)
inlinestatic

Definition at line 274 of file C4StringTable.h.

275  {
276  // elements are guarantueed to be non-nullptr
277  return *p1<*p2;
278  }

◆ Swap()

template<typename T >
void C4Set< T >::Swap ( C4Set< T > *  S2)
inline

Definition at line 262 of file C4StringTable.h.

263  {
264  unsigned int Capacity2 = S2->Capacity;
265  unsigned int Size2 = S2->Size;
266  T * Table2 = S2->Table;
267  S2->Capacity = Capacity;
268  S2->Size = Size;
269  S2->Table = Table;
270  Capacity = Capacity2;
271  Size = Size2;
272  Table = Table2;
273  }

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