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