45#ifndef IO_PARAMCONSTRAINT_HPP
46#define IO_PARAMCONSTRAINT_HPP
50#include "utils/CaseConversion.hpp"
59 template<
typename Derived>
61 std::string getConstraintDescription() {
return description_; }
64 std::string description_;
69 bool operator()(
const std::string& data)
const {
return !data.empty(); }
74 template<
typename DataType>
75 bool operator()(DataType data)
const {
83 template<
typename DataType>
84 bool operator()(DataType data)
const {
91 template<
typename DataType>
92 bool operator()(DataType data)
const {
100 template<
typename DataType>
101 bool operator()(DataType data)
const {
108 template<
typename DataType>
109 bool operator()(DataType data)
const {
117 template<
typename DataType>
118 bool operator()(DataType data)
const {
125 template<
typename DataType>
126 bool operator()(DataType data)
const {
127 return data % 2 == 0;
135 std::stringstream iss;
136 iss <<
"less than " << rhs;
137 this->description_ = iss.str();
139 template<
typename DataType>
140 bool operator()(DataType data)
const {
152 std::stringstream iss;
153 iss <<
"less than or equal to" << rhs;
154 this->description_ = iss.str();
157 template<
typename DataType>
158 bool operator()(DataType data)
const {
169 std::stringstream iss;
170 iss <<
"equal to" << rhs;
171 this->description_ = iss.str();
173 template<
typename DataType>
174 bool operator()(DataType data)
const {
185 rhs_(OpenMD::toUpperCopy(rhs)) {
186 std::stringstream iss;
187 iss <<
"equal to (case insensitive) " << rhs;
188 this->description_ = iss.str();
191 bool operator()(std::string data)
const {
192 return OpenMD::toUpperCopy(data) == rhs_;
202 std::stringstream iss;
203 iss <<
"contains " << rhs;
204 this->description_ = iss.str();
207 bool operator()(std::string data)
const {
211 if (tokenizer.
nextToken() == rhs_) {
return true; }
225 std::stringstream iss;
226 iss <<
"greater than" << rhs;
227 this->description_ = iss.str();
229 template<
typename DataType>
230 bool operator()(DataType data)
const {
242 std::stringstream iss;
243 iss <<
"greater than or equal to" << rhs;
244 this->description_ = iss.str();
246 template<
typename DataType>
247 bool operator()(DataType data)
const {
256 template<
typename Cons1T,
typename Cons2T>
261 cons1_(cons1), cons2_(cons2) {
262 std::stringstream iss;
263 iss <<
"(" << cons1_.getConstraintDescription() <<
" and "
264 << cons2_.getConstraintDescription() <<
")";
265 this->description_ = iss.str();
268 template<
typename DataType>
269 bool operator()(DataType data)
const {
270 return cons1_(data) && cons2_(data);
278 template<
typename Cons1T,
typename Cons2T>
283 cons1_(cons1), cons2_(cons2) {
284 std::stringstream iss;
285 iss << cons1_.getConstraintDescription() <<
" or "
286 << cons2_.getConstraintDescription() <<
"";
287 this->description_ = iss.str();
290 template<
typename DataType>
291 bool operator()(DataType data)
const {
292 return cons1_(data) || cons2_(data);
300 template<
typename ConsT>
305 std::stringstream iss;
306 iss <<
"(not" << cons_.getConstraintDescription() <<
")";
307 this->description_ = iss.str();
310 template<
typename DataType>
311 bool operator()(DataType data)
const {
319 template<
typename Cons1T,
typename Cons2T>
324 *
static_cast<const Cons1T*
>(&cons1),
325 *
static_cast<const Cons2T*
>(&cons2));
328 template<
typename Cons1T,
typename Cons2T>
329 inline OrParamConstraint<Cons1T, Cons2T> operator||(
330 const ParamConstraintFacade<Cons1T>& cons1,
331 const ParamConstraintFacade<Cons2T>& cons2) {
332 return OrParamConstraint<Cons1T, Cons2T>(
333 *
static_cast<const Cons1T*
>(&cons1),
334 *
static_cast<const Cons2T*
>(&cons2));
337 template<
typename ConsT>
338 inline NotParamConstraint<ConsT> operator!(
339 const ParamConstraintFacade<ConsT>& cons) {
340 return NotParamConstraint<ConsT>(*
static_cast<const ConsT*
>(&cons));
343 NotEmptyConstraint isNotEmpty();
344 ZeroConstraint isZero();
346 ParamConstraintFacade<NonZeroConstraint> isNonZero();
347 PositiveConstraint isPositive();
348 NonPositiveConstraint isNonPositive();
350 NegativeConstraint isNegative();
352 NonNegativeConstraint isNonNegative();
353 EvenConstraint isEven();
356 inline LessThanConstraint<T> isLessThan(T& v) {
357 return LessThanConstraint<T>(v);
361 inline LessThanOrEqualToConstraint<T> isLessThanOrEqualTo(T& v) {
362 return LessThanOrEqualToConstraint<T>(v);
366 inline EqualConstraint<T> isEqual(T& v) {
367 return EqualConstraint<T>(v);
371 inline GreaterThanConstraint<T> isGreaterThan(T& v) {
372 return GreaterThanConstraint<T>(v);
376 inline GreaterThanOrEqualTo<T> isGreaterThanOrEqualTo(T& v) {
377 return GreaterThanOrEqualTo<T>(v);
380 EqualIgnoreCaseConstraint isEqualIgnoreCase(std::string str);
The string tokenizer class allows an application to break a string into tokens The set of delimiters ...
std::string nextToken()
Returns the next token from this string tokenizer.
bool hasMoreTokens()
Tests if there are more tokens available from this tokenizer's string.
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
This class allows to recognize constraint predicates, so that they can be combined using composition ...