Chemical Data Processing Library C++ API - Version 1.4.0
ORMatchExpressionList.hpp
Go to the documentation of this file.
1 /*
2  * ORMatchExpressionList.hpp
3  *
4  * This file is part of the Chemical Data Processing Toolkit
5  *
6  * Copyright (C) 2003 Thomas Seidel <thomas.seidel@univie.ac.at>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this library; see the file COPYING. If not, write to
20  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23 
29 #ifndef CDPL_CHEM_ORMATCHEXPRESSIONLIST_HPP
30 #define CDPL_CHEM_ORMATCHEXPRESSIONLIST_HPP
31 
32 #include <memory>
33 
35 
36 
37 namespace CDPL
38 {
39 
40  namespace Chem
41  {
42 
52  template <typename ObjType1, typename ObjType2 = void>
53  class ORMatchExpressionList : public MatchExpressionList<ObjType1, ObjType2>
54  {
55 
56  public:
60  typedef std::shared_ptr<ORMatchExpressionList> SharedPointer;
61 
73  bool operator()(const ObjType1& query_obj1, const ObjType2& query_obj2, const ObjType1& target_obj1, const ObjType2& target_obj2,
74  const Base::Any& aux_data) const;
75 
89  bool operator()(const ObjType1& query_obj1, const ObjType2& query_obj2, const ObjType1& target_obj1, const ObjType2& target_obj2,
90  const AtomBondMapping& mapping, const Base::Any& aux_data) const;
91 
92  private:
93  const char* getClassName() const
94  {
95  return "ORMatchExpressionList";
96  }
97  };
98 
106  template <typename ObjType>
107  class ORMatchExpressionList<ObjType, void> : public MatchExpressionList<ObjType, void>
108  {
109 
110  public:
114  typedef std::shared_ptr<ORMatchExpressionList> SharedPointer;
115 
125  bool operator()(const ObjType& query_obj, const ObjType& target_obj, const Base::Any& aux_data) const;
126 
138  bool operator()(const ObjType& query_obj, const ObjType& target_obj, const AtomBondMapping& mapping,
139  const Base::Any& aux_data) const;
140 
141  private:
142  const char* getClassName() const
143  {
144  return "ORMatchExpressionList";
145  }
146  };
147  } // namespace Chem
148 } // namespace CDPL
149 
150 
151 // Implementation
152 
153 template <typename ObjType1, typename ObjType2>
154 bool CDPL::Chem::ORMatchExpressionList<ObjType1, ObjType2>::operator()(const ObjType1& query_obj1, const ObjType2& query_obj2,
155  const ObjType1& target_obj1, const ObjType2& target_obj2,
156  const Base::Any& data) const
157 {
158  if (this->isEmpty())
159  return true;
160 
161  typename MatchExpressionList<ObjType1, ObjType2>::ConstElementIterator exprs_end = this->getElementsEnd();
162 
163  for (typename MatchExpressionList<ObjType1, ObjType2>::ConstElementIterator it = this->getElementsBegin(); it != exprs_end; ++it)
164  if ((*it)(query_obj1, query_obj2, target_obj1, target_obj2, data))
165  return true;
166 
167  return false;
168 }
169 
170 template <typename ObjType1, typename ObjType2>
171 bool CDPL::Chem::ORMatchExpressionList<ObjType1, ObjType2>::operator()(const ObjType1& query_obj1, const ObjType2& query_obj2,
172  const ObjType1& target_obj1, const ObjType2& target_obj2,
173  const AtomBondMapping& mapping, const Base::Any& data) const
174 {
175  if (this->isEmpty())
176  return true;
177 
178  typename MatchExpressionList<ObjType1, ObjType2>::ConstElementIterator exprs_end = this->getElementsEnd();
179 
180  for (typename MatchExpressionList<ObjType1, ObjType2>::ConstElementIterator it = this->getElementsBegin(); it != exprs_end; ++it)
181  if ((*it)(query_obj1, query_obj2, target_obj1, target_obj2, mapping, data))
182  return true;
183 
184  return false;
185 }
186 
187 
188 template <typename ObjType>
189 bool CDPL::Chem::ORMatchExpressionList<ObjType, void>::operator()(const ObjType& query_obj, const ObjType& target_obj,
190  const Base::Any& data) const
191 {
192  if (this->isEmpty())
193  return true;
194 
196 
197  for (typename MatchExpressionList<ObjType, void>::ConstElementIterator it = this->getElementsBegin(); it != exprs_end; ++it)
198  if ((*it)(query_obj, target_obj, data))
199  return true;
200 
201  return false;
202 }
203 
204 template <typename ObjType>
205 bool CDPL::Chem::ORMatchExpressionList<ObjType, void>::operator()(const ObjType& query_obj, const ObjType& target_obj,
206  const AtomBondMapping& mapping, const Base::Any& data) const
207 {
208  if (this->isEmpty())
209  return true;
210 
211  typename MatchExpressionList<ObjType, void>::ConstElementIterator exprs_end = this->getElementsEnd();
212 
213  for (typename MatchExpressionList<ObjType, void>::ConstElementIterator it = this->getElementsBegin(); it != exprs_end; ++it)
214  if ((*it)(query_obj, target_obj, mapping, data))
215  return true;
216 
217  return false;
218 }
219 
220 #endif // CDPL_CHEM_ORMATCHEXPRESSIONLIST_HPP
Definition of class CDPL::Chem::MatchExpressionList.
Safe, type checked container for arbitrary data of variable type.
Definition: Any.hpp:60
Data structure for the common storage of related atom to atom and bond to bond mappings.
Definition: AtomBondMapping.hpp:55
Container for the storage and evaluation of logical match expression lists.
Definition: MatchExpressionList.hpp:61
std::shared_ptr< ORMatchExpressionList > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated ORMatchExpressionList instances.
Definition: ORMatchExpressionList.hpp:114
Chem::MatchExpressionList specialization that evaluates the stored expressions as a logical disjuncti...
Definition: ORMatchExpressionList.hpp:54
bool operator()(const ObjType1 &query_obj1, const ObjType2 &query_obj2, const ObjType1 &target_obj1, const ObjType2 &target_obj2, const Base::Any &aux_data) const
Performs an evaluation of the disjunctive expression list for the given query and target objects.
Definition: ORMatchExpressionList.hpp:154
std::shared_ptr< ORMatchExpressionList > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated ORMatchExpressionList instances.
Definition: ORMatchExpressionList.hpp:60
StorageType::const_iterator ConstElementIterator
A constant random access iterator used to iterate over the elements of the array.
Definition: Array.hpp:125
bool isEmpty() const
Tells whether the array is empty (getSize() == 0).
Definition: Array.hpp:716
ConstElementIterator getElementsBegin() const
Returns a constant iterator over the pointed-to objects that points to the beginning of the array.
Definition: IndirectArray.hpp:448
ConstElementIterator getElementsEnd() const
Returns a constant iterator over the pointed-to objects that points to the end of the array.
Definition: IndirectArray.hpp:462
The namespace of the Chemical Data Processing Library.