16 #ifndef TORC_GENERIC_SYMTAB_HPP
17 #define TORC_GENERIC_SYMTAB_HPP
23 #ifdef GENOM_SERIALIZATION
24 #include <boost/serialization/access.hpp>
25 #include <boost/serialization/map.hpp>
26 #endif //GENOM_SERIALIZATION
38 template <
typename _KeyType,
typename _ValueType,
bool cOverWriteExisting = false>
class SymTab {
39 #ifdef GENOM_SERIALIZATION
40 friend class boost::serialization::access;
44 #ifdef GENOM_SERIALIZATION
45 friend class boost::serialization::access;
54 #ifdef GENOM_SERIALIZATION
55 template <
class Archive>
void serialize(Archive& ar,
unsigned int) {
59 #endif //GENOM_SERIALIZATION
64 typedef std::map<KeyType, Data>
Map;
65 typedef std::map<KeyType, ValueType>
UserMap;
102 template <typename _Action>
void applyOnAll(const _Action& action) throw (
Error);
105 #ifdef GENOM_SERIALIZATION
106 template <
class Archive>
void serialize(Archive& ar,
unsigned int);
107 #endif //GENOM_SERIALIZATION
113 template <
typename _KeyType,
typename _ValueType,
bool cOverWriteExisting>
115 mValues(), mNextValue(0) {}
117 template <
typename _KeyType,
typename _ValueType,
bool cOverWriteExisting>
120 template <
typename _KeyType,
typename _ValueType,
bool cOverWriteExisting>
inline bool SymTab<
121 _KeyType, _ValueType, cOverWriteExisting>::get(
const KeyType& inKey,
123 typename Map::const_iterator it = mValues.find(inKey);
124 if(it == mValues.end()) {
127 outValue = (*it).second.mValue;
131 template <
typename _KeyType,
typename _ValueType,
bool cOverWriteExisting>
inline bool SymTab<
132 _KeyType, _ValueType, cOverWriteExisting>::set(
const KeyType& inKey,
const ValueType& inValue) {
137 typename Map::value_type value = std::make_pair(inKey, data);
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);
152 template <
typename _KeyType,
typename _ValueType,
bool cOverWriteExisting>
inline bool SymTab<
153 _KeyType, _ValueType, cOverWriteExisting>::remove(
const KeyType& inKey) {
154 return mValues.erase(inKey) > 0;
157 template <
typename _KeyType,
typename _ValueType,
bool cOverWriteExisting>
inline void SymTab<
158 _KeyType, _ValueType, cOverWriteExisting>::getValues(std::vector<ValueType>& outValues)
const {
159 std::vector<Data> values;
160 for(
typename Map::const_iterator it = mValues.begin(); it != mValues.end(); ++it) {
161 values.push_back((*it).second);
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);
170 template <
typename _KeyType,
typename _ValueType,
bool cOverWriteExisting>
inline void SymTab<
171 _KeyType, _ValueType, cOverWriteExisting>::getValueMap(
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);
181 template <
typename _KeyType,
typename _ValueType,
bool cOverWriteExisting>
inline size_t SymTab<
182 _KeyType, _ValueType, cOverWriteExisting>::getSize()
const {
183 return mValues.size();
186 template <
typename _KeyType,
typename _ValueType,
bool cOverWriteExisting>
inline void SymTab<
187 _KeyType, _ValueType, cOverWriteExisting>::clear() {
191 template <
typename _KeyType,
typename _ValueType,
bool cOverWriteExisting>
template <
193 const _Action& action)
throw (
Error) {
194 std::vector<Data> values;
195 for(
typename Map::const_iterator it = mValues.begin(); it != mValues.end(); ++it) {
196 values.push_back((*it).second);
198 sort(values.begin(), values.end(), std::less<Data>());
199 for(
typename std::vector<Data>::iterator value = values.begin(); value != values.end();
202 action((*value).mValue);
210 #ifdef GENOM_SERIALIZATION
211 template <
typename _KeyType,
typename _ValueType,
bool cOverWriteExisting>
template <
class Archive>
215 #endif //GENOM_SERIALIZATION
220 #endif // TORC_GENERIC_SYMTAB_HPP
void getValues(std::vector< ValueType > &outValues) const
bool set(const KeyType &inKey, const ValueType &inValue)
void applyOnAll(const _Action &action)
bool remove(const KeyType &inKey)
The Error object thrown by different methods of EdifOM.
bool get(const KeyType &inKey, ValueType &outValue) const
bool operator<(const Data &inRhs) const
void getValueMap(UserMap &outMap) const
std::map< KeyType, Data > Map
std::map< KeyType, ValueType > UserMap
void setCurrentLocation(const std::string &inFunction, const std::string &inFile, uint32_t inLine)