| 1 | /* | 
|---|
| 2 | * AtomIdSet.hpp | 
|---|
| 3 | * | 
|---|
| 4 | *  Created on: Feb 21, 2012 | 
|---|
| 5 | *      Author: heber | 
|---|
| 6 | */ | 
|---|
| 7 |  | 
|---|
| 8 | #ifndef ATOMIDSET_HPP_ | 
|---|
| 9 | #define ATOMIDSET_HPP_ | 
|---|
| 10 |  | 
|---|
| 11 |  | 
|---|
| 12 | // include config.h | 
|---|
| 13 | #ifdef HAVE_CONFIG_H | 
|---|
| 14 | #include <config.h> | 
|---|
| 15 | #endif | 
|---|
| 16 |  | 
|---|
| 17 | #include <boost/iterator/transform_iterator.hpp> | 
|---|
| 18 |  | 
|---|
| 19 | #include <set> | 
|---|
| 20 | #include <vector> | 
|---|
| 21 |  | 
|---|
| 22 | #include "types.hpp" | 
|---|
| 23 |  | 
|---|
| 24 | class atom; | 
|---|
| 25 | struct FromIdToAtom : | 
|---|
| 26 | public std::unary_function<atom *, atomId_t> | 
|---|
| 27 | { | 
|---|
| 28 | atom * operator()(atomId_t id) const; | 
|---|
| 29 | }; | 
|---|
| 30 |  | 
|---|
| 31 | /** AtomIdSet is a set of atomic ids that however behave as a set of atoms. | 
|---|
| 32 | * | 
|---|
| 33 | * This class represents an iterable set of atoms that is however only stored as | 
|---|
| 34 | * ids internally. | 
|---|
| 35 | */ | 
|---|
| 36 | class AtomIdSet | 
|---|
| 37 | { | 
|---|
| 38 | public: | 
|---|
| 39 | typedef std::set<atomId_t> atomIdSet; | 
|---|
| 40 | typedef boost::transform_iterator<FromIdToAtom, atomIdSet::iterator, atom *, atomId_t> iterator; | 
|---|
| 41 | typedef boost::transform_iterator<FromIdToAtom, atomIdSet::const_iterator, const atom *, atomId_t const &> const_iterator; | 
|---|
| 42 |  | 
|---|
| 43 | AtomIdSet(const atomIdSet &_atoms); | 
|---|
| 44 | AtomIdSet(const std::vector<atom *> &_atoms); | 
|---|
| 45 | AtomIdSet(); | 
|---|
| 46 | ~AtomIdSet(); | 
|---|
| 47 |  | 
|---|
| 48 | iterator begin(); | 
|---|
| 49 | const_iterator begin() const; | 
|---|
| 50 | iterator end(); | 
|---|
| 51 | const_iterator end() const; | 
|---|
| 52 | bool empty() const; | 
|---|
| 53 | size_t size() const; | 
|---|
| 54 | bool contains(const atom * const key) const; | 
|---|
| 55 | bool contains(const atomId_t &id) const; | 
|---|
| 56 | const_iterator find(const atom * const key) const; | 
|---|
| 57 | const_iterator find(const atomId_t &id) const; | 
|---|
| 58 | std::pair<iterator, bool> insert(const atom * const key); | 
|---|
| 59 | std::pair<iterator, bool> insert(const atomId_t &id); | 
|---|
| 60 | const_iterator erase(const_iterator &loc); | 
|---|
| 61 | const_iterator erase(const atom * const key); | 
|---|
| 62 | const_iterator erase(const atomId_t &id); | 
|---|
| 63 |  | 
|---|
| 64 | /** Getter for internal set of atoms. | 
|---|
| 65 | * | 
|---|
| 66 | * @return set of atomic ids | 
|---|
| 67 | */ | 
|---|
| 68 | const atomIdSet & getAtomIds() const { | 
|---|
| 69 | return atoms; | 
|---|
| 70 | } | 
|---|
| 71 |  | 
|---|
| 72 | private: | 
|---|
| 73 | //!> internal atoms stored by their ids | 
|---|
| 74 | atomIdSet atoms; | 
|---|
| 75 | }; | 
|---|
| 76 |  | 
|---|
| 77 |  | 
|---|
| 78 | #endif /* ATOMIDSET_HPP_ */ | 
|---|