OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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
 
template<>
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

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

Definition at line 171 of file C4StringTable.h.

171  : Table(new T[Capacity])
172  {
173  ClearTable();
174  }
template<typename T>
C4Set< T >::~C4Set ( )
inline

Definition at line 175 of file C4StringTable.h.

176  {
177  delete[] Table;
178  }
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

Member Function Documentation

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

Definition at line 220 of file C4StringTable.h.

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

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

Here is the caller graph for this function:

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  }
template<typename T>
void C4Set< T >::Clear ( )
inline

Definition at line 194 of file C4StringTable.h.

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

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

Here is the caller graph for this function:

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

Definition at line 449 of file C4PropList.cpp.

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

450 {
451  bool fNaming = pComp->hasNaming();
452  if (pComp->isDeserializer())
453  {
454  // Compiling: Empty previous
455  Clear();
456  // Read size (binary only)
457  uint32_t iSize;
458  if (!pComp->hasNaming()) pComp->Value(iSize);
459  // Read new
460  do
461  {
462  // No entries left to read?
463  if (!fNaming && !iSize--)
464  break;
465  // Read entries
466  try
467  {
468  T e;
469  // This could use the same technique StdArrayAdapt uses
470  // instead of hardcoding mkParAdapt here
471  pComp->Value(mkParAdapt(e, numbers));
472  Add(e);
473  }
474  catch (StdCompiler::NotFoundException *pEx)
475  {
476  // No value found: Stop reading loop
477  delete pEx;
478  break;
479  }
480  }
481  while (pComp->Separator(StdCompiler::SEP_SEP));
482  }
483  else
484  {
485  // Write size (binary only)
486  if (!fNaming)
487  {
488  int32_t iSize = GetSize();
489  pComp->Value(iSize);
490  }
491  // Write all entries
492  const T * p = First();
493  while (p)
494  {
495  pComp->Value(mkParAdapt(*const_cast<T *>(p), numbers));
496  p = Next(p);
497  if (p) pComp->Separator(StdCompiler::SEP_SEP);
498  }
499  }
500 }
T * Add(T const &e)
void Clear()
T const * Next(T const *p) const
unsigned int GetSize() const
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
Definition: StdAdaptors.h:458
T const * First() const
int iSize
Definition: TstC4NetIO.cpp:32

Here is the call graph for this function:

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

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

Here is the caller graph for this function:

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 b
#define a
template<typename T>
T const* C4Set< T >::First ( ) const
inline
template<typename T>
template<typename H >
T& C4Set< T >::Get ( e) const
inline

Definition at line 199 of file C4StringTable.h.

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(), C4PropList::operator==(), and C4PropList::SetPropertyByS().

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 unsigned int Hash(const H &)
static bool Equals(const T &, const H &)

Here is the caller graph for this function:

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

Definition at line 219 of file C4StringTable.h.

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

219 { return Size; }

Here is the caller graph for this function:

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

Definition at line 279 of file C4StringTable.h.

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

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  }
T const * Next(T const *p) const
T const * First() const

Here is the caller graph for this function:

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

Definition at line 209 of file C4StringTable.h.

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().

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  }
static unsigned int Hash(const H &)
static bool Equals(const T &, const H &)

Here is the caller graph for this function:

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

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

Here is the caller graph for this function:

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

Definition at line 1075 of file C4PropList.cpp.

References C4Set< T >::Hash().

1076 {
1077  return C4Set<C4PropListNumbered *>::Hash(static_cast<int>(reinterpret_cast<intptr_t>(e)));
1078 }
static unsigned int Hash(const H &)

Here is the call graph for this function:

template<typename T>
T const* C4Set< T >::Next ( T const *  p) const
inline
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  }
template<typename T>
template<typename H >
void C4Set< T >::Remove ( e)
inline

Definition at line 234 of file C4StringTable.h.

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

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 = nullptr;
244  --Size;
245  // Move entries which might have collided with e
246  while (*(r = &Table[++h % Capacity]))
247  {
248  T m = *r;
249  *r = nullptr;
250  AddInternal(std::move(m));
251  }
252  }
static unsigned int Hash(const H &)
static bool Equals(const T &, const H &)

Here is the caller graph for this function:

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  }
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: