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