torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
torc::generic::SymTab< _KeyType, _ValueType, cOverWriteExisting > Class Template Reference

A symbol table. More...

#include <SymTab.hpp>

Data Structures

struct  Data
 

Public Types

typedef _KeyType KeyType
 
typedef _ValueType ValueType
 
typedef std::map< KeyType, DataMap
 
typedef std::map< KeyType,
ValueType
UserMap
 

Public Member Functions

 SymTab ()
 
 ~SymTab () throw ()
 
bool get (const KeyType &inKey, ValueType &outValue) const
 
bool set (const KeyType &inKey, const ValueType &inValue)
 
bool remove (const KeyType &inKey)
 
void getValues (std::vector< ValueType > &outValues) const
 
void getValueMap (UserMap &outMap) const
 
size_t getSize () const
 
void clear ()
 
template<typename _Action >
void applyOnAll (const _Action &action) throw (Error)
 

Private Attributes

Map mValues
 
size_t mNextValue
 

Detailed Description

template<typename _KeyType, typename _ValueType, bool cOverWriteExisting = false>
class torc::generic::SymTab< _KeyType, _ValueType, cOverWriteExisting >

A symbol table.

This class acts as a symbol table to store key-value pairs

Definition at line 38 of file SymTab.hpp.

Member Typedef Documentation

template<typename _KeyType, typename _ValueType, bool cOverWriteExisting = false>
typedef _KeyType torc::generic::SymTab< _KeyType, _ValueType, cOverWriteExisting >::KeyType

Definition at line 62 of file SymTab.hpp.

template<typename _KeyType, typename _ValueType, bool cOverWriteExisting = false>
typedef std::map<KeyType, Data> torc::generic::SymTab< _KeyType, _ValueType, cOverWriteExisting >::Map

Definition at line 64 of file SymTab.hpp.

template<typename _KeyType, typename _ValueType, bool cOverWriteExisting = false>
typedef std::map<KeyType, ValueType> torc::generic::SymTab< _KeyType, _ValueType, cOverWriteExisting >::UserMap

Definition at line 65 of file SymTab.hpp.

template<typename _KeyType, typename _ValueType, bool cOverWriteExisting = false>
typedef _ValueType torc::generic::SymTab< _KeyType, _ValueType, cOverWriteExisting >::ValueType

Definition at line 63 of file SymTab.hpp.

Constructor & Destructor Documentation

template<typename _KeyType , typename _ValueType , bool cOverWriteExisting>
torc::generic::SymTab< _KeyType, _ValueType, cOverWriteExisting >::SymTab ( )

Definition at line 114 of file SymTab.hpp.

114  :
115  mValues(), mNextValue(0) {}
template<typename _KeyType , typename _ValueType , bool cOverWriteExisting>
torc::generic::SymTab< _KeyType, _ValueType, cOverWriteExisting >::~SymTab ( )
throw (
)

Definition at line 118 of file SymTab.hpp.

118 {}

Member Function Documentation

template<typename _KeyType , typename _ValueType , bool cOverWriteExisting>
template<typename _Action >
void torc::generic::SymTab< _KeyType, _ValueType, cOverWriteExisting >::applyOnAll ( const _Action &  action)
throw (Error
)
inline

Definition at line 192 of file SymTab.hpp.

