| [1c51c8] | 1 | #ifndef MOLECULEDESCRIPTOR_IMPL_HPP
 | 
|---|
 | 2 | #define MOLECULEDESCRIPTOR_IMPL_HPP
 | 
|---|
 | 3 | 
 | 
|---|
 | 4 | #include "Descriptors/MoleculeDescriptor.hpp"
 | 
|---|
 | 5 | 
 | 
|---|
 | 6 | /************************ Declarations of implementation Objects ************************/
 | 
|---|
 | 7 | 
 | 
|---|
 | 8 | /**
 | 
|---|
 | 9 |  * This class implements a general Base class for MoleculeDescriptors 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 molecules should be picked for a given descriptor.
 | 
|---|
 | 13 |  */
 | 
|---|
 | 14 | 
 | 
|---|
 | 15 | class MoleculeDescriptor_impl
 | 
|---|
 | 16 | {
 | 
|---|
 | 17 |   friend class MoleculeDescriptor;
 | 
|---|
 | 18 | public:
 | 
|---|
 | 19 | 
 | 
|---|
 | 20 |   MoleculeDescriptor_impl();
 | 
|---|
 | 21 |   virtual ~MoleculeDescriptor_impl();
 | 
|---|
 | 22 | 
 | 
|---|
 | 23 |   /**
 | 
|---|
 | 24 |    * Implement this abstract Method to make a concrete MoleculeDescriptor pick certain Molecules
 | 
|---|
 | 25 |    */
 | 
|---|
 | 26 |   virtual bool predicate(std::pair<moleculeId_t,molecule*>)=0;
 | 
|---|
 | 27 | 
 | 
|---|
 | 28 | protected:
 | 
|---|
 | 29 | 
 | 
|---|
 | 30 |   /**
 | 
|---|
 | 31 |    * This method is called when the Descriptor is used to find the first matching
 | 
|---|
 | 32 |    * Molecule. Walks through all Molecules and stops on the first match. Can be implemented
 | 
|---|
 | 33 |    * when the searched Molecule can be found in a more efficient way. Calculated
 | 
|---|
 | 34 |    * Moleculedescriptors will always use this method, so no improvement there.
 | 
|---|
 | 35 |    */
 | 
|---|
 | 36 |   virtual molecule* find();
 | 
|---|
 | 37 | 
 | 
|---|
 | 38 |   /**
 | 
|---|
 | 39 |    * This method is called when the Descriptor is used to find all matching Molecules.
 | 
|---|
 | 40 |    * Walks through all Molecules and tests the predicate on each one. A vector of all
 | 
|---|
 | 41 |    * matching Molecules is returned.
 | 
|---|
 | 42 |    */
 | 
|---|
 | 43 |   virtual std::vector<molecule*> findAll();
 | 
|---|
 | 44 | 
 | 
|---|
 | 45 |   /**
 | 
|---|
 | 46 |    * This method is used internally to query the Set of Molecules 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 |    */
 | 
|---|
 | 51 |   World::MoleculeSet& getMolecules();
 | 
|---|
 | 52 | };
 | 
|---|
 | 53 | 
 | 
|---|
 | 54 | /************************** Universe and Emptyset *****************/
 | 
|---|
 | 55 | 
 | 
|---|
 | 56 | /**
 | 
|---|
 | 57 |  * A simple MoleculeDescriptor that will always match all Molecules present in the World.
 | 
|---|
 | 58 |  */
 | 
|---|
 | 59 | class MoleculeAllDescriptor_impl : public MoleculeDescriptor_impl {
 | 
|---|
 | 60 | public:
 | 
|---|
 | 61 |   MoleculeAllDescriptor_impl();
 | 
|---|
 | 62 |   virtual ~MoleculeAllDescriptor_impl();
 | 
|---|
 | 63 | 
 | 
|---|
 | 64 |   /**
 | 
|---|
 | 65 |    * Always returns true for any Molecule
 | 
|---|
 | 66 |    */
 | 
|---|
 | 67 |   virtual bool predicate(std::pair<moleculeId_t,molecule*>);
 | 
|---|
 | 68 | };
 | 
|---|
 | 69 | 
 | 
|---|
 | 70 | 
 | 
|---|
 | 71 | /**
 | 
|---|
 | 72 |  * An MoleculeDescriptor that never matches any Molecule in the World.
 | 
|---|
 | 73 |  */
 | 
