| [f16a4b] | 1 | #ifndef ATOMDESCRIPTOR_IMPL_HPP
 | 
|---|
 | 2 | #define ATOMDESCRIPTOR_IMPL_HPP
 | 
|---|
 | 3 | 
 | 
|---|
| [7042f45] | 4 | #include "Descriptors/AtomDescriptor.hpp"
 | 
|---|
 | 5 | 
 | 
|---|
| [7a1ce5] | 6 | /************************ Declarations of implementation Objects ************************/
 | 
|---|
 | 7 | 
 | 
|---|
| [dbb474] | 8 | /**
 | 
|---|
 | 9 |  * This class implements a general Base class for AtomDescriptors using the PIMPL-Idiom
 | 
|---|
 | 10 |  *
 | 
|---|
 | 11 |  * The predicate for this class is empty and should be implemented by derived classes.
 | 
|---|
 | 12 |  * By the predicate it is described which atoms should be picked for a given descriptor.
 | 
|---|
 | 13 |  */
 | 
|---|
 | 14 | 
 | 
|---|
| [7a1ce5] | 15 | class AtomDescriptor_impl
 | 
|---|
 | 16 | {
 | 
|---|
 | 17 |   friend class AtomDescriptor;
 | 
|---|
 | 18 | public:
 | 
|---|
 | 19 | 
 | 
|---|
 | 20 |   AtomDescriptor_impl();
 | 
|---|
 | 21 |   virtual ~AtomDescriptor_impl();
 | 
|---|
 | 22 | 
 | 
|---|
| [dbb474] | 23 |   /**
 | 
|---|
 | 24 |    * Implement this abstract Method to make a concrete AtomDescriptor pick certain Atoms
 | 
|---|
 | 25 |    */
 | 
|---|
| [24a5e0] | 26 |   virtual bool predicate(std::pair<atomId_t,atom*>)=0;
 | 
|---|
| [7a1ce5] | 27 | 
 | 
|---|
 | 28 | protected:
 | 
|---|
| [dbb474] | 29 | 
 | 
|---|
 | 30 |   /**
 | 
|---|
 | 31 |    * This method is called when the Descriptor is used to find the first matching
 | 
|---|
 | 32 |    * Atom. Walks through all Atoms and stops on the first match. Can be implemented
 | 
|---|
 | 33 |    * when the searched Atom can be found in a more efficient way. Calculated
 | 
|---|
 | 34 |    * Atomdescriptors will always use this method, so no improvement there.
 | 
|---|
 | 35 |    */
 | 
|---|
| [7a1ce5] | 36 |   virtual atom* find();
 | 
|---|
| [dbb474] | 37 | 
 | 
|---|
 | 38 |   /**
 | 
|---|
 | 39 |    * This method is called when the Descriptor is used to find all matching Atoms.
 | 
|---|
 | 40 |    * Walks through all Atoms and tests the predicate on each one. A vector of all
 | 
|---|
 | 41 |    * matching Atoms is returned.
 | 
|---|
 | 42 |    */
 | 
|---|
| [7a1ce5] | 43 |   virtual std::vector<atom*> findAll();
 | 
|---|
| [dbb474] | 44 | 
 | 
|---|
 | 45 |   /**
 | 
|---|
 | 46 |    * This method is used internally to query the Set of Atoms from the world.
 | 
|---|
 | 47 |    * By using this method derived classes can also access the Internal World Datastructre.
 | 
|---|
 | 48 |    * Implemented in full in the Base Descriptor Implementation, so only this one method
 | 
|---|
 | 49 |    * needs to be friend with the World class.
 | 
|---|
 | 50 |    */
 | 
|---|
| [7042f45] | 51 |   World::AtomSet& getAtoms();
 | 
|---|
| [7a1ce5] | 52 | };
 | 
|---|
 | 53 | 
 | 
|---|
 | 54 | /************************** Universe and Emptyset *****************/
 | 
|---|
 | 55 | 
 | 
|---|
| [dbb474] | 56 | /**
 | 
|---|
 | 57 |  * A simple AtomDescriptor that will always match all Atoms present in the World.
 | 
|---|
 | 58 |  */
 | 
|---|
| [7a1ce5] | 59 | class AtomAllDescriptor_impl : public AtomDescriptor_impl {
 | 
|---|
 | 60 | public:
 | 
|---|
 | 61 |   AtomAllDescriptor_impl();
 | 
|---|
 | 62 |   virtual ~AtomAllDescriptor_impl();
 | 
|---|
| [dbb474] | 63 | 
 | 
|---|
 | 64 |   /**
 | 
|---|
 | 65 |    * Always returns true for any Atom
 | 
|---|
 | 66 |    */
 | 
|---|
| [24a5e0] | 67 |   virtual bool predicate(std::pair<atomId_t,atom*>);
 | 
|---|
| [7a1ce5] | 68 | };
 | 
|---|
 | 69 | 
 | 
|---|
| [dbb474] | 70 | 
 | 
|---|
 | 71 | /**
 | 
|---|
 | 72 |  * An AtomDescriptor that never matches any Atom in the World.
 | 
|---|
 | 73 |  */
 | 
