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
 
int32_t iSize
 

Friends

class C4ValueMapData
 

Detailed Description

Definition at line 93 of file C4ValueMap.h.

Constructor & Destructor Documentation

C4ValueMapNames::C4ValueMapNames ( )

Definition at line 328 of file C4ValueMap.cpp.

329  : pNames(0), iSize(0), pFirst(0)
330 {
331 
332 }
char ** pNames
Definition: C4ValueMap.h:106
C4ValueMapNames::C4ValueMapNames ( const C4ValueMapNames NamesToCopy)

Definition at line 334 of file C4ValueMap.cpp.

References iSize, and pNames.

335  : pNames(0), iSize(0), pFirst(0)
336 {
337  ChangeNameList(const_cast<const char **>(NamesToCopy.pNames), NamesToCopy.iSize);
338 }
char ** pNames
Definition: C4ValueMap.h:106
C4ValueMapNames::~C4ValueMapNames ( )
virtual

Definition at line 346 of file C4ValueMap.cpp.

References Reset().

347 {
348  Reset();
349 }

Here is the call graph for this function:

Member Function Documentation

int32_t C4ValueMapNames::AddName ( const char *  pnName)

Definition at line 439 of file C4ValueMap.cpp.

References GetItemNr(), and iSize.

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

440 {
441  // name already existing?
442  int32_t iNr;
443  if ((iNr=GetItemNr(pnName)) != -1)
444  return iNr;
445 
446  // create new dummy lists
447  const char **pDummyNames = new const char *[iSize + 1];
448 
449  // copy all data from old list
450  // (danger! if ChangeNameList would now delete them before
451  // creating the new list, this would cause cruel errors...)
452  int32_t i;
453  for (i = 0; i < iSize; i++)
454  {
455  pDummyNames[i] = pNames[i];
456  }
457  pDummyNames[i] = pnName;
458 
459  // change list
460  ChangeNameList(pDummyNames, iSize + 1);
461 
462  // delete dummy arrays
463  delete[] pDummyNames;
464 
465  // return index to new element (simply last element)
466  return iSize-1;
467 }
int32_t GetItemNr(const char *strName) const
Definition: C4ValueMap.cpp:469
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 469 of file C4ValueMap.cpp.

References iSize, and SEqual().

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

470 {
471  for (int32_t i = 0; i < iSize; i++)
472  if (SEqual(pNames[i], strName))
473  return i;
474  return -1;
475 }
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:97
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.

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

Definition at line 340 of file C4ValueMap.cpp.

References iSize, and pNames.

341 {
342  ChangeNameList(const_cast<const char **>(NamesToCopy.pNames), NamesToCopy.iSize);
343  return *this;
344 }
char ** pNames
Definition: C4ValueMap.h:106
void C4ValueMapNames::Reset ( )

Definition at line 351 of file C4ValueMap.cpp.

References iSize, and pNames.

Referenced by ~C4ValueMapNames().

352 {
353  // unreg all data lists
354  while (pFirst) UnRegister(pFirst);
355  // free name list
356  for (int32_t i = 0; i < iSize; i++)
357  delete[] pNames[i];
358  delete[] pNames;
359  pNames = nullptr;
360  iSize = 0;
361 }
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 433 of file C4ValueMap.cpp.

Referenced by C4ValueMapData::CompileFunc().

434 {
435  // simply pass it through...
436  ChangeNameList(pnNames, nSize);
437 }

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

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