| [f16a4b] | 1 | #ifndef ATOMDESCRIPTOR_IMPL_HPP
 | 
|---|
 | 2 | #define ATOMDESCRIPTOR_IMPL_HPP
 | 
|---|
 | 3 | 
 | 
|---|
| [56f73b] | 4 | // include config.h
 | 
|---|
 | 5 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 6 | #include <config.h>
 | 
|---|
 | 7 | #endif
 | 
|---|
 | 8 | 
 | 
|---|
 | 9 | 
 | 
|---|
| [7042f45] | 10 | #include "Descriptors/AtomDescriptor.hpp"
 | 
|---|
 | 11 | 
 | 
|---|
| [7a1ce5] | 12 | /************************ Declarations of implementation Objects ************************/
 | 
|---|
 | 13 | 
 | 
|---|
| [dbb474] | 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 | 
 | 
|---|
| [7a1ce5] | 21 | class AtomDescriptor_impl
 | 
|---|
 | 22 | {
 | 
|---|
 | 23 |   friend class AtomDescriptor;
 | 
|---|
 | 24 | public:
 | 
|---|
 | 25 | 
 | 
|---|
 | 26 |   AtomDescriptor_impl();
 | 
|---|
 | 27 |   virtual ~AtomDescriptor_impl();
 | 
|---|
 | 28 | 
 | 
|---|
| [dbb474] | 29 |   /**
 | 
|---|
 | 30 |    * Implement this abstract Method to make a concrete AtomDescriptor pick certain Atoms
 | 
|---|
 | 31 |    */
 | 
|---|
| [795c0f] | 32 |   virtual bool predicate(std::pair<atomId_t,const atom*>) const=0;
 | 
|---|
| [7a1ce5] | 33 | 
 | 
|---|
 | 34 | protected:
 | 
|---|
| [dbb474] | 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 |    */
 | 
|---|
| [7a1ce5] | 42 |   virtual atom* find();
 | 
|---|
| [dbb474] | 43 | 
 | 
|---|
| [795c0f] | 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 | 
 | 
|---|
| [dbb474] | 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 |    */
 | 
|---|
| [7a1ce5] | 57 |   virtual std::vector<atom*> findAll();
 | 
|---|
| [dbb474] | 58 | 
 | 
|---|
| [795c0f] | 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 | 
 | 
|---|
| [dbb474] | 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 |    */
 | 
|---|
| [7042f45] | 72 |   World::AtomSet& getAtoms();
 | 
|---|
| [8cce2b] | 73 | 
 | 
|---|
| [795c0f] | 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 | 
 | 
|---|
| [8cce2b] | 82 |   void checkAndAdd(std::vector<atom*>*,std::pair<atomId_t,atom*>);
 | 
|---|
| [795c0f] | 83 | 
 | 
|---|
 | 84 |   void checkAndAdd(std::vector<const atom*>*,std::pair<atomId_t,const atom*>) const;
 | 
|---|
| [7a1ce5] | 85 | };
 | 
|---|
 | 86 | 
 | 
|---|
 | 87 | /************************** Universe and Emptyset *****************/
 | 
|---|
 | 88 | 
 | 
|---|
| [dbb474] | 89 | /**
 | 
|---|
 | 90 |  * A simple AtomDescriptor that will always match all Atoms present in the World.
 | 
|---|
 | 91 |  */
 | 
|---|
| [7a1ce5] | 92 | class AtomAllDescriptor_impl : public AtomDescriptor_impl {
 | 
|---|
 | 93 | public:
 | 
|---|
 | 94 |   AtomAllDescriptor_impl();
 | 
|---|
 | 95 |   virtual ~AtomAllDescriptor_impl();
 | 
|---|
| [dbb474] | 96 | 
 | 
|---|
 | 97 |   /**
 | 
|---|
 | 98 |    * Always returns true for any Atom
 | 
|---|
 | 99 |    */
 | 
|---|
| [795c0f] | 100 |   virtual bool predicate(std::pair<atomId_t, const atom*>) const;
 | 
|---|
| [7a1ce5] | 101 | };
 | 
|---|
 | 102 | 
 | 
|---|
| [dbb474] | 103 | 
 | 
|---|
 | 104 | /**
 | 
|---|
 | 105 |  * An AtomDescriptor that never matches any Atom in the World.
 | 
|---|
 | 106 |  */
 | 
