[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();
|
---|
[8cce2b] | 52 |
|
---|
| 53 | void checkAndAdd(std::vector<atom*>*,std::pair<atomId_t,atom*>);
|
---|
[7a1ce5] | 54 | };
|
---|
| 55 |
|
---|
| 56 | /************************** Universe and Emptyset *****************/
|
---|
| 57 |
|
---|
[dbb474] | 58 | /**
|
---|
| 59 | * A simple AtomDescriptor that will always match all Atoms present in the World.
|
---|
| 60 | */
|
---|
[7a1ce5] | 61 | class AtomAllDescriptor_impl : public AtomDescriptor_impl {
|
---|
| 62 | public:
|
---|
| 63 | AtomAllDescriptor_impl();
|
---|
| 64 | virtual ~AtomAllDescriptor_impl();
|
---|
[dbb474] | 65 |
|
---|
| 66 | /**
|
---|
| 67 | * Always returns true for any Atom
|
---|
| 68 | */
|
---|
[24a5e0] | 69 | virtual bool predicate(std::pair<atomId_t,atom*>);
|
---|
[7a1ce5] | 70 | };
|
---|
| 71 |
|
---|
[dbb474] | 72 |
|
---|
| 73 | /**
|
---|
| 74 | * An AtomDescriptor that never matches any Atom in the World.
|
---|
| 75 | */
|
---|
[7a1ce5] | 76 | class AtomNoneDescriptor_impl : public AtomDescriptor_impl {
|
---|
| 77 | public:
|
---|
| 78 | AtomNoneDescriptor_impl();
|
---|
| 79 | virtual ~AtomNoneDescriptor_impl();
|
---|
[dbb474] | 80 |
|
---|
| 81 | /**
|
---|
| 82 | * Always returns false for any Atom
|
---|
| 83 | */
|
---|
[24a5e0] | 84 | virtual bool predicate(std::pair<atomId_t,atom*>);
|
---|
[7a1ce5] | 85 | };
|
---|
| 86 |
|
---|
| 87 | /************************** Operator stuff ************************/
|
---|
| 88 |
|
---|
[dbb474] | 89 | /**
|
---|
| 90 | * Intersection of two AtomDescriptors
|
---|
| 91 | */
|
---|
[7a1ce5] | 92 | class AtomAndDescriptor_impl : public AtomDescriptor_impl
|
---|
| 93 | {
|
---|
| 94 | public:
|
---|
| 95 | AtomAndDescriptor_impl(AtomDescriptor::impl_ptr _lhs, AtomDescriptor::impl_ptr _rhs);
|
---|
| 96 | ~AtomAndDescriptor_impl();
|
---|
[dbb474] | 97 |
|
---|
| 98 | /**
|
---|
| 99 | * This predicate uses the predicate from the first && the predicate from the
|
---|
| 100 | * second Descriptor to decide if an Atom should be selected.
|
---|
| 101 | */
|
---|
[24a5e0] | 102 | virtual bool predicate(std::pair<atomId_t,atom*>);
|
---|
[7a1ce5] | 103 |
|
---|
| 104 | private:
|
---|
| 105 | AtomDescriptor::impl_ptr lhs;
|
---|
| 106 | AtomDescriptor::impl_ptr rhs;
|
---|
| 107 | };
|
---|
| 108 |
|
---|
[dbb474] | 109 | /**
|
---|
| 110 | * Union of two AtomDescriptors
|
---|
| 111 | */
|
---|
[7a1ce5] | 112 | class AtomOrDescriptor_impl : public AtomDescriptor_impl
|
---|
| 113 | {
|
---|
| 114 | public:
|
---|
| 115 | AtomOrDescriptor_impl(AtomDescriptor::impl_ptr _lhs, AtomDescriptor::impl_ptr _rhs);
|
---|
| 116 | virtual ~AtomOrDescriptor_impl();
|
---|
[dbb474] | 117 |
|
---|
| 118 | /**
|
---|
| 119 | * This predicate uses the predicate form the first || the predicate from the
|
---|
| 120 | * second Descriptor to decide if an Atom should be selected.
|
---|
| 121 | */
|
---|
[24a5e0] | 122 | virtual bool predicate(std::pair<atomId_t,atom*>);
|
---|
[7a1ce5] | 123 |
|
---|
| 124 | private:
|
---|
| 125 | AtomDescriptor::impl_ptr lhs;
|
---|
| 126 | AtomDescriptor::impl_ptr rhs;
|
---|
| 127 | };
|
---|
| 128 |
|
---|
[dbb474] | 129 | /**
|
---|
| 130 | * Set Inversion of a Descriptor
|
---|
| 131 | */
|
---|
[7a1ce5] | 132 | class AtomNotDescriptor_impl : public AtomDescriptor_impl
|
---|
| 133 | {
|
---|
| 134 | public:
|
---|
| 135 | AtomNotDescriptor_impl(AtomDescriptor::impl_ptr _arg);
|
---|
| 136 | virtual ~AtomNotDescriptor_impl();
|
---|
| 137 |
|
---|
[dbb474] | 138 | /**
|
---|
| 139 | * Opposite of the given descriptor predicate.
|
---|
| 140 | */
|
---|
[24a5e0] | 141 | virtual bool predicate(std::pair<atomId_t,atom*>);
|
---|
[7a1ce5] | 142 |
|
---|
| 143 | private:
|
---|
| 144 | AtomDescriptor::impl_ptr arg;
|
---|
| 145 | };
|
---|
[f16a4b] | 146 |
|
---|
| 147 | #endif //ATOMDESCRIPTOR_IMPL_HPP
|
---|