1 | /*
|
---|
2 | * MoleculeDescriptor.cpp
|
---|
3 | *
|
---|
4 | * Created on: Feb 5, 2010
|
---|
5 | * Author: crueger
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "Helpers/MemDebug.hpp"
|
---|
9 |
|
---|
10 | #include "Descriptors/MoleculeDescriptor.hpp"
|
---|
11 | #include "Descriptors/MoleculeDescriptor_impl.hpp"
|
---|
12 |
|
---|
13 | #include "World.hpp"
|
---|
14 |
|
---|
15 | #include "molecule.hpp"
|
---|
16 |
|
---|
17 | #include <boost/bind.hpp>
|
---|
18 | #include <iostream>
|
---|
19 |
|
---|
20 | using namespace std;
|
---|
21 |
|
---|
22 | typedef World::MoleculeSet::iterator molecules_iter_t;
|
---|
23 |
|
---|
24 | /************************ Forwarding object **************************************/
|
---|
25 |
|
---|
26 |
|
---|
27 | MoleculeDescriptor::MoleculeDescriptor(impl_ptr _impl) :
|
---|
28 | impl(_impl)
|
---|
29 | {}
|
---|
30 |
|
---|
31 | MoleculeDescriptor::MoleculeDescriptor(const MoleculeDescriptor& src) :
|
---|
32 | impl(src.get_impl())
|
---|
33 | {}
|
---|
34 |
|
---|
35 | MoleculeDescriptor::~MoleculeDescriptor()
|
---|
36 | {}
|
---|
37 |
|
---|
38 | MoleculeDescriptor& MoleculeDescriptor::operator=(MoleculeDescriptor &src){
|
---|
39 | if(&src!=this) {
|
---|
40 | impl=src.get_impl();
|
---|
41 | }
|
---|
42 | return *this;
|
---|
43 | }
|
---|
44 |
|
---|
45 | molecule* MoleculeDescriptor::find(){
|
---|
46 | return impl->find();
|
---|
47 | }
|
---|
48 |
|
---|
49 | std::vector<molecule*> MoleculeDescriptor::findAll(){
|
---|
50 | return impl->findAll();
|
---|
51 | }
|
---|
52 |
|
---|
53 | MoleculeDescriptor::impl_ptr MoleculeDescriptor::get_impl() const{
|
---|
54 | return impl;
|
---|
55 | }
|
---|
56 |
|
---|
57 |
|
---|
58 |
|
---|
59 |
|
---|
60 | /**************************** implementation ********************/
|
---|
61 |
|
---|
62 | MoleculeDescriptor_impl::MoleculeDescriptor_impl()
|
---|
63 | {
|
---|
64 | }
|
---|
65 |
|
---|
66 | MoleculeDescriptor_impl::~MoleculeDescriptor_impl()
|
---|
67 | {
|
---|
68 | }
|
---|
69 |
|
---|
70 | World::MoleculeSet& MoleculeDescriptor_impl::getMolecules(){
|
---|
71 | return World::getInstance().molecules;
|
---|
72 | }
|
---|
73 |
|
---|
74 | molecule* MoleculeDescriptor_impl::find() {
|
---|
75 | World::MoleculeSet molecules = getMolecules();
|
---|
76 | molecules_iter_t res = find_if(molecules.begin(),molecules.end(),boost::bind(&MoleculeDescriptor_impl::predicate,this,_1));
|
---|
77 | return (res!=molecules.end())?((*res).second):0;
|
---|
78 | }
|
---|
79 |
|
---|
80 | vector<molecule*> MoleculeDescriptor_impl::findAll() {
|
---|
81 | vector<molecule*> res;
|
---|
82 | World::MoleculeSet molecules = getMolecules();
|
---|
83 | molecules_iter_t iter;
|
---|
84 | for(iter=molecules.begin();iter!=molecules.end();++iter) {
|
---|
85 | if(predicate(*iter)){
|
---|
86 | res.push_back((*iter).second);
|
---|
87 | }
|
---|
88 | }
|
---|
89 | return res;
|
---|
90 | }
|
---|
91 |
|
---|
92 | /************************** Universe and Emptyset *****************/
|
---|
93 |
|
---|
94 | MoleculeAllDescriptor_impl::MoleculeAllDescriptor_impl()
|
---|
95 | {}
|
---|
96 |
|
---|
97 | MoleculeAllDescriptor_impl::~MoleculeAllDescriptor_impl()
|
---|
98 | {}
|
---|
99 |
|
---|
100 | bool MoleculeAllDescriptor_impl::predicate(std::pair<moleculeId_t,molecule*>){
|
---|
101 | return true;
|
---|
102 | }
|
---|
103 |
|
---|
104 | MoleculeDescriptor AllMolecules(){
|
---|
105 | return MoleculeDescriptor(MoleculeDescriptor::impl_ptr(new MoleculeAllDescriptor_impl));
|
---|
106 | }
|
---|
107 |
|
---|
108 | MoleculeNoneDescriptor_impl::MoleculeNoneDescriptor_impl()
|
---|
109 | {}
|
---|
110 |
|
---|
111 | MoleculeNoneDescriptor_impl::~MoleculeNoneDescriptor_impl()
|
---|
112 | {}
|
---|
113 |
|
---|
114 | bool MoleculeNoneDescriptor_impl::predicate(std::pair<moleculeId_t,molecule*>){
|
---|
115 | return false;
|
---|
116 | }
|
---|
117 |
|
---|
118 | MoleculeDescriptor NoMolecules(){
|
---|
119 | return MoleculeDescriptor(MoleculeDescriptor::impl_ptr(new MoleculeNoneDescriptor_impl));
|
---|
120 | }
|
---|
121 |
|
---|
122 | /************************** Operator stuff ************************/
|
---|
123 |
|
---|
124 | // AND
|
---|
125 | MoleculeAndDescriptor_impl::MoleculeAndDescriptor_impl(MoleculeDescriptor::impl_ptr _lhs, MoleculeDescriptor::impl_ptr _rhs) :
|
---|
126 | lhs(_lhs), rhs(_rhs)
|
---|
127 | {}
|
---|
128 |
|
---|
129 | MoleculeAndDescriptor_impl::~MoleculeAndDescriptor_impl()
|
---|
130 | {}
|
---|
131 |
|
---|
132 | bool MoleculeAndDescriptor_impl::predicate(std::pair<moleculeId_t,molecule*> molecule){
|
---|
133 | return lhs->predicate(molecule) && rhs->predicate(molecule);
|
---|
134 | }
|
---|
135 | MoleculeDescriptor operator&&(const MoleculeDescriptor &lhs, const MoleculeDescriptor &rhs){
|
---|
136 | MoleculeDescriptor::impl_ptr newImpl = MoleculeDescriptor::impl_ptr(new MoleculeAndDescriptor_impl(lhs.get_impl(),rhs.get_impl()));
|
---|
137 | return MoleculeDescriptor(newImpl);
|
---|
138 | }
|
---|
139 |
|
---|
140 | // OR
|
---|
141 | MoleculeOrDescriptor_impl::MoleculeOrDescriptor_impl(MoleculeDescriptor::impl_ptr _lhs ,MoleculeDescriptor::impl_ptr _rhs) :
|
---|
142 | lhs(_lhs), rhs(_rhs)
|
---|
143 | {}
|
---|
144 |
|
---|
145 | MoleculeOrDescriptor_impl::~MoleculeOrDescriptor_impl(){
|
---|
146 | }
|
---|
147 |
|
---|
148 | bool MoleculeOrDescriptor_impl::predicate(std::pair<moleculeId_t,molecule*> molecule){
|
---|
149 | return lhs->predicate(molecule) || rhs->predicate(molecule);
|
---|
150 | }
|
---|
151 |
|
---|
152 | MoleculeDescriptor operator||(const MoleculeDescriptor &lhs, const MoleculeDescriptor &rhs){
|
---|
153 | MoleculeDescriptor::impl_ptr newImpl = MoleculeDescriptor::impl_ptr(new MoleculeOrDescriptor_impl(lhs.get_impl(),rhs.get_impl()));
|
---|
154 | return MoleculeDescriptor(newImpl);
|
---|
155 | }
|
---|
156 |
|
---|
157 | // NOT
|
---|
158 |
|
---|
159 | MoleculeNotDescriptor_impl::MoleculeNotDescriptor_impl(MoleculeDescriptor::impl_ptr _arg) :
|
---|
160 | arg(_arg)
|
---|
161 | {}
|
---|
162 |
|
---|
163 |
|
---|
164 | MoleculeNotDescriptor_impl::~MoleculeNotDescriptor_impl()
|
---|
165 | {
|
---|
166 | }
|
---|
167 |
|
---|
168 | bool MoleculeNotDescriptor_impl::predicate(std::pair<moleculeId_t,molecule*> molecule){
|
---|
169 | return !(arg->predicate(molecule));
|
---|
170 | }
|
---|
171 |
|
---|
172 | MoleculeDescriptor operator!(const MoleculeDescriptor &arg){
|
---|
173 | MoleculeDescriptor::impl_ptr newImpl = MoleculeDescriptor::impl_ptr(new MoleculeNotDescriptor_impl(arg.get_impl()));
|
---|
174 | return MoleculeDescriptor(newImpl);
|
---|
175 | }
|
---|