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

#include <C4ValueMap.h>

Public Member Functions

 C4ValueMapNames ()
 
 C4ValueMapNames (const C4ValueMapNames &NamesToCopy)
 
C4ValueMapNamesoperator= (const C4ValueMapNames &NamesToCopy)
 
virtual ~C4ValueMapNames ()
 
void SetNameArray (const char **pnNames, int32_t nSize)
 
int32_t AddName (const char *pnName)
 
int32_t GetItemNr (const char *strName) const
 
const char * GetItemUnsafe (int32_t idx) const
 
void Reset ()
 

Public Attributes

char ** pNames {nullptr}
 
int32_t iSize {0}
 

Friends

class C4ValueMapData
 

Detailed Description

Definition at line 93 of file C4ValueMap.h.

Constructor & Destructor Documentation

C4ValueMapNames::C4ValueMapNames ( )
default
C4ValueMapNames::C4ValueMapNames ( const C4ValueMapNames NamesToCopy)

Definition at line 325 of file C4ValueMap.cpp.

References iSize, and pNames.

326 {
327  ChangeNameList(const_cast<const char **>(NamesToCopy.pNames), NamesToCopy.iSize);
328 }
char ** pNames
Definition: C4ValueMap.h:106
C4ValueMapNames::~C4ValueMapNames ( )
virtual

Definition at line 336 of file C4ValueMap.cpp.

References Reset().

337 {
338  Reset();
339 }

Here is the call graph for this function:

Member Function Documentation

int32_t C4ValueMapNames::AddName ( const char *  pnName)

Definition at line 429 of file C4ValueMap.cpp.

References GetItemNr(), and iSize.

Referenced by C4AulScriptFunc::AddPar(), and C4AulCompiler::PreparseAstVisitor::visit().

430 {
431  // name already existing?
432  int32_t iNr;
433  if ((iNr=GetItemNr(pnName)) != -1)
434  return iNr;
435 
436  // create new dummy lists
437  const char **pDummyNames = new const char *[iSize + 1];
438 
439  // copy all data from old list
440  // (danger! if ChangeNameList would now delete them before
441  // creating the new list, this would cause cruel errors...)
442  int32_t i;
443  for (i = 0; i < iSize; i++)
444  {
445  pDummyNames[i] = pNames[i];
446  }
447  pDummyNames[i] = pnName;
448 
449  // change list
450  ChangeNameList(pDummyNames, iSize + 1);
451 
452  // delete dummy arrays
453  delete[] pDummyNames;
454 
455  // return index to new element (simply last element)
456  return iSize-1;
457 }
int32_t GetItemNr(const char *strName) const
Definition: C4ValueMap.cpp:459
char ** pNames
Definition: C4ValueMap.h:106

Here is the call graph for this function:

Here is the caller graph for this function:

int32_t C4ValueMapNames::GetItemNr ( const char *  strName) const

Definition at line 459 of file C4ValueMap.cpp.

References iSize, and SEqual().

Referenced by AddName(), C4ValueMapData::GetItem(), C4AulCompiler::PreparseAstVisitor::visit(), and C4AulCompiler::CodegenAstVisitor::visit().

460 {
461  for (int32_t i = 0; i < iSize; i++)
462  if (SEqual(pNames[i], strName))
463  return i;
464  return -1;
465 }
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:93
char ** pNames
Definition: C4ValueMap.h:106

Here is the call graph for this function:

Here is the caller graph for this function:

const char* C4ValueMapNames::GetItemUnsafe ( int32_t  idx) const
inline

Definition at line 124 of file C4ValueMap.h.

References pNames.

124 { return pNames[idx]; }
char ** pNames
Definition: C4ValueMap.h:106
C4ValueMapNames & C4ValueMapNames::operator= ( const C4ValueMapNames NamesToCopy)

Definition at line 330 of file C4ValueMap.cpp.

References iSize, and pNames.

331 {
332  ChangeNameList(const_cast<const char **>(NamesToCopy.pNames), NamesToCopy.iSize);
333  return *this;
334 }
char ** pNames
Definition: C4ValueMap.h:106
void C4ValueMapNames::Reset ( )

Definition at line 341 of file C4ValueMap.cpp.

References iSize, and pNames.

Referenced by ~C4ValueMapNames().

342 {
343  // unreg all data lists
344  while (pFirst) UnRegister(pFirst);
345  // free name list
346  for (int32_t i = 0; i < iSize; i++)
347  delete[] pNames[i];
348  delete[] pNames;
349  pNames = nullptr;
350  iSize = 0;
351 }
char ** pNames
Definition: C4ValueMap.h:106

Here is the caller graph for this function:

void C4ValueMapNames::SetNameArray ( const char **  pnNames,
int32_t  nSize 
)

Definition at line 423 of file C4ValueMap.cpp.

Referenced by C4ValueMapData::CompileFunc().

424 {
425  // simply pass it through...
426  ChangeNameList(pnNames, nSize);
427 }

Here is the caller graph for this function:

Friends And Related Function Documentation

friend class C4ValueMapData
friend

Definition at line 95 of file C4ValueMap.h.

Member Data Documentation

char** C4ValueMapNames::pNames {nullptr}

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