[fc1b24] | 1 | /*
|
---|
| 2 | * AtomDescriptor.hpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: Feb 5, 2010
|
---|
| 5 | * Author: crueger
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #ifndef ATOMDESCRIPTOR_HPP_
|
---|
| 9 | #define ATOMDESCRIPTOR_HPP_
|
---|
| 10 |
|
---|
[d1c5e2] | 11 |
|
---|
| 12 | #include <vector>
|
---|
| 13 | #include <map>
|
---|
| 14 | #include <boost/shared_ptr.hpp>
|
---|
[fc1b24] | 15 | #include "World.hpp"
|
---|
| 16 |
|
---|
[865a945] | 17 | class World;
|
---|
[fc1b24] | 18 | class atom;
|
---|
| 19 |
|
---|
[7a1ce5] | 20 | // internal implementation, allows assignment, copying etc
|
---|
| 21 | class AtomDescripter_impl;
|
---|
[fc1b24] | 22 |
|
---|
[dbb474] | 23 | /**
|
---|
| 24 | * An AtomDescriptor describes a Set of Atoms from the World. Can be used for any method that needs to work on
|
---|
| 25 | * a specific set of Atoms.
|
---|
| 26 | *
|
---|
| 27 | * This Class is implemented using the PIMPL-Idion, i.e. this class only contains an abstract structure
|
---|
| 28 | * that forwards any request to a wrapped pointer-to-implementation. This way operators and calculations
|
---|
| 29 | * on Descriptors are possible.
|
---|
| 30 | *
|
---|
| 31 | * Concrete Implementation Objects can be shared between multiple Wrappers, so make sure that
|
---|
| 32 | * any Implementation remainst constant during lifetime.
|
---|
| 33 | */
|
---|
[7a1ce5] | 34 | class AtomDescriptor {
|
---|
[865a945] | 35 | // close coupling to the world to allow access
|
---|
[7a1ce5] | 36 | friend atom* World::getAtom(AtomDescriptor descriptor);
|
---|
| 37 | friend std::vector<atom*> World::getAllAtoms(AtomDescriptor descriptor);
|
---|
[6e97e5] | 38 | template <class,class,class> friend class SelectiveIterator;
|
---|
[d1c5e2] | 39 |
|
---|
[7a1ce5] | 40 | friend AtomDescriptor operator&&(const AtomDescriptor &lhs, const AtomDescriptor &rhs);
|
---|
| 41 | friend AtomDescriptor operator||(const AtomDescriptor &lhs, const AtomDescriptor &rhs);
|
---|
| 42 | friend AtomDescriptor operator!(const AtomDescriptor &arg);
|
---|
[fc1b24] | 43 |
|
---|
| 44 | public:
|
---|
[dbb474] | 45 | typedef boost::shared_ptr<AtomDescriptor_impl> impl_ptr; //!< Allow easy changes of the pointer-to-implementation type
|
---|
[d1c5e2] | 46 |
|
---|
[7a1ce5] | 47 | AtomDescriptor(impl_ptr);
|
---|
[dbb474] | 48 |
|
---|
| 49 | /**
|
---|
| 50 | * Copy constructor.
|
---|
| 51 | * Takes the Implementation from the copied object and sets it's own pointer to link there.
|
---|
| 52 | * This way the actuall implementation object is shared between copy and original
|
---|
| 53 | */
|
---|
[7a1ce5] | 54 | AtomDescriptor(const AtomDescriptor&);
|
---|
| 55 | ~AtomDescriptor();
|
---|
[fc1b24] | 56 |
|
---|
[dbb474] | 57 | /**
|
---|
| 58 | * Assignment Operator.
|
---|
| 59 | *
|
---|
| 60 | * Implemented by setting the pointer to the new Implementation.
|
---|
| 61 | */
|
---|
[7a1ce5] | 62 | AtomDescriptor &operator=(AtomDescriptor &);
|
---|
[d1c5e2] | 63 |
|
---|
[7a1ce5] | 64 | protected:
|
---|
[dbb474] | 65 | /**
|
---|
| 66 | * forward Method to implementation
|
---|
| 67 | */
|
---|
[7a1ce5] | 68 | atom* find();
|
---|
[dbb474] | 69 |
|
---|
| 70 | /**
|
---|
| 71 | * forward Method to implementation
|
---|
| 72 | */
|
---|
[7a1ce5] | 73 | std::vector<atom*> findAll();
|
---|
[dbb474] | 74 |
|
---|
| 75 | /**
|
---|
| 76 | * Return the implementation this Wrapper currently points to.
|
---|
| 77 | * Used for copying, assignment and in Iterators over subsets of the World.
|
---|
| 78 | */
|
---|
[7a1ce5] | 79 | impl_ptr get_impl() const;
|
---|
[d1c5e2] | 80 |
|
---|
| 81 | private:
|
---|
[7a1ce5] | 82 | impl_ptr impl;
|
---|
[d1c5e2] | 83 | };
|
---|
| 84 |
|
---|
[dbb474] | 85 | /**
|
---|
| 86 | * produce an Atomdescriptor that at the point of construction contains an implementation that matches all Atoms
|
---|
| 87 | */
|
---|
[7a1ce5] | 88 | AtomDescriptor AllAtoms();
|
---|
[dbb474] | 89 |
|
---|
| 90 | /**
|
---|
| 91 | * produce an Atomdescriptor that at the point of construction contains an implementation that matches no Atoms
|
---|
| 92 | */
|
---|
[7a1ce5] | 93 | AtomDescriptor NoAtoms();
|
---|
[d1c5e2] | 94 |
|
---|
[dbb474] | 95 | /**
|
---|
| 96 | * Set Intersection for two Atomdescriptors. The resulting Atomdescriptor will only match an Atom if both
|
---|
| 97 | * given Atomdescriptors also match. Uses short circuit inside, so the second predicate wont be called
|
---|
| 98 | * when the first one failed.
|
---|
| 99 | */
|
---|
[7a1ce5] | 100 | AtomDescriptor operator&&(const AtomDescriptor &lhs, const AtomDescriptor &rhs);
|
---|
[dbb474] | 101 |
|
---|
| 102 | /**
|
---|
| 103 | * Set Union for two AtomDescriptors. The resulting AtomDescriptor will match an Atom if at least one of
|
---|
| 104 | * the two given AtomDescriptors does match. Used short circuit inside, so the second predicate wont
|
---|
| 105 | * be called when the first one failed.
|
---|
| 106 | */
|
---|
[7a1ce5] | 107 | AtomDescriptor operator||(const AtomDescriptor &lhs, const AtomDescriptor &rhs);
|
---|
[dbb474] | 108 |
|
---|
| 109 | /**
|
---|
| 110 | * Set inversion for an AtomDescriptor. Matches an Atom if the given AtomDescriptor did not match.
|
---|
| 111 | */
|
---|
[7a1ce5] | 112 | AtomDescriptor operator!(const AtomDescriptor &arg);
|
---|
[d1c5e2] | 113 |
|
---|
[fc1b24] | 114 | #endif /* ATOMDESCRIPTOR_HPP_ */
|
---|