#include <HxNameTable.h>
Inheritance diagram for HxNameTable::
Public Types | |
typedef size_t | sizeType |
The type of the Id's. More... | |
Public Methods | |
HxNameTable () | |
Constructor. More... | |
virtual | ~HxNameTable () |
Destructor. More... | |
void | insert (HxString name, sizeType id) |
Insert name,id combination. More... | |
sizeType | getId (HxString name) |
Get the id for this name. More... | |
HxString | getName (sizeType id) const |
Get the name for this id. More... | |
std::vector< HxString > | getNames () const |
Get all names in the table. More... | |
std::ostream & | put (std::ostream &) const |
Put the table on the stream. More... |
A name table is used to maintain a list of name,id combinations. The id's are unique.
|
The type of the Id's.
|
|
Constructor.
00015 { 00016 } |
|
Destructor.
00019 { 00020 } |
|
Insert name,id combination.
00024 { 00025 Map::iterator ptr; 00026 HxString oldName(""); 00027 00028 if (i >= _index.size()) { 00029 _index.insert(_index.end(), i-_index.size()+1, HxString("")); 00030 } 00031 00032 oldName = _index[i]; 00033 if ((!oldName.empty()) && (oldName != name)) { 00034 ptr = _map.find(oldName); 00035 if (ptr != _map.end()) { 00036 _map.erase(ptr); 00037 } 00038 } 00039 00040 if ((ptr = _map.find(name)) != _map.end()) { 00041 _index[(*ptr).second] = ""; 00042 } 00043 00044 _map[name] = i; 00045 _index[i] = name; 00046 } |
|
Get the id for this name.
00050 { 00051 Map::iterator ptr = _map.find(name); 00052 if (ptr != _map.end()) { 00053 return (*ptr).second; 00054 } else { 00055 _index.push_back(name); 00056 _map.insert(Entry(name, _index.size()-1)); 00057 return _index.size()-1; 00058 } 00059 } |
|
Get the name for this id.
00063 { 00064 return id < _index.size() ? _index[id] : HxString(""); 00065 } |
|
Get all names in the table.
00069 { 00070 return _index; 00071 } |
|
Put the table on the stream.
00075 { 00076 Map::const_iterator mapPtr; 00077 Index::const_iterator idxPtr; 00078 sizeType i; 00079 00080 os << "MAP" << STD_ENDL; 00081 for (mapPtr = _map.begin(); mapPtr != _map.end(); ++mapPtr) { 00082 os << (*mapPtr).first << " " << (*mapPtr).second << STD_ENDL; 00083 } 00084 os << "INDEX" << STD_ENDL; 00085 for (i=0, idxPtr = _index.begin(); idxPtr != _index.end(); ++i, ++idxPtr) { 00086 os << i << " " << *idxPtr << STD_ENDL; 00087 } 00088 00089 return os; 00090 } |