Chemical Data Processing Library C++ API - Version 1.4.0
ANDMatchExpressionList.hpp
Go to the documentation of this file.
1 /*
2  * ANDMatchExpressionList.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_ANDMATCHEXPRESSIONLIST_HPP
30 #define CDPL_CHEM_ANDMATCHEXPRESSIONLIST_HPP
31 
32 #include <memory>
33 
35 
36 
37 namespace CDPL
38 {
39 
40  namespace Chem
41  {
42 
53  template <typename ObjType1, typename ObjType2 = void>
54  class ANDMatchExpressionList : public MatchExpressionList<ObjType1, ObjType2>
55  {
56 
57  public:
61  typedef std::shared_ptr<ANDMatchExpressionList> SharedPointer;
62 
74  bool operator()(const ObjType1& query_obj1, const ObjType2& query_obj2, const ObjType1& target_obj1, const ObjType2& target_obj2,
75  const Base::Any& aux_data) const;
76 
90  bool operator()(const ObjType1& query_obj1, const ObjType2& query_obj2, const ObjType1& target_obj1, const ObjType2& target_obj2,
91  const AtomBondMapping& mapping, const Base::Any& aux_data) const;
92 
93  private:
94  const char* getClassName() const
95  {
96  return "ANDMatchExpressionList";
97  }
98  };
99 
108  template <typename ObjType>
109  class ANDMatchExpressionList<ObjType, void> : public MatchExpressionList<ObjType, void>
110  {
111 
112  public:
116  typedef std::shared_ptr<ANDMatchExpressionList> SharedPointer;
117 
127  bool operator()(const ObjType& query_obj, const ObjType& target_obj, const Base::Any& aux_data) const;
128 
140  bool operator()(const ObjType& query_obj, const ObjType& target_obj, const AtomBondMapping& mapping,
141  const Base::Any& aux_data) const;
142 
143  private:
144  const char* getClassName() const
145  {
146  return "ANDMatchExpressionList";
147  }
148  };
149  } // namespace Chem
150 } // namespace CDPL
151 
152 
153 // Implementation
154 
155 template <typename ObjType1, typename ObjType2>
156 bool CDPL::Chem::ANDMatchExpressionList<ObjType1, ObjType2>::operator()(const ObjType1& query_obj1, const ObjType2& query_obj2,
157  const ObjType1& target_obj1, const ObjType2& target_obj2,
158  const Base::Any& data) const
159 {
160  typename MatchExpressionList<ObjType1, ObjType2>::ConstElementIterator exprs_end = this->getElementsEnd();
161 
162  for (typename MatchExpressionList<ObjType1, ObjType2>::ConstElementIterator it = this->getElementsBegin(); it != exprs_end; ++it)
163  if (!(*it)(query_obj1, query_obj2, target_obj1, target_obj2, data))
164  return false;
165 
166  return true;
167 }
168 
169 template <typename ObjType1, typename ObjType2>
170 bool CDPL::Chem::ANDMatchExpressionList<ObjType1, ObjType2>::operator()(const ObjType1& query_obj1, const ObjType2& query_obj2,
171  const ObjType1& target_obj1, const ObjType2& target_obj2,
172  const AtomBondMapping& mapping, const Base::Any& data) const
173 {
174  typename MatchExpressionList<ObjType1, ObjType2>::ConstElementIterator exprs_end = this->getElementsEnd();
175 
176  for (typename MatchExpressionList<ObjType1, ObjType2>::ConstElementIterator it = this->getElementsBegin(); it != exprs_end; ++it)
177  if (!(*it)(query_obj1, query_obj2, target_obj1, target_obj2, mapping, data))
178  return false;
179 
180  return true;
181 }
182 
183 
184 template <typename ObjType>
185 bool CDPL::Chem::ANDMatchExpressionList<ObjType, void>::operator()(const ObjType& query_obj, const ObjType& target_obj,
186  const Base::Any& data) const
187 {
189 
190  for (typename MatchExpressionList<ObjType, void>::ConstElementIterator it = this->getElementsBegin(); it != exprs_end; ++it)
191  if (!(*it)(query_obj, target_obj, data))
192  return false;
193 
194  return true;
195 }
196 
197 template <typename ObjType>
198 bool CDPL::Chem::ANDMatchExpressionList<ObjType, void>::operator()(const ObjType& query_obj, const ObjType& target_obj,
199  const AtomBondMapping& mapping, const Base::Any& data) const
200 {
201  typename MatchExpressionList<ObjType, void>::ConstElementIterator exprs_end = this->getElementsEnd();
202 
203  for (typename MatchExpressionList<ObjType, void>::ConstElementIterator it = this->getElementsBegin(); it != exprs_end; ++it)
204  if (!(*it)(query_obj, target_obj, mapping, data))
205  return false;
206 
207  return true;
208 }
209 
210 #endif // CDPL_CHEM_ANDMATCHEXPRESSIONLIST_HPP
Definition of class CDPL::Chem::MatchExpressionList.
Safe, type checked container for arbitrary data of variable type.
Definition: Any.hpp:60
std::shared_ptr< ANDMatchExpressionList > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated ANDMatchExpressionList instances.
Definition: ANDMatchExpressionList.hpp:116
Chem::MatchExpressionList specialization that evaluates the stored expressions as a logical conjuncti...
Definition: ANDMatchExpressionList.hpp:55
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 conjunctive expression list for the given query and target objects.
Definition: ANDMatchExpressionList.hpp:156
std::shared_ptr< ANDMatchExpressionList > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated ANDMatchExpressionList instances.
Definition: ANDMatchExpressionList.hpp:61
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
StorageType::const_iterator ConstElementIterator
A constant random access iterator used to iterate over the elements of the array.
Definition: Array.hpp:125
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.