| [1c51c8] | 1 | /* | 
|---|
|  | 2 | * MoleculeDescriptor.hpp | 
|---|
|  | 3 | * | 
|---|
|  | 4 | *  Created on: Feb 5, 2010 | 
|---|
|  | 5 | *      Author: crueger | 
|---|
|  | 6 | */ | 
|---|
|  | 7 |  | 
|---|
|  | 8 | #ifndef MOLECULEDESCRIPTOR_HPP_ | 
|---|
|  | 9 | #define MOLECULEDESCRIPTOR_HPP_ | 
|---|
|  | 10 |  | 
|---|
| [56f73b] | 11 | // include config.h | 
|---|
|  | 12 | #ifdef HAVE_CONFIG_H | 
|---|
|  | 13 | #include <config.h> | 
|---|
|  | 14 | #endif | 
|---|
|  | 15 |  | 
|---|
|  | 16 |  | 
|---|
| [1c51c8] | 17 |  | 
|---|
|  | 18 | #include <vector> | 
|---|
|  | 19 | #include <map> | 
|---|
|  | 20 | #include <boost/shared_ptr.hpp> | 
|---|
|  | 21 | #include "World.hpp" | 
|---|
|  | 22 |  | 
|---|
|  | 23 | class World; | 
|---|
|  | 24 | class molecule; | 
|---|
|  | 25 |  | 
|---|
|  | 26 | // internal implementation, allows assignment, copying etc | 
|---|
|  | 27 | class MoleculeDescriptor_impl; | 
|---|
|  | 28 |  | 
|---|
|  | 29 | /** | 
|---|
|  | 30 | * An MoleculeDescriptor describes a Set of Molecules from the World. Can be used for any method that needs to work on | 
|---|
|  | 31 | * a specific set of Molecules. | 
|---|
|  | 32 | * | 
|---|
|  | 33 | * This Class is implemented using the PIMPL-Idion, i.e. this class only contains an abstract structure | 
|---|
|  | 34 | * that forwards any request to a wrapped pointer-to-implementation. This way operators and calculations | 
|---|
|  | 35 | * on Descriptors are possible. | 
|---|
|  | 36 | * | 
|---|
|  | 37 | * Concrete Implementation Objects can be shared between multiple Wrappers, so make sure that | 
|---|
|  | 38 | * any Implementation remainst constant during lifetime. | 
|---|
|  | 39 | */ | 
|---|
|  | 40 | class MoleculeDescriptor { | 
|---|
|  | 41 | // close coupling to the world to allow access | 
|---|
|  | 42 | friend molecule* World::getMolecule(MoleculeDescriptor descriptor); | 
|---|
|  | 43 | friend std::vector<molecule*> World::getAllMolecules(MoleculeDescriptor descriptor); | 
|---|
| [6e97e5] | 44 | template <class,class,class> friend class SelectiveIterator; | 
|---|
| [feb5d0] | 45 | template <class,class,class> friend class SelectiveConstIterator; | 
|---|
| [1c51c8] | 46 |  | 
|---|
|  | 47 | friend MoleculeDescriptor operator&&(const MoleculeDescriptor &lhs, const MoleculeDescriptor &rhs); | 
|---|
|  | 48 | friend MoleculeDescriptor operator||(const MoleculeDescriptor &lhs, const MoleculeDescriptor &rhs); | 
|---|
|  | 49 | friend MoleculeDescriptor operator!(const MoleculeDescriptor &arg); | 
|---|
|  | 50 |  | 
|---|
|  | 51 | public: | 
|---|
| [6e97e5] | 52 | typedef MoleculeDescriptor_impl impl_t; | 
|---|
|  | 53 | typedef boost::shared_ptr<impl_t> impl_ptr; //!< Allow easy changes of the pointer-to-implementation type | 
|---|
| [1c51c8] | 54 |  | 
|---|
|  | 55 | MoleculeDescriptor(impl_ptr); | 
|---|
|  | 56 |  | 
|---|
|  | 57 | /** | 
|---|
|  | 58 | * Copy constructor. | 
|---|
|  | 59 | * Takes the Implementation from the copied object and sets it's own pointer to link there. | 
|---|
|  | 60 | * This way the actuall implementation object is shared between copy and original | 
|---|
|  | 61 | */ | 
|---|
|  | 62 | MoleculeDescriptor(const MoleculeDescriptor&); | 
|---|
|  | 63 | ~MoleculeDescriptor(); | 
|---|
|  | 64 |  | 
|---|
|  | 65 | /** | 
|---|
|  | 66 | * Assignment Operator. | 
|---|
|  | 67 | * | 
|---|
|  | 68 | * Implemented by setting the pointer to the new Implementation. | 
|---|
|  | 69 | */ | 
|---|
|  | 70 | MoleculeDescriptor &operator=(MoleculeDescriptor &); | 
|---|
|  | 71 |  | 
|---|
|  | 72 | protected: | 
|---|
|  | 73 | /** | 
|---|
|  | 74 | * forward Method to implementation | 
|---|
|  | 75 | */ | 
|---|
|  | 76 | molecule* find(); | 
|---|
|  | 77 |  | 
|---|
|  | 78 | /** | 
|---|
|  | 79 | * forward Method to implementation | 
|---|
|  | 80 | */ | 
|---|
|  | 81 | std::vector<molecule*> findAll(); | 
|---|
|  | 82 |  | 
|---|
|  | 83 | /** | 
|---|
|  | 84 | * Return the implementation this Wrapper currently points to. | 
|---|
|  | 85 | * Used for copying, assignment and in Iterators over subsets of the World. | 
|---|
|  | 86 | */ | 
|---|
|  | 87 | impl_ptr get_impl() const; | 
|---|
|  | 88 |  | 
|---|
|  | 89 | private: | 
|---|
|  | 90 | impl_ptr impl; | 
|---|
|  | 91 | }; | 
|---|
|  | 92 |  | 
|---|
|  | 93 | /** | 
|---|
|  | 94 | * produce an Moleculedescriptor that at the point of construction contains an implementation that matches all Molecules | 
|---|
|  | 95 | */ | 
|---|
|  | 96 | MoleculeDescriptor AllMolecules(); | 
|---|
|  | 97 |  | 
|---|
|  | 98 | /** | 
|---|
|  | 99 | * produce an Moleculedescriptor that at the point of construction contains an implementation that matches no Molecules | 
|---|
|  | 100 | */ | 
|---|
|  | 101 | MoleculeDescriptor NoMolecules(); | 
|---|
|  | 102 |  | 
|---|
|  | 103 | /** | 
|---|
|  | 104 | * Set Intersection for two Moleculedescriptors. The resulting Moleculedescriptor will only match an Molecule if both | 
|---|
|  | 105 | * given Moleculedescriptors also match. Uses short circuit inside, so the second predicate wont be called | 
|---|
|  | 106 | * when the first one failed. | 
|---|
|  | 107 | */ | 
|---|
|  | 108 | MoleculeDescriptor operator&&(const MoleculeDescriptor &lhs, const MoleculeDescriptor &rhs); | 
|---|
|  | 109 |  | 
|---|
|  | 110 | /** | 
|---|
|  | 111 | * Set Union for two MoleculeDescriptors. The resulting MoleculeDescriptor will match an Molecule if at least one of | 
|---|
|  | 112 | * the two given MoleculeDescriptors does match. Used short circuit inside, so the second predicate wont | 
|---|
|  | 113 | * be called when the first one failed. | 
|---|
|  | 114 | */ | 
|---|
|  | 115 | MoleculeDescriptor operator||(const MoleculeDescriptor &lhs, const MoleculeDescriptor &rhs); | 
|---|
|  | 116 |  | 
|---|
|  | 117 | /** | 
|---|
|  | 118 | * Set inversion for an MoleculeDescriptor. Matches an Molecule if the given MoleculeDescriptor did not match. | 
|---|
|  | 119 | */ | 
|---|
|  | 120 | MoleculeDescriptor operator!(const MoleculeDescriptor &arg); | 
|---|
|  | 121 |  | 
|---|
|  | 122 | #endif /* MOLECULEDESCRIPTOR_HPP_ */ | 
|---|