Chemical Data Processing Library C++ API - Version 1.2.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 
49  template <typename ObjType1, typename ObjType2 = void>
50  class ANDMatchExpressionList : public MatchExpressionList<ObjType1, ObjType2>
51  {
52 
53  public:
57  typedef std::shared_ptr<ANDMatchExpressionList> SharedPointer;
58 
70  bool operator()(const ObjType1& query_obj1, const ObjType2& query_obj2, const ObjType1& target_obj1, const ObjType2& target_obj2,
71  const Base::Any& aux_data) const;
72 
86  bool operator()(const ObjType1& query_obj1, const ObjType2& query_obj2, const ObjType1& target_obj1, const ObjType2& target_obj2,
87  const AtomBondMapping& mapping, const Base::Any& aux_data) const;
88 
89  private:
90  const char* getClassName() const
91  {
92  return "ANDMatchExpressionList";
93  }
94  };
95 
100  template <typename ObjType>
101  class ANDMatchExpressionList<ObjType, void> : public MatchExpressionList<ObjType, void>
102  {
103 
104  public:
108  typedef std::shared_ptr<ANDMatchExpressionList> SharedPointer;
109 
119  bool operator()(const ObjType& query_obj, const ObjType& target_obj, const Base::Any& aux_data) const;
120 
132  bool operator()(const ObjType& query_obj, const ObjType& target_obj, const AtomBondMapping& mapping,
133  const Base::Any& aux_data) const;
134 
135  private:
136  const char* getClassName() const
137  {
138  return "ANDMatchExpressionList";
139  }
140  };
141  } // namespace Chem
142 } // namespace CDPL
143 
144 
145 // Implementation
146 
147 template <typename ObjType1, typename ObjType2>
148 bool CDPL::Chem::ANDMatchExpressionList<ObjType1, ObjType2>::operator()(const ObjType1& query_obj1, const ObjType2& query_obj2,
149  const ObjType1& target_obj1, const ObjType2& target_obj2,
150  const Base::Any& data) const
151 {
152  typename MatchExpressionList<ObjType1, ObjType2>::ConstElementIterator exprs_end = this->getElementsEnd();
153 
154  for (typename MatchExpressionList<ObjType1, ObjType2>::ConstElementIterator it = this->getElementsBegin(); it != exprs_end; ++it)
155  if (!(*it)(query_obj1, query_obj2, target_obj1, target_obj2, data))
156  return false;
157 
158  return true;
159 }
160 
161 template <typename ObjType1, typename ObjType2>
162 bool CDPL::Chem::ANDMatchExpressionList<ObjType1, ObjType2>::operator()(const ObjType1& query_obj1, const ObjType2& query_obj2,
163  const ObjType1& target_obj1, const ObjType2& target_obj2,
164  const AtomBondMapping& mapping, const Base::Any& data) const
165 {
166  typename MatchExpressionList<ObjType1, ObjType2>::ConstElementIterator exprs_end = this->getElementsEnd();
167 
168  for (typename MatchExpressionList<ObjType1, ObjType2>::ConstElementIterator it = this->getElementsBegin(); it != exprs_end; ++it)
169  if (!(*it)(query_obj1, query_obj2, target_obj1, target_obj2, mapping, data))
170  return false;
171 
172  return true;
173 }
174 
175 
176 template <typename ObjType>
177 bool CDPL::Chem::ANDMatchExpressionList<ObjType, void>::operator()(const ObjType& query_obj, const ObjType& target_obj,
178  const Base::Any& data) const
179 {
181 
182  for (typename MatchExpressionList<ObjType, void>::ConstElementIterator it = this->getElementsBegin(); it != exprs_end; ++it)
183  if (!(*it)(query_obj, target_obj, data))
184  return false;
185 
186  return true;
187 }
188 
189 template <typename ObjType>
190 bool CDPL::Chem::ANDMatchExpressionList<ObjType, void>::operator()(const ObjType& query_obj, const ObjType& target_obj,
191  const AtomBondMapping& mapping, const Base::Any& data) const
192 {
193  typename MatchExpressionList<ObjType, void>::ConstElementIterator exprs_end = this->getElementsEnd();
194 
195  for (typename MatchExpressionList<ObjType, void>::ConstElementIterator it = this->getElementsBegin(); it != exprs_end; ++it)
196  if (!(*it)(query_obj, target_obj, mapping, data))
197  return false;
198 
199  return true;
200 }
201 
202 #endif // CDPL_CHEM_ANDMATCHEXPRESSIONLIST_HPP
Definition of the class CDPL::Chem::MatchExpressionList.
A safe, type checked container for arbitrary data of variable type.
Definition: Any.hpp:59
std::shared_ptr< ANDMatchExpressionList > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated ANDMatchExpressionList instances.
Definition: ANDMatchExpressionList.hpp:108
ANDMatchExpressionList.
Definition: ANDMatchExpressionList.hpp:51
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:148
std::shared_ptr< ANDMatchExpressionList > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated ANDMatchExpressionList instances.
Definition: ANDMatchExpressionList.hpp:57
A data structure for the common storage of related atom to atom and bond to bond mappings.
Definition: AtomBondMapping.hpp:55
A 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.