| 1 |
tim |
2366 |
/* |
| 2 |
|
|
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
| 3 |
|
|
* |
| 4 |
|
|
* The University of Notre Dame grants you ("Licensee") a |
| 5 |
|
|
* non-exclusive, royalty free, license to use, modify and |
| 6 |
|
|
* redistribute this software in source and binary code form, provided |
| 7 |
|
|
* that the following conditions are met: |
| 8 |
|
|
* |
| 9 |
|
|
* 1. Acknowledgement of the program authors must be made in any |
| 10 |
|
|
* publication of scientific results based in part on use of the |
| 11 |
|
|
* program. An acceptable form of acknowledgement is citation of |
| 12 |
|
|
* the article in which the program was described (Matthew |
| 13 |
|
|
* A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher |
| 14 |
|
|
* J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented |
| 15 |
|
|
* Parallel Simulation Engine for Molecular Dynamics," |
| 16 |
|
|
* J. Comput. Chem. 26, pp. 252-271 (2005)) |
| 17 |
|
|
* |
| 18 |
|
|
* 2. Redistributions of source code must retain the above copyright |
| 19 |
|
|
* notice, this list of conditions and the following disclaimer. |
| 20 |
|
|
* |
| 21 |
|
|
* 3. Redistributions in binary form must reproduce the above copyright |
| 22 |
|
|
* notice, this list of conditions and the following disclaimer in the |
| 23 |
|
|
* documentation and/or other materials provided with the |
| 24 |
|
|
* distribution. |
| 25 |
|
|
* |
| 26 |
|
|
* This software is provided "AS IS," without a warranty of any |
| 27 |
|
|
* kind. All express or implied conditions, representations and |
| 28 |
|
|
* warranties, including any implied warranty of merchantability, |
| 29 |
|
|
* fitness for a particular purpose or non-infringement, are hereby |
| 30 |
|
|
* excluded. The University of Notre Dame and its licensors shall not |
| 31 |
|
|
* be liable for any damages suffered by licensee as a result of |
| 32 |
|
|
* using, modifying or distributing the software or its |
| 33 |
|
|
* derivatives. In no event will the University of Notre Dame or its |
| 34 |
|
|
* licensors be liable for any lost revenue, profit or data, or for |
| 35 |
|
|
* direct, indirect, special, consequential, incidental or punitive |
| 36 |
|
|
* damages, however caused and regardless of the theory of liability, |
| 37 |
|
|
* arising out of the use of or inability to use software, even if the |
| 38 |
|
|
* University of Notre Dame has been advised of the possibility of |
| 39 |
|
|
* such damages. |
| 40 |
|
|
*/ |
| 41 |
|
|
|
| 42 |
|
|
#ifndef IO_PARAMCONSTRAINT_HPP
|
| 43 |
|
|
#define IO_PARAMCONSTRAINT_HPP
|
| 44 |
|
|
|
| 45 |
|
|
/**
|
| 46 |
|
|
* This class allows to recognize constraint predicates, so that they can be combined using
|
| 47 |
|
|
* composition operators. Every constraint predicate must be derived from this class
|
| 48 |
|
|
*/
|
| 49 |
|
|
template<typename Derived>
|
| 50 |
|
|
struct ParamConstraintFacade {
|
| 51 |
|
|
};
|
| 52 |
|
|
|
| 53 |
|
|
|
| 54 |
|
|
struct NonConstraint : public ParamConstraintFacade<NonConstraint>{
|
| 55 |
|
|
template<typename DataType>
|
| 56 |
|
|
bool operator()( DataType data ) const {
|
| 57 |
|
|
return true;
|
| 58 |
|
|
}
|
| 59 |
|
|
};
|
| 60 |
|
|
|
| 61 |
|
|
struct NotEmptyConstraint : public ParamConstraintFacade<NotEmptyConstraint>{
|
| 62 |
|
|
bool operator()( const std::string data ) const {
|
| 63 |
|
|
return !data.empty();
|
| 64 |
|
|
}
|
| 65 |
|
|
};
|
| 66 |
|
|
|
| 67 |
|
|
struct ZeroConstraint : public ParamConstraintFacade<ZeroConstraint>{
|
| 68 |
|
|
template<typename DataType>
|
| 69 |
|
|
bool operator()( DataType data ) const
|
| 70 |
|
|
{
|
| 71 |
|
|
return data == 0;
|
| 72 |
|
|
}
|
| 73 |
|
|
};
|
| 74 |
|
|
|
| 75 |
|
|
struct NotZeroConstraint : public ParamConstraintFacade<NotZeroConstraint>{
|
| 76 |
|
|
template<typename DataType>
|
| 77 |
|
|
bool operator()( DataType data ) const
|
| 78 |
|
|
{
|
| 79 |
|
|
return data != 0;
|
| 80 |
|
|
}
|
| 81 |
|
|
};
|
| 82 |
|
|
|
| 83 |
|
|
struct PositiveConstraint : public ParamConstraintFacade<PositiveConstraint>{
|
| 84 |
|
|
template<typename DataType>
|
| 85 |
|
|
bool operator()( DataType data ) const
|
| 86 |
|
|
{
|
| 87 |
|
|
return data > 0;
|
| 88 |
|
|
}
|
| 89 |
|
|
};
|
| 90 |
|
|
|
| 91 |
|
|
struct NotPositiveConstraint : public ParamConstraintFacade<NotPositiveConstraint>{
|
| 92 |
|
|
template<typename DataType>
|
| 93 |
|
|
bool operator()( DataType data ) const
|
| 94 |
|
|
{
|
| 95 |
|
|
return data <= 0;
|
| 96 |
|
|
}
|
| 97 |
|
|
};
|
| 98 |
|
|
struct NotNegativeConstraint : public ParamConstraintFacade<NotNegativeConstraint>{
|
| 99 |
|
|
template<typename DataType>
|
| 100 |
|
|
bool operator()( DataType data ) const
|
| 101 |
|
|
{
|
| 102 |
|
|
return data >= 0;
|
| 103 |
|
|
}
|
| 104 |
|
|
};
|
| 105 |
|
|
|
| 106 |
|
|
struct NegativeConstraint : public ParamConstraintFacade<NegativeConstraint>{
|
| 107 |
|
|
template<typename DataType>
|
| 108 |
|
|
bool operator()( DataType data ) const
|
| 109 |
|
|
{
|
| 110 |
|
|
return data < 0;
|
| 111 |
|
|
}
|
| 112 |
|
|
};
|
| 113 |
|
|
|
| 114 |
|
|
struct NotNegativeConstraint : public ParamConstraintFacade<NotNegativeConstraint>{
|
| 115 |
|
|
template<typename DataType>
|
| 116 |
|
|
bool operator()( DataType data ) const
|
| 117 |
|
|
{
|
| 118 |
|
|
return true;
|
| 119 |
|
|
}
|
| 120 |
|
|
};
|
| 121 |
|
|
|
| 122 |
|
|
template<typename T>
|
| 123 |
|
|
struct LessThanConstraint : public ParamConstraintFacade<LessThanConstraint> {
|
| 124 |
|
|
|
| 125 |
|
|
LessThanConstraint(T rhs) : rhs_(rhs){}
|
| 126 |
|
|
template<typename DataType>
|
| 127 |
|
|
bool operator()( DataType data ) const {
|
| 128 |
|
|
return data < rhs_;
|
| 129 |
|
|
}
|
| 130 |
|
|
private:
|
| 131 |
|
|
T rhs_;
|
| 132 |
|
|
};
|
| 133 |
|
|
|
| 134 |
|
|
template<typename T>
|
| 135 |
|
|
struct LessEqualConstraint : public ParamConstraintFacade<LessEqualConstraint> {
|
| 136 |
|
|
|
| 137 |
|
|
LessEqualConstraint(T rhs) : rhs_(rhs){}
|
| 138 |
|
|
template<typename DataType>
|
| 139 |
|
|
bool operator()( DataType data ) const {
|
| 140 |
|
|
return data <= rhs_;
|
| 141 |
|
|
}
|
| 142 |
|
|
private:
|
| 143 |
|
|
T rhs_;
|
| 144 |
|
|
};
|
| 145 |
|
|
|
| 146 |
|
|
template<typename T>
|
| 147 |
|
|
struct EqualConstraint : public ParamConstraintFacade<EqualConstraint> {
|
| 148 |
|
|
|
| 149 |
|
|
EqualConstraint(T rhs) : rhs_(rhs){}
|
| 150 |
|
|
template<typename DataType>
|
| 151 |
|
|
bool operator()( DataType data ) const {
|
| 152 |
|
|
return data == rhs_;
|
| 153 |
|
|
}
|
| 154 |
|
|
private:
|
| 155 |
|
|
T rhs_;
|
| 156 |
|
|
};
|
| 157 |
|
|
|
| 158 |
|
|
// class_and composition predicate
|
| 159 |
|
|
template<typename Cons1T, typename Cons2T>
|
| 160 |
|
|
struct AndParamConstraint:
|
| 161 |
|
|
public ParamConstraintFacade< AndParamConstraint<Cons1T,Cons2T> > {
|
| 162 |
|
|
public:
|
| 163 |
|
|
|
| 164 |
|
|
AndParamConstraint( Cons1T cons1, Cons2T cons2 ) :
|
| 165 |
|
|
cons1_(cons1, cons2_(cons2) {}
|
| 166 |
|
|
|
| 167 |
|
|
template<typename DataType>
|
| 168 |
|
|
bool operator()( DataType data ) const {
|
| 169 |
|
|
return cons1_(data) && cons2_(data);
|
| 170 |
|
|
}
|
| 171 |
|
|
|
| 172 |
|
|
private:
|
| 173 |
|
|
Cons1T cons1_;
|
| 174 |
|
|
Cons2T cons2_;
|
| 175 |
|
|
};
|
| 176 |
|
|
|
| 177 |
|
|
|
| 178 |
|
|
|
| 179 |
|
|
template<typename Cons1T, typename Cons2T>
|
| 180 |
|
|
struct OrParamConstraint:
|
| 181 |
|
|
public ParamConstraintFacade< OrParamConstraint<Cons1T,Cons2T> > {
|
| 182 |
|
|
public:
|
| 183 |
|
|
|
| 184 |
|
|
|
| 185 |
|
|
OrParamConstraint( Cons1T cons1, Cons2T cons2 ) :
|
| 186 |
|
|
cons1_(cons1, cons2_(cons2) {}
|
| 187 |
|
|
|
| 188 |
|
|
template<typename DataType>
|
| 189 |
|
|
bool operator()( DataType data ) const {
|
| 190 |
|
|
return cons1_(data) || cons2_(data);
|
| 191 |
|
|
}
|
| 192 |
|
|
|
| 193 |
|
|
private:
|
| 194 |
|
|
Cons1T cons1_;
|
| 195 |
|
|
Cons2T cons2_;
|
| 196 |
|
|
};
|
| 197 |
|
|
|
| 198 |
|
|
template<typename ConsT>
|
| 199 |
|
|
struct NotParamConstraint:
|
| 200 |
|
|
public ParamConstraintFacade< NotParamConstraint<ConsT> >
|
| 201 |
|
|
{
|
| 202 |
|
|
public:
|
| 203 |
|
|
|
| 204 |
|
|
|
| 205 |
|
|
NotParamConstraint( ConsT cons) :
|
| 206 |
|
|
cons_(cons) {}
|
| 207 |
|
|
|
| 208 |
|
|
template<typename DataType>
|
| 209 |
|
|
bool operator()( DataType data ) const {
|
| 210 |
|
|
return !cons_(data);
|
| 211 |
|
|
}
|
| 212 |
|
|
|
| 213 |
|
|
private:
|
| 214 |
|
|
ConsT cons_;
|
| 215 |
|
|
};
|
| 216 |
|
|
|
| 217 |
|
|
|
| 218 |
|
|
template<typename Cons1T, typename Cons2T>
|
| 219 |
|
|
inline AndParamConstraint<Cons1T, Cons2T>
|
| 220 |
|
|
operator &&(const ParamConstraintFacade<Cons1T>& cons1, const ParamConstraintFacade<Cons2T>& cons2 ) {
|
| 221 |
|
|
|
| 222 |
|
|
return AndParamConstraint<Cons1T,Cons2T>(
|
| 223 |
|
|
*static_cast<const Cons1T*>(&cons1),
|
| 224 |
|
|
*static_cast<const Cons2T*>(&cons2) );
|
| 225 |
|
|
}
|
| 226 |
|
|
|
| 227 |
|
|
template<typename Cons1T, typename Cons2T>
|
| 228 |
|
|
inline OrParamConstraint<Cons1T, Cons2T>
|
| 229 |
|
|
operator ||( const ParamConstraintFacade<Cons1T>& cons1, const ParamConstraintFacade<Cons2T>& cons2 ) {
|
| 230 |
|
|
|
| 231 |
|
|
return OrParamConstraint<Cons1T,Cons2T>(
|
| 232 |
|
|
*static_cast<const Cons1T*>(&cons1),
|
| 233 |
|
|
*static_cast<const Cons2T*>(&cons2) );
|
| 234 |
|
|
}
|
| 235 |
|
|
|
| 236 |
|
|
|
| 237 |
|
|
template<typename ConsT>
|
| 238 |
|
|
inline NotParamConstraint<ConsT>
|
| 239 |
|
|
operator !( const ParamConstraintFacade<ConsT>& cons ) {
|
| 240 |
|
|
|
| 241 |
|
|
return NotParamConstraint<ConsT>(*static_cast<const ConsT*>(&cons));
|
| 242 |
|
|
}
|
| 243 |
|
|
|
| 244 |
|
|
|
| 245 |
|
|
|
| 246 |
|
|
#endif
|