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