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