| 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 KeySet;
 | 
|---|
| 25 | 
 | 
|---|
| 26 | class atom;
 | 
|---|
| 27 | struct FromIdToAtom :
 | 
|---|
| 28 |   public std::unary_function<atom *, atomId_t>
 | 
|---|
| 29 | {
 | 
|---|
| 30 |     atom * operator()(atomId_t id) const;
 | 
|---|
| 31 | };
 | 
|---|
| 32 | 
 | 
|---|
| 33 | /** AtomIdSet is a set of atomic ids that however behave as a set of atoms.
 | 
|---|
| 34 |  *
 | 
|---|
| 35 |  * This class represents an iterable set of atoms that is however only stored as
 | 
|---|
| 36 |  * ids internally.
 | 
|---|
| 37 |  */
 | 
|---|
| 38 | class AtomIdSet
 | 
|---|
| 39 | {
 | 
|---|
| 40 | public:
 | 
|---|
| 41 |   typedef std::set<atomId_t> atomIdSet;
 | 
|---|
| 42 |   typedef boost::transform_iterator<FromIdToAtom, atomIdSet::iterator, atom *, atomId_t> iterator;
 | 
|---|
| 43 |   typedef boost::transform_iterator<FromIdToAtom, atomIdSet::const_iterator, const atom *, atomId_t const &> const_iterator;
 | 
|---|
| 44 | 
 | 
|---|
| 45 |   AtomIdSet(const atomIdSet &_atoms);
 | 
|---|
| 46 |   AtomIdSet(const KeySet &_keysets);
 | 
|---|
| 47 |   AtomIdSet(const std::vector<atom *> &_atoms);
 | 
|---|
| 48 |   AtomIdSet();
 | 
|---|
| 49 |   ~AtomIdSet();
 | 
|---|
| 50 | 
 | 
|---|
| 51 |   iterator begin();
 | 
|---|
| 52 |   const_iterator begin() const;
 | 
|---|
| 53 |   iterator end();
 | 
|---|
| 54 |   const_iterator end() const;
 | 
|---|
| 55 |   bool empty() const;
 | 
|---|
| 56 |   size_t size() const;
 | 
|---|
| 57 |   bool contains(const atom * const key) const;
 | 
|---|
| 58 |   bool contains(const atomId_t &id) const;
 | 
|---|
| 59 |   const_iterator find(const atom * const key) const;
 | 
|---|
| 60 |   const_iterator find(const atomId_t &id) const;
 | 
|---|
| 61 |   std::pair<iterator, bool> insert(const atom * const key);
 | 
|---|
| 62 |   std::pair<iterator, bool> insert(const atomId_t &id);
 | 
|---|
| 63 |   const_iterator erase(const_iterator &loc);
 | 
|---|
| 64 |   const_iterator erase(const atom * const key);
 | 
|---|
| 65 |   const_iterator erase(const atomId_t &id);
 | 
|---|
| 66 | 
 | 
|---|
| 67 |   /** Getter for internal set of atoms.
 | 
|---|
| 68 |    *
 | 
|---|
| 69 |    * @return set of atomic ids
 | 
|---|
| 70 |    */
 | 
|---|
| 71 |   const atomIdSet & getAtomIds() const {
 | 
|---|
| 72 |     return atoms;
 | 
|---|
| 73 |   }
 | 
|---|
| 74 | 
 | 
|---|
| 75 | private:
 | 
|---|
| 76 |   //!> internal atoms stored by their ids
 | 
|---|
| 77 |   atomIdSet atoms;
 | 
|---|
| 78 | };
 | 
|---|
| 79 | 
 | 
|---|
| 80 | 
 | 
|---|
| 81 | #endif /* ATOMIDSET_HPP_ */
 | 
|---|