Chemical Data Processing Library C++ API - Version 1.4.0
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 
53  {
54 
55  public:
60  enum Relation
61  {
62 
66  ANY,
67 
73 
79 
85 
91 
97 
102  NOT_EQUAL
103  };
104 
111  MatchConstraint(unsigned int id, Relation relation):
112  id(id), relation(relation) {}
113 
121  template <typename T>
122  MatchConstraint(unsigned int id, Relation rel, T&& val):
123  id(id), relation(rel), value(std::forward<T>(val))
124  {}
125 
130  unsigned int getID() const;
131 
136  void setID(unsigned int id);
137 
143 
149 
154  const Base::Any& getValue() const;
155 
162  template <typename T>
163  const T& getValue() const
164  {
165  return value.getData<T>();
166  }
167 
172  template <typename T>
173  void setValue(T&& val)
174  {
175  value = std::forward<T>(val);
176  }
177 
182  bool hasValue() const;
183 
184  private:
185  unsigned int id;
186  Relation relation;
187  Base::Any value;
188  };
189 
197  class CDPL_CHEM_API MatchConstraintList : public Util::Array<MatchConstraint>
198  {
199 
200  public:
204  typedef std::shared_ptr<MatchConstraintList> SharedPointer;
205 
209  enum Type
210  {
211 
216 
221 
226 
230  NOT_OR_LIST
231  };
232 
237  MatchConstraintList(Type type = AND_LIST):
238  type(type) {}
239 
244  Type getType() const;
245 
250  void setType(Type type);
251 
253 
260  void addElement(unsigned int id, MatchConstraint::Relation rel);
261 
269  template <typename T>
270  void addElement(unsigned int id, MatchConstraint::Relation rel, T&& val)
271  {
272  addElement(MatchConstraint(id, rel, std::forward<T>(val)));
273  }
274 
275  private:
276  const char* getClassName() const;
277 
278  Type type;
279  };
280  } // namespace Chem
281 } // namespace CDPL
282 
283 #endif // CDPL_CHEM_MATCHCONSTRAINTLIST_HPP
Definition of class CDPL::Base::Any.
Definition of class CDPL::Util::Array.
Definition of the preprocessor macro CDPL_CHEM_API.
#define CDPL_CHEM_API
Tells the compiler/linker which classes, functions and variables are part of the library API.
Safe, type checked container for arbitrary data of variable type.
Definition: Any.hpp:60
Data structure storing a set of Chem::MatchConstraint objects together with a logical type.
Definition: MatchConstraintList.hpp:198
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:270
void addElement(unsigned int id, MatchConstraint::Relation rel)
Appends a new Chem::MatchConstraint element with the given identifier and relational constraint on th...
std::shared_ptr< MatchConstraintList > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated MatchConstraintList instances.
Definition: MatchConstraintList.hpp:204
void setType(Type type)
Sets the logical type of the match constraint list.
Type getType() const
Returns the logical type of the match constraint list.
Type
Defines constants that describe the logical type of the match constraint list.
Definition: MatchConstraintList.hpp:210
@ NOT_AND_LIST
Specifies that at least one of the match constraints must not be fulfilled.
Definition: MatchConstraintList.hpp:220
@ AND_LIST
Specifies that all of the match constraints must be fulfilled.
Definition: MatchConstraintList.hpp:215
@ OR_LIST
Specifies that at least one of the match constraints must be fulfilled.
Definition: MatchConstraintList.hpp:225
MatchConstraintList(Type type=AND_LIST)
Constructs the MatchConstraintList instance with the specified logical type.
Definition: MatchConstraintList.hpp:237
Describes a single attribute comparison constraint between a query and a target object.
Definition: MatchConstraintList.hpp:53
const Base::Any & getValue() const
Returns the value of the query attribute.
void setRelation(Relation rel)
Sets the relational constraint that must be fulfilled by the values of matching query/target attribut...
bool hasValue() const
Tells whether a query attribute value has been set.
void setValue(T &&val)
Sets the value of the query attribute.
Definition: MatchConstraintList.hpp:173
MatchConstraint(unsigned int id, Relation relation)
Constructs the MatchConstraint instance with the given identifier and relational constraint on the va...
Definition: MatchConstraintList.hpp:111
void setID(unsigned int id)
Sets the match constraint identifier to id.
Relation getRelation() const
Returns the relational constraint that must be fulfilled by the values of matching query/target attri...
unsigned int getID() const
Returns the identifier of the match constraint.
MatchConstraint(unsigned int id, Relation rel, T &&val)
Constructs the MatchConstraint instance with the given identifier, relational constraint on the value...
Definition: MatchConstraintList.hpp:122
const T & getValue() const
Returns a const reference to the value of the query attribute of type T.
Definition: MatchConstraintList.hpp:163
Relation
Defines constants for the specification of relational constraints on the values of query/target attri...
Definition: MatchConstraintList.hpp:61
@ LESS_OR_EQUAL
Specifies that the value of the query attribute must be less than or equal to the corresponding value...
Definition: MatchConstraintList.hpp:90
@ EQUAL
Specifies that the value of the query attribute must be equal to the corresponding value of the targe...
Definition: MatchConstraintList.hpp:78
@ GREATER_OR_EQUAL
Specifies that the value of the query attribute must be greater than or equal to the corresponding va...
Definition: MatchConstraintList.hpp:96
@ LESS
Specifies that the value of the query attribute must be less than the corresponding value of the targ...
Definition: MatchConstraintList.hpp:72
@ GREATER
Specifies that the value of the query attribute must be greater than the corresponding value of the t...
Definition: MatchConstraintList.hpp:84
@ ANY
Specifies that the relation between the query and target attribute value is not constrained.
Definition: MatchConstraintList.hpp:66
Dynamic array class providing amortized constant time access to arbitrary elements.
Definition: Array.hpp:92
constexpr unsigned int T
Specifies Hydrogen (Tritium).
Definition: AtomType.hpp:67
The namespace of the Chemical Data Processing Library.