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