Chemical Data Processing Library C++ API - Version 1.1.1
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 
49  template <typename ObjType1, typename ObjType2 = void>
50  class ORMatchExpressionList : public MatchExpressionList<ObjType1, ObjType2>
51  {
52 
53  public:
57  typedef std::shared_ptr<ORMatchExpressionList> 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 "ORMatchExpressionList";
93  }
94  };
95 
100  template <typename ObjType>
101  class ORMatchExpressionList<ObjType, void> : public MatchExpressionList<ObjType, void>
102  {
103 
104  public:
108  typedef std::shared_ptr<ORMatchExpressionList> 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 "ORMatchExpressionList";
139  }
140  };
141  } // namespace Chem
142 } // namespace CDPL
143 
144 
145 // Implementation
146 
147 template <typename ObjType1, typename ObjType2>
148 bool CDPL::Chem::ORMatchExpressionList<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  if (this->isEmpty())
153  return true;
154 
155  typename MatchExpressionList<ObjType1, ObjType2>::ConstElementIterator exprs_end = this->getElementsEnd();
156 
157  for (typename MatchExpressionList<ObjType1, ObjType2>::ConstElementIterator it = this->getElementsBegin(); it != exprs_end; ++it)
158  if ((*it)(query_obj1, query_obj2, target_obj1, target_obj2, data))
159  return true;
160 
161  return false;
162 }
163 
164 template <typename ObjType1, typename ObjType2>
165 bool CDPL::Chem::ORMatchExpressionList<ObjType1, ObjType2>::operator()(const ObjType1& query_obj1, const ObjType2& query_obj2,
166  const ObjType1& target_obj1, const ObjType2& target_obj2,
167  const AtomBondMapping& mapping, const Base::Any& data) const
168 {
169  if (this->isEmpty())
170  return true;
171 
172  typename MatchExpressionList<ObjType1, ObjType2>::ConstElementIterator exprs_end = this->getElementsEnd();
173 
174  for (typename MatchExpressionList<ObjType1, ObjType2>::ConstElementIterator it = this->getElementsBegin(); it != exprs_end; ++it)
175  if ((*it)(query_obj1, query_obj2, target_obj1, target_obj2, mapping, data))
176  return true;
177 
178  return false;
179 }
180 
181 
182 template <typename ObjType>
183 bool CDPL::Chem::ORMatchExpressionList<ObjType, void>::operator()(const ObjType& query_obj, const ObjType& target_obj,
184  const Base::Any& data) const
185 {
186  if (this->isEmpty())
187  return true;
188 
190 
191  for (typename MatchExpressionList<ObjType, void>::ConstElementIterator it = this->getElementsBegin(); it != exprs_end; ++it)
192  if ((*it)(query_obj, target_obj, data))
193  return true;
194 
195  return false;
196 }
197 
198 template <typename ObjType>
199 bool CDPL::Chem::ORMatchExpressionList<ObjType, void>::operator()(const ObjType& query_obj, const ObjType& target_obj,
200  const AtomBondMapping& mapping, const Base::Any& data) const
201 {
202  if (this->isEmpty())
203  return true;
204 
205  typename MatchExpressionList<ObjType, void>::ConstElementIterator exprs_end = this->getElementsEnd();
206 
207  for (typename MatchExpressionList<ObjType, void>::ConstElementIterator it = this->getElementsBegin(); it != exprs_end; ++it)
208  if ((*it)(query_obj, target_obj, mapping, data))
209  return true;
210 
211  return false;
212 }
213 
214 #endif // CDPL_CHEM_ORMATCHEXPRESSIONLIST_HPP
CDPL::Chem::ORMatchExpressionList::operator()
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:148
CDPL::Util::IndirectArray< MatchExpression< ObjType1, void > >::getElementsBegin
ConstElementIterator getElementsBegin() const
Returns a constant iterator over the pointed-to objects that points to the beginning of the array.
Definition: IndirectArray.hpp:448
CDPL::Chem::ORMatchExpressionList::SharedPointer
std::shared_ptr< ORMatchExpressionList > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated ORMatchExpressionList instances.
Definition: ORMatchExpressionList.hpp:57
CDPL::Base::Any
A safe, type checked container for arbitrary data of variable type.
Definition: Any.hpp:59
CDPL::Chem::ORMatchExpressionList< ObjType, void >::SharedPointer
std::shared_ptr< ORMatchExpressionList > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated ORMatchExpressionList instances.
Definition: ORMatchExpressionList.hpp:108
CDPL::Util::IndirectArray< MatchExpression< ObjType1, void > >::getElementsEnd
ConstElementIterator getElementsEnd() const
Returns a constant iterator over the pointed-to objects that points to the end of the array.
Definition: IndirectArray.hpp:462
CDPL::Util::Array< typename ValueType::SharedPointer >::ConstElementIterator
StorageType::const_iterator ConstElementIterator
A constant random access iterator used to iterate over the elements of the array.
Definition: Array.hpp:125
CDPL::Util::Array< typename ValueType::SharedPointer >::isEmpty
bool isEmpty() const
Tells whether the array is empty (getSize() == 0).
Definition: Array.hpp:708
CDPL::Chem::ORMatchExpressionList
ORMatchExpressionList.
Definition: ORMatchExpressionList.hpp:51
CDPL::Chem::MatchExpressionList
A container for the storage and evaluation of logical match expression lists.
Definition: MatchExpressionList.hpp:61
CDPL
The namespace of the Chemical Data Processing Library.
MatchExpressionList.hpp
Definition of the class CDPL::Chem::MatchExpressionList.
CDPL::Chem::AtomBondMapping
A data structure for the common storage of related atom to atom and bond to bond mappings.
Definition: AtomBondMapping.hpp:55