OpenClonk
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() [1/2]

C4ValueMapNames::C4ValueMapNames ( )
default

Referenced by C4ValueMapData::CompileFunc().

Here is the caller graph for this function:

◆ C4ValueMapNames() [2/2]

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::~C4ValueMapNames ( )
virtual

Definition at line 336 of file C4ValueMap.cpp.

References C4ValueMapData::Reset().

337 {
338  Reset();
339 }
Here is the call graph for this function:

Member Function Documentation

◆ AddName()

int32_t C4ValueMapNames::AddName ( const char *  pnName)

Definition at line 429 of file C4ValueMap.cpp.

References iSize, and C4ValueMapData::pNames.

Referenced by C4AulScriptFunc::AddPar(), and C4AulScriptEngine::RegisterGlobalConstant().

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 caller graph for this function:

◆ GetItemNr()

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

Definition at line 459 of file C4ValueMap.cpp.

References iSize, C4ValueMapData::pNames, and SEqual().

Referenced by C4AulScriptEngine::GetGlobalConstant(), C4ValueMapData::GetItem(), C4AulDebug::OnLog(), 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:

◆ GetItemUnsafe()

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

Definition at line 124 of file C4ValueMap.h.

References C4ValueMapData::pData, C4ValueMapData::pNames, and C4ValueMapData::Reset().

124 { return pNames[idx]; }
char ** pNames
Definition: C4ValueMap.h:106
Here is the call graph for this function:

◆ operator=()

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

◆ Reset()

void C4ValueMapNames::Reset ( )

Definition at line 341 of file C4ValueMap.cpp.

References iSize, C4ValueMapData::pData, C4ValueMapData::pNames, SCopy(), and SLen().

Referenced by C4AulScriptEngine::Clear().

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 call graph for this function:
Here is the caller graph for this function:

◆ SetNameArray()

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

◆ C4ValueMapData

friend class C4ValueMapData
friend

Definition at line 95 of file C4ValueMap.h.

Member Data Documentation

◆ iSize

◆ pNames

char** C4ValueMapNames::pNames {nullptr}

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