Chemical Data Processing Library C++ API - Version 1.1.1
MatchConstraintList.hpp
Go to the documentation of this file.
1 /*
2  * MatchConstraintList.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_MATCHCONSTRAINTLIST_HPP
30 #define CDPL_CHEM_MATCHCONSTRAINTLIST_HPP
31 
32 #include <utility>
33 #include <memory>
34 
35 #include "CDPL/Chem/APIPrefix.hpp"
36 #include "CDPL/Base/Any.hpp"
37 #include "CDPL/Util/Array.hpp"
38 
39 
40 namespace CDPL
41 {
42 
43  namespace Chem
44  {
45 
50  {
51 
52  public:
57  enum Relation
58  {
59 
63  ANY,
64 
70 
76 
82 
88 
94 
99  NOT_EQUAL
100  };
101 
108  MatchConstraint(unsigned int id, Relation relation):
109  id(id), relation(relation) {}
110 
118  template <typename T>
119  MatchConstraint(unsigned int id, Relation rel, T&& val):
120  id(id), relation(rel), value(std::forward<T>(val))
121  {}
122 
127  unsigned int getID() const;
128 
133  void setID(unsigned int id);
134 
140 
146 
151  const Base::Any& getValue() const;
152 
159  template <typename T>
160  const T& getValue() const
161  {
162  return value.getData<T>();
163  }
164 
169  template <typename T>
170  void setValue(T&& val)
171  {
172  value = std::forward<T>(val);
173  }
174 
179  bool hasValue() const;
180 
181  private:
182  unsigned int id;
183  Relation relation;
184  Base::Any value;
185  };
186 
190  class CDPL_CHEM_API MatchConstraintList : public Util::Array<MatchConstraint>
191  {
192 
193  public:
197  typedef std::shared_ptr<MatchConstraintList> SharedPointer;
198 
202  enum Type
203  {
204 
209 
214 
219 
223  NOT_OR_LIST
224  };
225 
230  MatchConstraintList(Type type = AND_LIST):
231  type(type) {}
232 
237  Type getType() const;
238 
243  void setType(Type type);
244 
246 
253  void addElement(unsigned int id, MatchConstraint::Relation rel);
254 
262  template <typename T>
263  void addElement(unsigned int id, MatchConstraint::Relation rel, T&& val)
264  {
265  addElement(MatchConstraint(id, rel, std::forward<T>(val)));
266  }
267 
268  private:
269  const char* getClassName() const;
270 
271  Type type;
272  };
273  } // namespace Chem
274 } // namespace CDPL
275 
276 #endif // CDPL_CHEM_MATCHCONSTRAINTLIST_HPP
APIPrefix.hpp
Definition of the preprocessor macro CDPL_CHEM_API.
CDPL_CHEM_API
#define CDPL_CHEM_API
Tells the compiler/linker which classes, functions and variables are part of the library API.
CDPL::Chem::MatchConstraint::Relation
Relation
Defines constants for the specification of relational constraints on the values of query/target attri...
Definition: MatchConstraintList.hpp:58
CDPL::Chem::MatchConstraint::hasValue
bool hasValue() const
Tells wether a query attribute value has been set.
CDPL::Chem::MatchConstraint::setValue
void setValue(T &&val)
Sets the value of the query attribute.
Definition: MatchConstraintList.hpp:170
CDPL::Chem::MatchConstraint::LESS_OR_EQUAL
@ LESS_OR_EQUAL
Specifies that the value of the query attribute must be less than or equal to the corresponding value...
Definition: MatchConstraintList.hpp:87
CDPL::Chem::MatchConstraintList::SharedPointer
std::shared_ptr< MatchConstraintList > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated MatchConstraintList instances.
Definition: MatchConstraintList.hpp:197
CDPL::Util::Array
A dynamic array class providing amortized constant time access to arbitrary elements.
Definition: Array.hpp:92
CDPL::Chem::MatchConstraint::EQUAL
@ EQUAL
Specifies that the value of the query attribute must be equal to the corresponding value of the targe...
Definition: MatchConstraintList.hpp:75
CDPL::Chem::MatchConstraintList::getType
Type getType() const
Returns the logical type of the match constraint list.
CDPL::Chem::MatchConstraintList::OR_LIST
@ OR_LIST
Specifies that at least one of the match constraints must be fulfilled.
Definition: MatchConstraintList.hpp:218
CDPL::Chem::MatchConstraint::LESS
@ LESS
Specifies that the value of the query attribute must be less than the corresponding value of the targ...
Definition: MatchConstraintList.hpp:69
Array.hpp
Definition of the class CDPL::Util::Array.
CDPL::Chem::MatchConstraint::MatchConstraint
MatchConstraint(unsigned int id, Relation rel, T &&val)
Constructs a MatchConstraint object with the given identifier, relational constraint on the values of...
Definition: MatchConstraintList.hpp:119
CDPL::Base::Any
A safe, type checked container for arbitrary data of variable type.
Definition: Any.hpp:59
CDPL::Chem::MatchConstraintList::Type
Type
Defines constants that describe the logical type of the match constraint list.
Definition: MatchConstraintList.hpp:203
CDPL::Chem::MatchConstraint::getValue
const Base::Any & getValue() const
Returns the value of the query attribute.
CDPL::Chem::MatchConstraintList
MatchConstraintList.
Definition: MatchConstraintList.hpp:191
CDPL::Chem::AtomType::T
const unsigned int T
Specifies Hydrogen (Tritium).
Definition: AtomType.hpp:67
CDPL::Chem::MatchConstraint::GREATER
@ GREATER
Specifies that the value of the query attribute must be greater than the corresponding value of the t...
Definition: MatchConstraintList.hpp:81
CDPL
The namespace of the Chemical Data Processing Library.
CDPL::Chem::MatchConstraint
MatchConstraint.
Definition: MatchConstraintList.hpp:50
CDPL::Chem::MatchConstraintList::addElement
void addElement(unsigned int id, MatchConstraint::Relation rel, T &&val)
Appends a new Chem::MatchConstraint element with the given identifier, relational constraint on the v...
Definition: MatchConstraintList.hpp:263
CDPL::Chem::MatchConstraintList::AND_LIST
@ AND_LIST
Specifies that all of the match constraints must be fulfilled.
Definition: MatchConstraintList.hpp:208
CDPL::Chem::MatchConstraint::MatchConstraint
MatchConstraint(unsigned int id, Relation relation)
Constructs a MatchConstraint object with the given identifier and relational constraint on the values...
Definition: MatchConstraintList.hpp:108
CDPL::Chem::MatchConstraint::getID
unsigned int getID() const
Returns the identifier of the match constraint.
CDPL::Chem::MatchConstraint::GREATER_OR_EQUAL
@ GREATER_OR_EQUAL
Specifies that the value of the query attribute must be greater than or equal to the corresponding va...
Definition: MatchConstraintList.hpp:93
CDPL::Chem::MatchConstraint::setRelation
void setRelation(Relation rel)
Sets the relational constraint that must be fulfilled by the values of matching query/target attribut...
CDPL::Chem::MatchConstraint::ANY
@ ANY
Specifies that the relation between the query and target attribute value is not constrained.
Definition: MatchConstraintList.hpp:63
CDPL::Chem::MatchConstraintList::MatchConstraintList
MatchConstraintList(Type type=AND_LIST)
Constructs a MatchConstraintList object with the specified logical type.
Definition: MatchConstraintList.hpp:230
CDPL::Chem::MatchConstraintList::NOT_AND_LIST
@ NOT_AND_LIST
Specifies that at least one of the match constraints must not be fulfilled.
Definition: MatchConstraintList.hpp:213
Any.hpp
Definition of the class CDPL::Base::Any.
CDPL::Chem::MatchConstraint::getRelation
Relation getRelation() const
Returns the relational constraint that must be fulfilled by the values of matching query/target attri...
CDPL::Chem::MatchConstraint::setID
void setID(unsigned int id)
Sets the match constraint identifier to id.
CDPL::Chem::MatchConstraint::getValue
const T & getValue() const
Returns a const reference to the value of the query attribute of type T.
Definition: MatchConstraintList.hpp:160
CDPL::Chem::MatchConstraintList::setType
void setType(Type type)
Sets the logical type of the match constraint list.
CDPL::Chem::MatchConstraintList::addElement
void addElement(unsigned int id, MatchConstraint::Relation rel)
Appends a new Chem::MatchConstraint element with the given identifier and relational constraint on th...