1 | /*
|
---|
2 | * AtomSet.hpp
|
---|
3 | *
|
---|
4 | * Created on: Jul 8, 2010
|
---|
5 | * Author: crueger
|
---|
6 | */
|
---|
7 |
|
---|
8 | #ifndef OBSERVEDCONTAINER_HPP_
|
---|
9 | #define OBSERVEDCONTAINER_HPP_
|
---|
10 |
|
---|
11 | #include "types.hpp"
|
---|
12 |
|
---|
13 | #include <utility>
|
---|
14 | #include "Patterns/ObservedIterator.hpp"
|
---|
15 | #include "Descriptors/SelectiveIterator.hpp"
|
---|
16 |
|
---|
17 | class World;
|
---|
18 | class atom;
|
---|
19 | class AtomDescriptor;
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * Forward to std::map<atomId_t,atom*> that allows production of observed and
|
---|
23 | * unobserved iterators to all atoms.
|
---|
24 | *
|
---|
25 | * Imported via typedef into class World. Defined here to avoid bloating of the
|
---|
26 | * World class
|
---|
27 | */
|
---|
28 | template <class Container>
|
---|
29 | class ObservedContainer
|
---|
30 | {
|
---|
31 | friend class World;
|
---|
32 |
|
---|
33 | public:
|
---|
34 | typedef Container set_t;
|
---|
35 | // this iterator can be used for internal purposes...
|
---|
36 | // no lock used here
|
---|
37 | typedef typename set_t::iterator internal_iterator;
|
---|
38 | typedef typename std::reverse_iterator<internal_iterator> reverse_internal_iterator;
|
---|
39 |
|
---|
40 | // typedefs for iterator structure
|
---|
41 | typedef ObservedIterator<set_t> iterator;
|
---|
42 | typedef typename set_t::const_iterator const_iterator;
|
---|
43 | typedef std::reverse_iterator<iterator> reverse_iterator;
|
---|
44 | typedef typename std::reverse_iterator<const_iterator> const_reverse_iterator;
|
---|
45 |
|
---|
46 | // some more typedefs for STL-Structure
|
---|
47 | typedef typename set_t::key_type key_type;
|
---|
48 | typedef typename set_t::mapped_type mapped_type;
|
---|
49 | typedef typename set_t::value_type value_type;
|
---|
50 | typedef typename set_t::key_compare key_compare;
|
---|
51 | typedef typename set_t::allocator_type allocator_type;
|
---|
52 |
|
---|
53 | ObservedContainer(Observable*);
|
---|
54 | ObservedContainer(const ObservedContainer&);
|
---|
55 | virtual ~ObservedContainer();
|
---|
56 |
|
---|
57 | // all the functions from STL-map (forwards to content)
|
---|
58 | ObservedContainer& operator=(const ObservedContainer&);
|
---|
59 |
|
---|
60 | iterator begin();
|
---|
61 | const_iterator begin() const;
|
---|
62 | iterator end();
|
---|
63 | const_iterator end() const;
|
---|
64 | reverse_iterator rbegin();
|
---|
65 | const_reverse_iterator rbegin() const;
|
---|
66 | reverse_iterator rend();
|
---|
67 | const_reverse_iterator rend() const;
|
---|
68 |
|
---|
69 | bool empty() const;
|
---|
70 | size_t size() const;
|
---|
71 | size_t max_size() const;
|
---|
72 |
|
---|
73 | mapped_type &operator[](const key_type&);
|
---|
74 |
|
---|
75 | std::pair<iterator,bool> insert (const value_type&);
|
---|
76 |
|
---|
77 | size_t erase ( const key_type& x );
|
---|
78 | void clear();
|
---|
79 |
|
---|
80 | iterator find ( const key_type& x );
|
---|
81 | const_iterator find ( const key_type& x ) const;
|
---|
82 |
|
---|
83 | size_t count ( const key_type& x ) const;
|
---|
84 | internal_iterator begin_internal();
|
---|
85 | internal_iterator end_internal();
|
---|
86 | reverse_internal_iterator rbegin_internal();
|
---|
87 | reverse_internal_iterator rend_internal();
|
---|
88 |
|
---|
89 | set_t &getContent();
|
---|
90 | private:
|
---|
91 | set_t content;
|
---|
92 | Observable *obs;
|
---|
93 | };
|
---|
94 |
|
---|
95 | #endif /* OBSERVEDCONTAINER_HPP_ */
|
---|