193  {
194  std::vector<Data> values;
195  for(typename Map::const_iterator it = mValues.begin(); it != mValues.end(); ++it) {
196  values.push_back((*it).second);
197  }
198  sort(values.begin(), values.end(), std::less<Data>());
199  for(typename std::vector<Data>::iterator value = values.begin(); value != values.end();
200  ++value) {
201  try {
202  action((*value).mValue);
203  } catch(Error& e) {
204  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
205  throw;
206  }
207  }
208 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename _KeyType , typename _ValueType , bool cOverWriteExisting>
void torc::generic::SymTab< _KeyType, _ValueType, cOverWriteExisting >::clear ( void  )
inline

Definition at line 187 of file SymTab.hpp.

187  {
188  mValues.clear();
189 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename _KeyType , typename _ValueType , bool cOverWriteExisting>
bool torc::generic::SymTab< _KeyType, _ValueType, cOverWriteExisting >::get ( const KeyType inKey,
ValueType outValue 
) const
inline

Get a value for a key

Parameters
[in]inKeykey to look for
[out]outValueresultant value
Returns
true if object was found

Definition at line 121 of file SymTab.hpp.

122  {
123  typename Map::const_iterator it = mValues.find(inKey);
124  if(it == mValues.end()) {
125  return false;
126  }
127  outValue = (*it).second.mValue;
128  return true;
129 }

+ Here is the caller graph for this function:

template<typename _KeyType , typename _ValueType , bool cOverWriteExisting>
size_t torc::generic::SymTab< _KeyType, _ValueType, cOverWriteExisting >::getSize ( void  ) const
inline

Definition at line 182 of file SymTab.hpp.

182  {
183  return mValues.size();
184 }
template<typename _KeyType, typename _ValueType, bool cOverWriteExisting = false>
void torc::generic::SymTab< _KeyType, _ValueType, cOverWriteExisting >::getValueMap ( UserMap outMap) const
inline

Definition at line 171 of file SymTab.hpp.

172  {
173 
174  for(typename Map::const_iterator it = mValues.begin(); it != mValues.end(); ++it) {
175  typename UserMap::value_type value = std::make_pair((*it).first, (*it).second.mValue);
176  outMap.insert(value);
177  }
178  return;
179 }

+ Here is the caller graph for this function:

template<typename _KeyType , typename _ValueType , bool cOverWriteExisting>
void torc::generic::SymTab< _KeyType, _ValueType, cOverWriteExisting >::getValues ( std::vector< ValueType > &  outValues) const
inline

Definition at line 158 of file SymTab.hpp.

158  {
159  std::vector<Data> values;
160  for(typename Map::const_iterator it = mValues.begin(); it != mValues.end(); ++it) {
161  values.push_back((*it).second);
162  }
163  sort(values.begin(), values.end(), std::less<Data>());
164  for(typename std::vector<Data>::iterator it = values.begin(); it != values.end(); ++it) {
165  outValues.push_back((*it).mValue);
166  }
167  return;
168 }

+ Here is the caller graph for this function:

template<typename _KeyType , typename _ValueType , bool cOverWriteExisting>
bool torc::generic::SymTab< _KeyType, _ValueType, cOverWriteExisting >::remove ( const KeyType inKey)
inline

Remove a value for a key

Parameters
[in]inKeykey to look for
Returns
true if object was removed

Definition at line 153 of file SymTab.hpp.

153  {
154  return mValues.erase(inKey) > 0;
155 }

+ Here is the caller graph for this function:

template<typename _KeyType , typename _ValueType , bool cOverWriteExisting>
bool torc::generic::SymTab< _KeyType, _ValueType, cOverWriteExisting >::set ( const KeyType inKey,
const ValueType inValue 
)
inline

Set a value for a key. If cOverWriteExisting is true, Existing value will be replaced.

Parameters
[in]inKeykey to look for
[in]inValuevalue to be stored
Returns
True if value was inserted

Definition at line 132 of file SymTab.hpp.

132  {
133  Data data;
134  data.mIndex = mNextValue;
135  data.mValue = inValue;
136  mNextValue++;
137  typename Map::value_type value = std::make_pair(inKey, data);
138 
139  std::pair<typename Map::iterator, bool> res = mValues.insert(value);
140  if(false == res.second) {
141  if(cOverWriteExisting) {
142  mValues.erase(res.first);
143  mValues.insert(value);
144  } else {
145  mNextValue--;
146  return false;
147  }
148  }
149  return true;
150 }

+ Here is the caller graph for this function:

Field Documentation

template<typename _KeyType, typename _ValueType, bool cOverWriteExisting = false>
size_t torc::generic::SymTab< _KeyType, _ValueType, cOverWriteExisting >::mNextValue
private

Definition at line 110 of file SymTab.hpp.

template<typename _KeyType, typename _ValueType, bool cOverWriteExisting = false>
Map torc::generic::SymTab< _KeyType, _ValueType, cOverWriteExisting >::mValues
private

Definition at line 108 of file SymTab.hpp.


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