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