|---|
 | 74 | class MoleculeNoneDescriptor_impl : public MoleculeDescriptor_impl {
 | 
|---|
 | 75 | public:
 | 
|---|
 | 76 |   MoleculeNoneDescriptor_impl();
 | 
|---|
 | 77 |   virtual ~MoleculeNoneDescriptor_impl();
 | 
|---|
 | 78 | 
 | 
|---|
 | 79 |   /**
 | 
|---|
 | 80 |    * Always returns false for any Molecule
 | 
|---|
 | 81 |    */
 | 
|---|
 | 82 |   virtual bool predicate(std::pair<moleculeId_t,molecule*>);
 | 
|---|
 | 83 | };
 | 
|---|
 | 84 | 
 | 
|---|
 | 85 | /************************** Operator stuff ************************/
 | 
|---|
 | 86 | 
 | 
|---|
 | 87 | /**
 | 
|---|
 | 88 |  * Intersection of two MoleculeDescriptors
 | 
|---|
 | 89 |  */
 | 
|---|
 | 90 | class MoleculeAndDescriptor_impl : public MoleculeDescriptor_impl
 | 
|---|
 | 91 | {
 | 
|---|
 | 92 | public:
 | 
|---|
 | 93 |   MoleculeAndDescriptor_impl(MoleculeDescriptor::impl_ptr _lhs, MoleculeDescriptor::impl_ptr _rhs);
 | 
|---|
 | 94 |   ~MoleculeAndDescriptor_impl();
 | 
|---|
 | 95 | 
 | 
|---|
 | 96 |   /**
 | 
|---|
 | 97 |    * This predicate uses the predicate from the first && the predicate from the
 | 
|---|
 | 98 |    * second Descriptor to decide if an Molecule should be selected.
 | 
|---|
 | 99 |    */
 | 
|---|
 | 100 |   virtual bool predicate(std::pair<moleculeId_t,molecule*>);
 | 
|---|
 | 101 | 
 | 
|---|
 | 102 | private:
 | 
|---|
 | 103 |   MoleculeDescriptor::impl_ptr lhs;
 | 
|---|
 | 104 |   MoleculeDescriptor::impl_ptr rhs;
 | 
|---|
 | 105 | };
 | 
|---|
 | 106 | 
 | 
|---|
 | 107 | /**
 | 
|---|
 | 108 |  * Union of two MoleculeDescriptors
 | 
|---|
 | 109 |  */
 | 
|---|
 | 110 | class MoleculeOrDescriptor_impl : public MoleculeDescriptor_impl
 | 
|---|
 | 111 | {
 | 
|---|
 | 112 | public:
 | 
|---|
 | 113 |   MoleculeOrDescriptor_impl(MoleculeDescriptor::impl_ptr _lhs, MoleculeDescriptor::impl_ptr _rhs);
 | 
|---|
 | 114 |   virtual ~MoleculeOrDescriptor_impl();
 | 
|---|
 | 115 | 
 | 
|---|
 | 116 |   /**
 | 
|---|
 | 117 |    * This predicate uses the predicate form the first || the predicate from the
 | 
|---|
 | 118 |    * second Descriptor to decide if an Molecule should be selected.
 | 
|---|
 | 119 |    */
 | 
|---|
 | 120 |   virtual bool predicate(std::pair<moleculeId_t,molecule*>);
 | 
|---|
 | 121 | 
 | 
|---|
 | 122 | private:
 | 
|---|
 | 123 |   MoleculeDescriptor::impl_ptr lhs;
 | 
|---|
 | 124 |   MoleculeDescriptor::impl_ptr rhs;
 | 
|---|
 | 125 | };
 | 
|---|
 | 126 | 
 | 
|---|
 | 127 | /**
 | 
|---|
 | 128 |  * Set Inversion of a Descriptor
 | 
|---|
 | 129 |  */
 | 
|---|
 | 130 | class MoleculeNotDescriptor_impl : public MoleculeDescriptor_impl
 | 
|---|
 | 131 | {
 | 
|---|
 | 132 | public:
 | 
|---|
 | 133 |   MoleculeNotDescriptor_impl(MoleculeDescriptor::impl_ptr _arg);
 | 
|---|
 | 134 |   virtual ~MoleculeNotDescriptor_impl();
 | 
|---|
 | 135 | 
 | 
|---|
 | 136 |   /**
 | 
|---|
 | 137 |    * Opposite of the given descriptor predicate.
 | 
|---|
 | 138 |    */
 | 
|---|
 | 139 |   virtual bool predicate(std::pair<moleculeId_t,molecule*>);
 | 
|---|
 | 140 | 
 | 
|---|
 | 141 | private:
 | 
|---|
 | 142 |   MoleculeDescriptor::impl_ptr arg;
 | 
|---|
 | 143 | };
 | 
|---|
 | 144 | 
 | 
|---|
 | 145 | #endif //MOLECULEDESCRIPTOR_IMPL_HPP
 | 
|---|