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