21 #ifndef _cvc3__include__cdmap_ordered_h_
22 #define _cvc3__include__cdmap_ordered_h_
47 template <
class Key,
class Data>
70 if(d_cdmap->
d_map.count(d_key) > 0) {
71 d_cdmap->
d_map.erase(d_key);
72 d_cdmap->
d_trash.push_back(
this);
86 const Key& key,
const Data& data,
int scope = -1)
88 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>
128 class CDMapOrdered:
public ContextObj {
131 std::map<Key,CDOmapOrdered<Key,Data>*>
d_map;
133 std::vector<CDOmapOrdered<Key,Data>*>
d_trash;
146 i=d_trash.begin(), iend=d_trash.end(); i!=iend; ++i)
154 i=d_map.begin(), iend=d_map.end();
155 i!=iend; ++i)
delete (*i).second;
161 :
ContextObj(context), d_first(NULL), d_context(context) {
162 IF_DEBUG(setName(
"CDMapOrdered")); ;
166 size_t size()
const {
return d_map.size(); }
167 size_t count(
const Key& k)
const {
return d_map.count(k); }
172 typename std::map<Key,CDOmapOrdered<Key,Data>*>
::iterator i(d_map.find(k));
174 if(i == d_map.end()) {
183 void insert(
const Key& k,
const Data& d,
int scope = -1) {
185 typename std::map<Key,CDOmapOrdered<Key,Data>*>
::iterator i(d_map.find(k));
186 if(i == d_map.end()) {
191 (*i).second->
set(d, scope);
198 class iterator :
public std::iterator<std::input_iterator_tag,std::pair<const Key, Data>,std::ptrdiff_t> {
201 typename std::map<Key,CDOmapOrdered<Key,Data>*>::const_iterator
d_it;
212 return d_it == i.
d_it;
215 return d_it != i.
d_it;
219 const std::pair<const Key, CDOmapOrdered<Key,Data>*>& p(*d_it);
220 return std::pair<const Key, Data>(p.first, *p.second);
234 const std::pair<const Key, Data>*
d_pair;
236 Proxy(
const std::pair<const Key, Data>& p): d_pair(&p) { }
262 return d_it == i.
d_it;
265 return d_it != i.
d_it;
269 return std::pair<const Key, Data>(d_it->
getKey(), d_it->
get());
277 const std::pair<const Key, Data>*
d_pair;
279 Proxy(
const std::pair<const Key, Data>& p): d_pair(&p) { }
iterator find(const Key &k) const
const std::pair< const Key, Data > * d_pair
bool operator==(const iterator &i) const
virtual void restoreData(ContextObj *data)
Restore the current object from the given data.
CDMapOrderedData(Context *context)
orderedIterator orderedEnd() const
void insert(const Key &k, const Data &d, int scope=-1)
CDMapOrdered(Context *context, int scope=-1)
CDMapOrderedData(const ContextObj &co)
size_t count(const Key &k) const
std::pair< const Key, Data > & operator*()
std::pair< const Key, Data > & operator*()
virtual void setNull(void)
Set the current object to be invalid.
virtual void restoreData(ContextObj *data)
Restore the current object from the given data.
void makeCurrent(int scope=-1)
CDOmapOrdered< Key, Data > * next() const
orderedIterator orderedBegin() const
std::map< Key, CDOmapOrdered< Key, Data > * > d_map
orderedIterator(const CDOmapOrdered< Key, Data > *p)
orderedIterator & operator++()
std::vector< CDOmapOrdered< Key, Data > * > d_trash
Proxy(const std::pair< const Key, Data > &p)
const std::pair< const Key, Data > * d_pair
void setNull(void)
Set the current object to be invalid.
Proxy(const std::pair< const Key, Data > &p)
iterator(const iterator &i)
CDOmapOrdered(Context *context, CDMapOrdered< Key, Data > *cdmap, const Key &key, const Data &data, int scope=-1)
const Key & getKey() const
virtual ContextObj * makeCopy(ContextMemoryManager *cmm)
Make a copy of the current object so it can be restored to its current state.
std::map< Key, CDOmapOrdered< Key, Data > * >::const_iterator d_it
CDOmapOrdered< Key, Data > & operator[](const Key &k)
virtual ContextObj * makeCopy(ContextMemoryManager *cmm)
Make a copy of the current object so it can be restored to its current state.
std::pair< const Key, Data > operator*() const
bool operator!=(const iterator &i) const
CDOmapOrdered< Key, Data > * d_next
virtual void setNull(void)
Set the current object to be invalid.
ContextObj * makeCopy(ContextMemoryManager *cmm)
Make a copy of the current object so it can be restored to its current state.
bool operator!=(const orderedIterator &i) const
CDOmapOrdered< Key, Data > & operator=(const Data &data)
void restoreData(ContextObj *data)
Restore the current object from the given data.
void set(const Data &data, int scope=-1)
iterator(const typename std::map< Key, CDOmapOrdered< Key, Data > * >::const_iterator &i)
CDMapOrdered< Key, Data > * d_cdmap
bool operator==(const orderedIterator &i) const
CDOmapOrdered< Key, Data > * d_prev
std::pair< const Key, Data > operator*() const
orderedIterator(const orderedIterator &i)
CDOmapOrdered< Key, Data > * d_first
const CDOmapOrdered< Key, Data > * d_it