|---|
| [7a1ce5] | 107 | class AtomNoneDescriptor_impl : public AtomDescriptor_impl {
 | 
|---|
 | 108 | public:
 | 
|---|
 | 109 |   AtomNoneDescriptor_impl();
 | 
|---|
 | 110 |   virtual ~AtomNoneDescriptor_impl();
 | 
|---|
| [dbb474] | 111 | 
 | 
|---|
 | 112 |   /**
 | 
|---|
 | 113 |    * Always returns false for any Atom
 | 
|---|
 | 114 |    */
 | 
|---|
| [795c0f] | 115 |   virtual bool predicate(std::pair<atomId_t,const atom*>)const;
 | 
|---|
| [7a1ce5] | 116 | };
 | 
|---|
 | 117 | 
 | 
|---|
 | 118 | /************************** Operator stuff ************************/
 | 
|---|
 | 119 | 
 | 
|---|
| [dbb474] | 120 | /**
 | 
|---|
 | 121 |  * Intersection of two AtomDescriptors
 | 
|---|
 | 122 |  */
 | 
|---|
| [7a1ce5] | 123 | class AtomAndDescriptor_impl : public AtomDescriptor_impl
 | 
|---|
 | 124 | {
 | 
|---|
 | 125 | public:
 | 
|---|
 | 126 |   AtomAndDescriptor_impl(AtomDescriptor::impl_ptr _lhs, AtomDescriptor::impl_ptr _rhs);
 | 
|---|
 | 127 |   ~AtomAndDescriptor_impl();
 | 
|---|
| [dbb474] | 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 |    */
 | 
|---|
| [795c0f] | 133 |   virtual bool predicate(std::pair<atomId_t,const atom*>) const;
 | 
|---|
| [7a1ce5] | 134 | 
 | 
|---|
 | 135 | private:
 | 
|---|
 | 136 |   AtomDescriptor::impl_ptr lhs;
 | 
|---|
 | 137 |   AtomDescriptor::impl_ptr rhs;
 | 
|---|
 | 138 | };
 | 
|---|
 | 139 | 
 | 
|---|
| [dbb474] | 140 | /**
 | 
|---|
 | 141 |  * Union of two AtomDescriptors
 | 
|---|
 | 142 |  */
 | 
|---|
| [7a1ce5] | 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();
 | 
|---|
| [dbb474] | 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 |    */
 | 
|---|
| [795c0f] | 153 |   virtual bool predicate(std::pair<atomId_t,const atom*>) const;
 | 
|---|
| [7a1ce5] | 154 | 
 | 
|---|
 | 155 | private:
 | 
|---|
 | 156 |   AtomDescriptor::impl_ptr lhs;
 | 
|---|
 | 157 |   AtomDescriptor::impl_ptr rhs;
 | 
|---|
 | 158 | };
 | 
|---|
 | 159 | 
 | 
|---|
| [dbb474] | 160 | /**
 | 
|---|
 | 161 |  * Set Inversion of a Descriptor
 | 
|---|
 | 162 |  */
 | 
|---|
| [7a1ce5] | 163 | class AtomNotDescriptor_impl : public AtomDescriptor_impl
 | 
|---|
 | 164 | {
 | 
|---|
 | 165 | public:
 | 
|---|
 | 166 |   AtomNotDescriptor_impl(AtomDescriptor::impl_ptr _arg);
 | 
|---|
 | 167 |   virtual ~AtomNotDescriptor_impl();
 | 
|---|
 | 168 | 
 | 
|---|
| [dbb474] | 169 |   /**
 | 
|---|
 | 170 |    * Opposite of the given descriptor predicate.
 | 
|---|
 | 171 |    */
 | 
|---|
| [795c0f] | 172 |   virtual bool predicate(std::pair<atomId_t,const atom*>) const;
 | 
|---|
| [7a1ce5] | 173 | 
 | 
|---|
 | 174 | private:
 | 
|---|
 | 175 |   AtomDescriptor::impl_ptr arg;
 | 
|---|
 | 176 | };
 | 
|---|
| [f16a4b] | 177 | 
 | 
|---|
 | 178 | #endif //ATOMDESCRIPTOR_IMPL_HPP
 | 
|---|