21 #ifndef _cvc3__include__cdmap_h_
22 #define _cvc3__include__cdmap_h_
46 template <
class Key,
class Data,
class HashFcn = std::hash<Key> >
class CDMap;
48 template <
class Key,
class Data,
class HashFcn = std::hash<Key> >
71 if(d_cdmap->
d_map.count(d_key) > 0) {
72 d_cdmap->
d_map.erase(d_key);
73 d_cdmap->
d_trash.push_back(
this);
87 const Key& key,
const Data& data,
int scope = -1)
88 :
ContextObj(context), d_key(key), d_inMap(false), d_cdmap(cdmap) {
93 first = d_next = d_prev =
this;
98 d_prev->
d_next = first->d_prev =
this;
102 void set(
const Data& data,
int scope=-1) {
106 const Data&
get()
const {
return d_data; }
107 operator Data() {
return get(); }
110 if (d_next == d_cdmap->
d_first)
return NULL;
127 template <
class Key,
class Data,
class HashFcn>
128 class CDMap:
public ContextObj {
133 std::vector<CDOmap<Key, Data, HashFcn>*>
d_trash;
146 i=d_trash.begin(), iend=d_trash.end(); i!=iend; ++i) {
166 :
ContextObj(context), d_first(NULL), d_context(context) {
181 if(i == d_map.
end()) {
190 void insert(
const Key& k,
const Data& d,
int scope = -1) {
193 if(i == d_map.
end()) {
198 (*i).second->
set(d, scope);
205 class iterator :
public std::iterator<std::input_iterator_tag,std::pair<const Key, Data>,std::ptrdiff_t> {
219 return d_it == i.
d_it;
222 return d_it != i.
d_it;
226 const std::pair<const Key, CDOmap<Key, Data, HashFcn>*>& p(*d_it);
227 return std::pair<const Key, Data>(p.first, *p.second);
241 const std::pair<const Key, Data>*
d_pair;
243 Proxy(
const std::pair<const Key, Data>& p): d_pair(&p) { }
258 iterator
end()
const {
return iterator(d_map.
end()); }
269 return d_it == i.
d_it;
272 return d_it != i.
d_it;
276 return std::pair<const Key, Data>(d_it->
getKey(), d_it->
get());
284 const std::pair<const Key, Data>*
d_pair;
286 Proxy(
const std::pair<const Key, Data>& p): d_pair(&p) { }
300 orderedIterator
orderedBegin()
const {
return orderedIterator(d_first); }
301 orderedIterator
orderedEnd()
const {
return orderedIterator(NULL); }
303 iterator
find(
const Key& k)
const {
return iterator(d_map.
find(k)); }
CDOmap< Key, Data, HashFcn > & ElementReference
CDOmap< Key, Data, HashFcn > * d_first
std::pair< const Key, Data > operator*() const
size_type count(const _Key &key) const
orderedIterator orderedBegin() const
std::hash_map< Key, CDOmap< Key, Data, HashFcn > *, HashFcn >::const_iterator d_it
bool operator!=(const orderedIterator &i) const
virtual void setNull(void)
Set the current object to be invalid.
void set(const Data &data, int scope=-1)
void insert(const Key &k, const Data &d, int scope=-1)
void makeCurrent(int scope=-1)
std::pair< const Key, Data > operator*() const
bool operator!=(const iterator &i) const
const CDOmap< Key, Data, HashFcn > * d_it
virtual void restoreData(ContextObj *data)
Restore the current object from the given data.
const Key & getKey() const
virtual void setNull(void)
Set the current object to be invalid.
virtual ContextObj * makeCopy(ContextMemoryManager *cmm)
Make a copy of the current object so it can be restored to its current state.
iterator find(const key_type &key)
operations
std::vector< CDOmap< Key, Data, HashFcn > * > d_trash
CDMapData(const ContextObj &co)
CDOmap< Key, Data, HashFcn > * d_next
const std::pair< const Key, Data > * d_pair
iterator begin()
iterators
void setNull(void)
Set the current object to be invalid.
CDMapData(Context *context)
virtual void restoreData(ContextObj *data)
Restore the current object from the given data.
CDMap< Key, Data, HashFcn > * d_cdmap
CDOmap< Key, Data, HashFcn > & operator[](const Key &k)
Proxy(const std::pair< const Key, Data > &p)
orderedIterator & operator++()
virtual ContextObj * makeCopy(ContextMemoryManager *cmm)
Make a copy of the current object so it can be restored to its current state.
bool operator==(const iterator &i) const
orderedIterator(const CDOmap< Key, Data, HashFcn > *p)
size_t count(const Key &k) const
CDMap(Context *context, int scope=-1)
CDOmap< Key, Data, HashFcn > * next() const
bool operator==(const orderedIterator &i) const
iterator(const iterator &i)
std::hash_map< Key, CDOmap< Key, Data, HashFcn > *, HashFcn > d_map
CDOmap< Key, Data, HashFcn > & operator=(const Data &data)
iterator find(const Key &k) const
std::pair< const Key, Data > & operator*()
std::pair< const Key, Data > & operator*()
CDOmap< Key, Data, HashFcn > * d_prev
const std::pair< const Key, Data > * d_pair
orderedIterator(const orderedIterator &i)
iterator(const typename std::hash_map< Key, CDOmap< Key, Data, HashFcn > *, HashFcn >::const_iterator &i)
void restoreData(ContextObj *data)
Restore the current object from the given data.
ContextObj * makeCopy(ContextMemoryManager *cmm)
Make a copy of the current object so it can be restored to its current state.
CDOmap(Context *context, CDMap< Key, Data, HashFcn > *cdmap, const Key &key, const Data &data, int scope=-1)
Proxy(const std::pair< const Key, Data > &p)
orderedIterator orderedEnd() const