|---|
| [7a1ce5] | 74 | class AtomNoneDescriptor_impl : public AtomDescriptor_impl {
 | 
|---|
 | 75 | public:
 | 
|---|
 | 76 |   AtomNoneDescriptor_impl();
 | 
|---|
 | 77 |   virtual ~AtomNoneDescriptor_impl();
 | 
|---|
| [dbb474] | 78 | 
 | 
|---|
 | 79 |   /**
 | 
|---|
 | 80 |    * Always returns false for any Atom
 | 
|---|
 | 81 |    */
 | 
|---|
| [24a5e0] | 82 |   virtual bool predicate(std::pair<atomId_t,atom*>);
 | 
|---|
| [7a1ce5] | 83 | };
 | 
|---|
 | 84 | 
 | 
|---|
 | 85 | /************************** Operator stuff ************************/
 | 
|---|
 | 86 | 
 | 
|---|
| [dbb474] | 87 | /**
 | 
|---|
 | 88 |  * Intersection of two AtomDescriptors
 | 
|---|
 | 89 |  */
 | 
|---|
| [7a1ce5] | 90 | class AtomAndDescriptor_impl : public AtomDescriptor_impl
 | 
|---|
 | 91 | {
 | 
|---|
 | 92 | public:
 | 
|---|
 | 93 |   AtomAndDescriptor_impl(AtomDescriptor::impl_ptr _lhs, AtomDescriptor::impl_ptr _rhs);
 | 
|---|
 | 94 |   ~AtomAndDescriptor_impl();
 | 
|---|
| [dbb474] | 95 | 
 | 
|---|
 | 96 |   /**
 | 
|---|
 | 97 |    * This predicate uses the predicate from the first && the predicate from the
 | 
|---|
 | 98 |    * second Descriptor to decide if an Atom should be selected.
 | 
|---|
 | 99 |    */
 | 
|---|
| [24a5e0] | 100 |   virtual bool predicate(std::pair<atomId_t,atom*>);
 | 
|---|
| [7a1ce5] | 101 | 
 | 
|---|
 | 102 | private:
 | 
|---|
 | 103 |   AtomDescriptor::impl_ptr lhs;
 | 
|---|
 | 104 |   AtomDescriptor::impl_ptr rhs;
 | 
|---|
 | 105 | };
 | 
|---|
 | 106 | 
 | 
|---|
| [dbb474] | 107 | /**
 | 
|---|
 | 108 |  * Union of two AtomDescriptors
 | 
|---|
 | 109 |  */
 | 
|---|
| [7a1ce5] | 110 | class AtomOrDescriptor_impl : public AtomDescriptor_impl
 | 
|---|
 | 111 | {
 | 
|---|
 | 112 | public:
 | 
|---|
 | 113 |   AtomOrDescriptor_impl(AtomDescriptor::impl_ptr _lhs, AtomDescriptor::impl_ptr _rhs);
 | 
|---|
 | 114 |   virtual ~AtomOrDescriptor_impl();
 | 
|---|
| [dbb474] | 115 | 
 | 
|---|
 | 116 |   /**
 | 
|---|
 | 117 |    * This predicate uses the predicate form the first || the predicate from the
 | 
|---|
 | 118 |    * second Descriptor to decide if an Atom should be selected.
 | 
|---|
 | 119 |    */
 | 
|---|
| [24a5e0] | 120 |   virtual bool predicate(std::pair<atomId_t,atom*>);
 | 
|---|
| [7a1ce5] | 121 | 
 | 
|---|
 | 122 | private:
 | 
|---|
 | 123 |   AtomDescriptor::impl_ptr lhs;
 | 
|---|
 | 124 |   AtomDescriptor::impl_ptr rhs;
 | 
|---|
 | 125 | };
 | 
|---|
 | 126 | 
 | 
|---|
| [dbb474] | 127 | /**
 | 
|---|
 | 128 |  * Set Inversion of a Descriptor
 | 
|---|
 | 129 |  */
 | 
|---|
| [7a1ce5] | 130 | class AtomNotDescriptor_impl : public AtomDescriptor_impl
 | 
|---|
 | 131 | {
 | 
|---|
 | 132 | public:
 | 
|---|
 | 133 |   AtomNotDescriptor_impl(AtomDescriptor::impl_ptr _arg);
 | 
|---|
 | 134 |   virtual ~AtomNotDescriptor_impl();
 | 
|---|
 | 135 | 
 | 
|---|
| [dbb474] | 136 |   /**
 | 
|---|
 | 137 |    * Opposite of the given descriptor predicate.
 | 
|---|
 | 138 |    */
 | 
|---|
| [24a5e0] | 139 |   virtual bool predicate(std::pair<atomId_t,atom*>);
 | 
|---|
| [7a1ce5] | 140 | 
 | 
|---|
 | 141 | private:
 | 
|---|
 | 142 |   AtomDescriptor::impl_ptr arg;
 | 
|---|
 | 143 | };
 | 
|---|
| [f16a4b] | 144 | 
 | 
|---|
 | 145 | #endif //ATOMDESCRIPTOR_IMPL_HPP
 | 
|---|