Home2L - C/C++ API v1.4-0-g38cc (2024-05-25)
Smart Tools for a Private Home
List of all members
CDict< T > Class Template Reference

Description

template<typename T>
class CDict< T >

Dictionary.

A dictionary stores arbitrary (key, value) pairs. The key is always of type CString / const char *. Internally, the dictionary is stored in an array containing the (key, value) pairs, which is kept ordered by the keys.

The values are dynamically allocated objects, to which pointers are stored in the array. All 'Set...' methods require dynamic objects to be passed and take over their ownerships. On element deletion, these objects are deleted. It is legal to pass NULL to 'Set...' methods.

Definition at line 1195 of file base.H.

#include "base.H"

Inheritance diagram for CDict< T >:
Inheritance graph
[legend]

Public Member Functions

Read access ...
T * Get (int idx)
 
T * Get (const char *key)
 
T * operator[] (int idx)
 
T * operator[] (const char *key)
 
Write access ...

For any operations passing a new value object, the dictionary takes over the ownership: The pointer passed as 'value' remains valid until the entry is deleted from the list. Then it will be free'd using 'delete'.

int Set (const char *key, T *value)
 Add or replace the keyed entry. Complexity is O(n). More...
 
void SetValue (int idx, T *value)
 Set (replace) a value. More...
 
T * DisownValue (int idx)
 Disown a value and clear it in the dictionary.
 
T * DisownValue (const char *key)
 Disown a value and clear it in the dictionary.
 
void Merge (CDict< T > *dict2)
 Merge another dictionary into this one. Complexity is O(n_this + n_dict2). 'dict2' will be empty afterwards. More...
 
- Public Member Functions inherited from CDictRaw
void Del (int idx)
 Delete entry; complexity is O(n). More...
 
void Del (const char *key)
 Delete entry by key; complexity is O(n).
 
const char * GetKey (int idx) const
 Get key by index.
 
int Find (const char *key, int *retInsIdx=NULL)
 Make binary search and return index of entry found or -1 if the key does not exist. If retInsIdx != NULL, the index to insert a new item is return in *retInsIdx.
 
void PrefixSearch (const char *key, int *retIdx0, int *retIdx1)
 Determine all elements with keys starting with key. More...
 
virtual void Dump (const char *name)
 Dump contents by means of INFO logs (for debugging)
 
- Public Member Functions inherited from CListRaw
int Entries () const
 Get number of entries.
 
void Clear ()
 Clear the list.
 
void Del (int idx)
 Delete entry; complexity is O(n).
 

Member Function Documentation

◆ Set()

template<typename T >
int CDict< T >::Set ( const char *  key,
T *  value 
)
inline

Add or replace the keyed entry. Complexity is O(n).

Returns
Index of new entry

Definition at line 1212 of file base.H.

◆ SetValue()

template<typename T >
void CDict< T >::SetValue ( int  idx,
T *  value 
)
inline

Set (replace) a value.

Parameters
idxis the index.
valuemust be a dynamically allocated object or 'NULL'. The dictionary will take over ownership and call 'delete' on it later. The entry must exist and 'idx' be valid. Complexity is O(1).

Definition at line 1215 of file base.H.

◆ Merge()

template<typename T >
void CDict< T >::Merge ( CDict< T > *  dict2)
inline

Merge another dictionary into this one. Complexity is O(n_this + n_dict2). 'dict2' will be empty afterwards.

The recommended way to add a bunch of new entries to a dictionary is to first add them to a new dictionary and then use this method to merge them into 'this'.

Definition at line 1226 of file base.H.


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