Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
Dict Class Reference

#include <Dict.h>

Public Types

enum  { MAX_LEN = 32767 }
 
enum  DataType {
  DICT_NONE = -1 , DICT_BOOL = 0 , DICT_INT , DICT_REAL ,
  DICT_ASCIISTRING , DICT_UNICODESTRING
}
 

Public Member Functions

 Dict (Int numPairsToPreAllocate=0)
 
 Dict (const Dict &src)
 
 ~Dict ()
 
Dictoperator= (const Dict &src)
 
void clear ()
 
Int getPairCount () const
 
NameKeyType getNthKey (Int n) const
 
DataType getType (NameKeyType key) const
 
Bool known (NameKeyType key, DataType d) const
 
DataType getNthType (Int n) const
 
Bool getBool (NameKeyType key, Bool *exists=NULL) const
 
Int getInt (NameKeyType key, Bool *exists=NULL) const
 
Real getReal (NameKeyType key, Bool *exists=NULL) const
 
AsciiString getAsciiString (NameKeyType key, Bool *exists=NULL) const
 
UnicodeString getUnicodeString (NameKeyType key, Bool *exists=NULL) const
 
Bool getNthBool (Int n) const
 
Int getNthInt (Int n) const
 
Real getNthReal (Int n) const
 
AsciiString getNthAsciiString (Int n) const
 
UnicodeString getNthUnicodeString (Int n) const
 
void setBool (NameKeyType key, Bool value)
 
void setInt (NameKeyType key, Int value)
 
void setReal (NameKeyType key, Real value)
 
void setAsciiString (NameKeyType key, const AsciiString &value)
 
void setUnicodeString (NameKeyType key, const UnicodeString &value)
 
Bool remove (NameKeyType key)
 
void copyPairFrom (const Dict &that, NameKeyType key)
 

Detailed Description

Dict provides a general utility class for maintaining a sorted key-value pair list. Keys are currently required to be of type NameKeyType, and data may be Bool, int, real, or string.

Current implementation keeps the pairs sorted by key, and does a binary search for lookups; this might change in the future, depending on usage and performance (e.g., to a hashtable). So don't rely on the quirks of this implementation.

Definition at line 66 of file Dict.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
MAX_LEN 

max total len of any Dict, in Pairs

Definition at line 69 of file Dict.h.

◆ DataType

Enumerator
DICT_NONE 
DICT_BOOL 
DICT_INT 
DICT_REAL 
DICT_ASCIISTRING 
DICT_UNICODESTRING 

Definition at line 74 of file Dict.h.

Constructor & Destructor Documentation

◆ Dict() [1/2]

Dict::Dict ( Int numPairsToPreAllocate = 0)

Default constructor – construct a new, empty Dict.

Definition at line 224 of file Dict.cpp.

◆ Dict() [2/2]

Dict::Dict ( const Dict & src)
inline

Copy constructor – make this Dict identical to the other Dict. (This is actually quite efficient, because they will simply share the same data and increment the refcount.)

Definition at line 332 of file Dict.h.

◆ ~Dict()

Dict::~Dict ( )
inline

Destructor. Not too exciting... clean up the works and such.

Definition at line 339 of file Dict.h.

Member Function Documentation

◆ clear()

void Dict::clear ( )

remove all pairs.

Definition at line 201 of file Dict.cpp.

◆ copyPairFrom()

void Dict::copyPairFrom ( const Dict & that,
NameKeyType key )

copy the pair with the given key from 'that', replacing any such pair in 'this'. if no such pair exists in 'that', any pair with that key will be removed from 'this'.

Definition at line 534 of file Dict.cpp.

◆ getAsciiString()

AsciiString Dict::getAsciiString ( NameKeyType key,
Bool * exists = NULL ) const

return the value for the pair with the given key. if there is no pair with the given key, or the value is not of the correct type, "" is returned.

Definition at line 314 of file Dict.cpp.

◆ getBool()

Bool Dict::getBool ( NameKeyType key,
Bool * exists = NULL ) const

return the value for the pair with the given key. if there is no pair with the given key, or the value is not of the correct type, 0 is returned.

Definition at line 269 of file Dict.cpp.

◆ getInt()

Int Dict::getInt ( NameKeyType key,
Bool * exists = NULL ) const

return the value for the pair with the given key. if there is no pair with the given key, or the value is not of the correct type, 0 is returned.

Definition at line 284 of file Dict.cpp.

◆ getNthAsciiString()

AsciiString Dict::getNthAsciiString ( Int n) const

return the value for the pair with the given index. if the index is out of range, or the value is not of the correct type, "" is returned.

Definition at line 389 of file Dict.cpp.

◆ getNthBool()

Bool Dict::getNthBool ( Int n) const

return the value for the pair with the given index. if the index is out of range, or the value is not of the correct type, 0 is returned.

Definition at line 344 of file Dict.cpp.

◆ getNthInt()

Int Dict::getNthInt ( Int n) const

return the value for the pair with the given index. if the index is out of range, or the value is not of the correct type, 0 is returned.

Definition at line 359 of file Dict.cpp.

◆ getNthKey()

NameKeyType Dict::getNthKey ( Int n) const
inline

Return the key for the nth pair (0-based index). return NAMEKEY_INVALID if n is out of range.

Definition at line 351 of file Dict.h.

◆ getNthReal()

Real Dict::getNthReal ( Int n) const

return the value for the pair with the given index. if the index is out of range, or the value is not of the correct type, 0 is returned.

Definition at line 374 of file Dict.cpp.

◆ getNthType()

Dict::DataType Dict::getNthType ( Int n) const
inline

Return the datatype for the nth pair (0-based index). return DICT_NONE if n is out of range.

Definition at line 359 of file Dict.h.

◆ getNthUnicodeString()

UnicodeString Dict::getNthUnicodeString ( Int n) const

return the value for the pair with the given index. if the index is out of range, or the value is not of the correct type, "" is returned.

Definition at line 404 of file Dict.cpp.

◆ getPairCount()

Int Dict::getPairCount ( ) const
inline

return the number of key-value pairs in the dict.

Definition at line 345 of file Dict.h.

◆ getReal()

Real Dict::getReal ( NameKeyType key,
Bool * exists = NULL ) const

return the value for the pair with the given key. if there is no pair with the given key, or the value is not of the correct type, 0 is returned.

Definition at line 299 of file Dict.cpp.

◆ getType()

Dict::DataType Dict::getType ( NameKeyType key) const

Return the datatype for the pair with the given key. return DICT_NONE if no pair with the key exists.

Definition at line 259 of file Dict.cpp.

◆ getUnicodeString()

UnicodeString Dict::getUnicodeString ( NameKeyType key,
Bool * exists = NULL ) const

return the value for the pair with the given key. if there is no pair with the given key, or the value is not of the correct type, "" is returned.

Definition at line 329 of file Dict.cpp.

◆ known()

Bool Dict::known ( NameKeyType key,
DataType d ) const
inline

Return there is a pair with the given key and datatype, return true.

Definition at line 131 of file Dict.h.

◆ operator=()

Dict & Dict::operator= ( const Dict & src)

Definition at line 244 of file Dict.cpp.

◆ remove()

Bool Dict::remove ( NameKeyType key)

remove the pair with the given key. if such a pair existed, return true. if no such pair existed, return false.

Definition at line 516 of file Dict.cpp.

◆ setAsciiString()

void Dict::setAsciiString ( NameKeyType key,
const AsciiString & value )

set the value for the pair with the given key. if no such pair exists, it is created. if such a pair exists, it is replaced. note that when replacing a pair, the new and old data types need not match.

Definition at line 496 of file Dict.cpp.

◆ setBool()

void Dict::setBool ( NameKeyType key,
Bool value )

set the value for the pair with the given key. if no such pair exists, it is created. if such a pair exists, it is replaced. note that when replacing a pair, the new and old data types need not match.

Definition at line 466 of file Dict.cpp.

◆ setInt()

void Dict::setInt ( NameKeyType key,
Int value )

set the value for the pair with the given key. if no such pair exists, it is created. if such a pair exists, it is replaced. note that when replacing a pair, the new and old data types need not match.

Definition at line 476 of file Dict.cpp.

◆ setReal()

void Dict::setReal ( NameKeyType key,
Real value )

set the value for the pair with the given key. if no such pair exists, it is created. if such a pair exists, it is replaced. note that when replacing a pair, the new and old data types need not match.

Definition at line 486 of file Dict.cpp.

◆ setUnicodeString()

void Dict::setUnicodeString ( NameKeyType key,
const UnicodeString & value )

set the value for the pair with the given key. if no such pair exists, it is created. if such a pair exists, it is replaced. note that when replacing a pair, the new and old data types need not match.

Definition at line 506 of file Dict.cpp.


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