Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_StandardParameterEntryValidators.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Teuchos: Common Tools Package
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef TEUCHOS_STANDARD_PARAMETER_ENTRY_VALIDATORS_H
43 #define TEUCHOS_STANDARD_PARAMETER_ENTRY_VALIDATORS_H
44 
49 #include "Teuchos_TwoDArray.hpp"
50 #include "Teuchos_Assert.hpp"
51 #include "Teuchos_StrUtils.hpp"
54 
55 namespace Teuchos {
56 
57 
70 template<class IntegralType>
72 public:
75 
85  ArrayView<const std::string> const& strings,
86  std::string const& defaultParameterName
87  );
88 
105  ArrayView<const std::string> const& strings,
106  ArrayView<const IntegralType> const& integralValues,
107  std::string const& defaultParameterName
108  );
109 
130  ArrayView<const std::string> const& strings,
131  ArrayView<const std::string> const& stringsDocs,
132  ArrayView<const IntegralType> const& integralValues,
133  std::string const& defaultParameterName
134  );
135 
137 
140 
152  IntegralType getIntegralValue(
153  const std::string &str, const std::string &paramName = "",
154  const std::string &sublistName = ""
155  ) const;
156 
170  IntegralType getIntegralValue(
171  const ParameterEntry &entry, const std::string &paramName = "",
172  const std::string &sublistName = "", const bool activeQuery = true
173  ) const;
174 
189  std::string getStringValue(
190  const ParameterEntry &entry, const std::string &paramName = "",
191  const std::string &sublistName = "", const bool activeQuery = true
192  ) const;
193 
200  IntegralType getIntegralValue(
201  ParameterList &paramList, const std::string &paramName,
202  const std::string &defaultValue
203  ) const;
204 
208  std::string getStringValue(
209  ParameterList &paramList, const std::string &paramName,
210  const std::string &defaultValue
211  ) const;
212 
219 
224  const std::string& getDefaultParameterName() const;
225 
237  std::string validateString(
238  const std::string &str, const std::string &paramName = "",
239  const std::string &sublistName = ""
240  ) const;
241 
243 
246 
248  const std::string getXMLTypeName() const;
249 
251  void printDoc(
252  std::string const& docString,
253  std::ostream & out
254  ) const;
255 
258  validStringValues() const;
259 
261  void validate(
262  ParameterEntry const& entry,
263  std::string const& paramName,
264  std::string const& sublistName
265  ) const;
266 
268 
269 private:
270 
271  typedef std::map<std::string,IntegralType> map_t;
273  std::string validValues_;
277 
278  void setValidValues(
279  ArrayView<const std::string> const& strings,
280  ArrayView<const std::string> const* stringsDocs = NULL
281  );
282 
283  // Not defined and not to be called.
285 
286 };
287 
288 
293 template<class IntegralType>
295 stringToIntegralParameterEntryValidator(
296  ArrayView<const std::string> const& strings,
297  std::string const& defaultParameterName
298  );
299 
300 
305 template<class IntegralType>
307 stringToIntegralParameterEntryValidator(
308  ArrayView<const std::string> const& strings,
309  ArrayView<const IntegralType> const& integralValues,
310  std::string const& defaultParameterName
311  );
312 
313 
318 template<class IntegralType>
320 stringToIntegralParameterEntryValidator(
321  ArrayView<const std::string> const& strings,
322  ArrayView<const std::string> const& stringsDocs,
323  ArrayView<const IntegralType> const& integralValues,
324  std::string const& defaultParameterName
325  );
326 
337 template<class IntegralType>
338 void setStringToIntegralParameter(
339  std::string const& paramName,
340  std::string const& defaultValue,
341  std::string const& docString,
342  ArrayView<const std::string> const& strings,
343  ParameterList * paramList
344  );
345 
346 
358 template<class IntegralType>
359 void setStringToIntegralParameter(
360  std::string const& paramName,
361  std::string const& defaultValue,
362  std::string const& docString,
363  ArrayView<const std::string> const& strings,
364  ArrayView<const IntegralType> const& integralValues,
365  ParameterList * paramList
366  );
367 
368 
380 template<class IntegralType>
381 void setStringToIntegralParameter(
382  std::string const& paramName,
383  std::string const& defaultValue,
384  std::string const& docString,
385  ArrayView<const std::string> const& strings,
386  ArrayView<const std::string> const& stringsDocs,
387  ArrayView<const IntegralType> const& integralValues,
388  ParameterList * paramList
389  );
390 
391 
402 template<class IntegralType>
403 IntegralType getIntegralValue(
404  ParameterList const& paramList, std::string const& paramName
405  );
406 
407 
419 template<class IntegralType>
420 std::string getStringValue(
421  ParameterList const& paramList, std::string const& paramName
422  );
423 
424 
430 template<class IntegralType>
433  ParameterEntry const& entry, ParameterList const& paramList,
434  std::string const& paramName
435  );
436 
437 
443 std::string getVerbosityLevelParameterValueName(
444  const EVerbosityLevel verbLevel
445  );
446 
447 
453 verbosityLevelParameterEntryValidator(std::string const& defaultParameterName);
454 
460 template<class IntegralType>
462 
463 public:
464 
467 
472  getDummyObject();
473 
475 };
476 
477 template<class IntegralType>
480 {
481  return stringToIntegralParameterEntryValidator<IntegralType>(
482  tuple<std::string>(""), tuple<std::string>(""),
483  tuple<IntegralType>((IntegralType)1), "");
484 }
485 
486 
487 
502  : public ParameterEntryValidator
503 {
504 public:
505 
508 
510  enum EPreferredType { PREFER_INT, PREFER_DOUBLE, PREFER_STRING };
511 
512 
515  public:
517  AcceptedTypes( bool allowAllTypesByDefault = true )
518  :allowInt_(allowAllTypesByDefault),allowDouble_(allowAllTypesByDefault),
519  allowString_(allowAllTypesByDefault)
520  {}
522  AcceptedTypes& allowInt( bool _allowInt )
523  { allowInt_ = _allowInt; return *this; }
525  AcceptedTypes& allowDouble( bool _allowDouble )
526  { allowDouble_ = _allowDouble; return *this; }
528  AcceptedTypes& allowString( bool _allowString )
529  { allowString_ = _allowString; return *this; }
531  bool allowInt() const { return allowInt_; }
533  bool allowDouble() const { return allowDouble_; }
535  bool allowString() const { return allowString_; }
536  private:
537  bool allowInt_;
540  };
541 
543 
546 
551 
563  EPreferredType const preferredType,
564  AcceptedTypes const& acceptedTypes
565  );
566 
568 
571 
573  int getInt(
574  const ParameterEntry &entry, const std::string &paramName = "",
575  const std::string &sublistName = "", const bool activeQuery = true
576  ) const;
577 
579  double getDouble(
580  const ParameterEntry &entry, const std::string &paramName = "",
581  const std::string &sublistName = "", const bool activeQuery = true
582  ) const;
583 
585  std::string getString(
586  const ParameterEntry &entry, const std::string &paramName = "",
587  const std::string &sublistName = "", const bool activeQuery = true
588  ) const;
589 
593  int getInt(
594  ParameterList &paramList, const std::string &paramName,
595  const int defaultValue
596  ) const;
597 
601  double getDouble(
602  ParameterList &paramList, const std::string &paramName,
603  const double defaultValue
604  ) const;
605 
609  std::string getString(
610  ParameterList &paramList, const std::string &paramName,
611  const std::string &defaultValue
612  ) const;
613 
616  bool isDoubleAllowed() const;
617 
620  bool isIntAllowed() const;
621 
624  bool isStringAllowed() const;
625 
628  EPreferredType getPreferredType() const;
629 
631  static const std::string&
633  {
634  switch(enumValue){
635  case PREFER_INT:
636  return getIntEnumString();
637  break;
638  case PREFER_DOUBLE:
639  return getDoubleEnumString();
640  break;
641  case PREFER_STRING:
642  return getStringEnumString();
643  break;
644  default:
645  static const std::string typeString(toString(enumValue));
646  throw std::runtime_error("Cannot convert enumValue: " + typeString + " to a string");
647  //Should never get here. This code is here so that a warning is not generated.
648  return typeString;
649  }
650  }
651 
653  static EPreferredType getPrefferedTypeStringEnum(const std::string& enumString)
654  {
655  if(enumString == getIntEnumString()){
656  return PREFER_INT;
657  }
658  else if(enumString == getDoubleEnumString()){
659  return PREFER_DOUBLE;
660  }
661  else if(enumString == getStringEnumString()){
662  return PREFER_STRING;
663  }
664  else{
665  throw std::runtime_error("Cannot convert enumString: " + enumString + " to an enum");
666  }
667  //Should never get here. This code is here so that a warning is not generated.
668  return (EPreferredType)-1;
669  }
670 
672 
675 
677  const std::string getXMLTypeName() const;
678 
680  void printDoc(
681  std::string const& docString,
682  std::ostream & out
683  ) const;
684 
686  ValidStringsList
687  validStringValues() const;
688 
690  void validate(
691  ParameterEntry const& entry,
692  std::string const& paramName,
693  std::string const& sublistName
694  ) const;
695 
697  void validateAndModify(
698  std::string const& paramName,
699  std::string const& sublistName,
700  ParameterEntry * entry
701  ) const;
702 
703 
705 
706 private:
707 
708  // ////////////////////////////
709  // Private data members
710 
712  std::string acceptedTypesString_;
713 
714 //use pragmas to disable some false-positive warnings for windows sharedlibs export
715 #ifdef _MSC_VER
716 #pragma warning(push)
717 #pragma warning(disable:4251)
718 #endif
720 #ifdef _MSC_VER
721 #pragma warning(pop)
722 #endif
723 
724  // ////////////////////////////
725  // Private member functions
726 
727  /* \brief Gets the string representing the "int" preferred type enum */
728  static const std::string& getIntEnumString(){
729  static const std::string intEnumString_ = TypeNameTraits<int>::name();
730  return intEnumString_;
731  }
732 
733  /* \brief Gets the string representing the "double" preferred type enum */
734  static const std::string& getDoubleEnumString(){
735  static const std::string doubleEnumString_ = TypeNameTraits<double>::name();
736  return doubleEnumString_;
737  }
738 
739  /* \brief Gets the string representing the "string" preferred type enum */
740  static const std::string& getStringEnumString(){
741  static const std::string stringEnumString_ = TypeNameTraits<std::string>::name();
742  return stringEnumString_;
743  }
744 
745 
746  void finishInitialization();
747 
748  void throwTypeError(
749  ParameterEntry const& entry,
750  std::string const& paramName,
751  std::string const& sublistName
752  ) const;
753 
754 };
755 
756 
757 // Nonmember helper functions
758 
759 
764 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT RCP<AnyNumberParameterEntryValidator>
765 anyNumberParameterEntryValidator();
766 
767 
772 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT RCP<AnyNumberParameterEntryValidator>
773 anyNumberParameterEntryValidator(
775  AnyNumberParameterEntryValidator::AcceptedTypes const& acceptedTypes
776  );
777 
783 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT void setIntParameter(
784  std::string const& paramName,
785  int const value, std::string const& docString,
786  ParameterList *paramList,
787  AnyNumberParameterEntryValidator::AcceptedTypes const& acceptedTypes
788  = AnyNumberParameterEntryValidator::AcceptedTypes()
789  );
790 
791 
797 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT void setDoubleParameter(
798  std::string const& paramName,
799  double const& value, std::string const& docString,
800  ParameterList *paramList,
801  AnyNumberParameterEntryValidator::AcceptedTypes const& acceptedTypes
802  = AnyNumberParameterEntryValidator::AcceptedTypes()
803  );
804 
805 
811 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT void setNumericStringParameter(
812  std::string const& paramName,
813  std::string const& value, std::string const& docString,
814  ParameterList *paramList,
815  AnyNumberParameterEntryValidator::AcceptedTypes const& acceptedTypes
816  = AnyNumberParameterEntryValidator::AcceptedTypes()
817  );
818 
819 
834 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT int getIntParameter(
835  ParameterList const& paramList, std::string const& paramName
836  );
837 
838 
853 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT double getDoubleParameter(
854  ParameterList const& paramList,
855  std::string const& paramName
856  );
857 
858 
874 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT std::string getNumericStringParameter(
875  ParameterList const& paramList,
876  std::string const& paramName
877  );
878 
884 template<>
886 
887 public:
888 
891 
895  static RCP<AnyNumberParameterEntryValidator > getDummyObject();
896 
898 
899 };
900 
901 
906 template <class T>
909  static inline T notDefined() {
910  return T::this_type_is_missing_a_specialization();
911  }
912 };
913 
914 
935 template <class T>
937 public:
938 
940  static inline T min()
942 
944  static inline T max()
946 
949  static inline T defaultStep()
951 
954  static inline unsigned short defaultPrecision()
956 
957 };
958 
959 
960 template<>
961 class EnhancedNumberTraits<short int>{
962 public:
963  static inline short int min() { return std::numeric_limits<short int>::min(); }
964  static inline short int max() { return std::numeric_limits<short int>::max(); }
965  static inline short int defaultStep() { return 1; }
966  static inline unsigned short defaultPrecision() { return 0; }
967 };
968 
969 
970 template<>
971 class EnhancedNumberTraits<short unsigned int>{
972 public:
973  static inline short unsigned int min() { return std::numeric_limits<short unsigned int>::min(); }
974  static inline short unsigned int max() { return std::numeric_limits<short unsigned int>::max(); }
975  static inline short unsigned int defaultStep() { return 1; }
976  static inline unsigned short defaultPrecision() { return 0; }
977 };
978 
979 
980 template<>
982 public:
983  static inline int min() { return std::numeric_limits<int>::min(); }
984  static inline int max() { return std::numeric_limits<int>::max(); }
985  static inline int defaultStep() { return 1; }
986  static inline unsigned short defaultPrecision() { return 0; }
987 };
988 
989 
990 template<>
991 class EnhancedNumberTraits<unsigned int>{
992 public:
993  static inline unsigned int min() { return std::numeric_limits<unsigned int>::min(); }
994  static inline unsigned int max() { return std::numeric_limits<unsigned int>::max(); }
995  static inline unsigned int defaultStep() { return 1; }
996  static inline unsigned short defaultPrecision() { return 0; }
997 };
998 
999 
1000 template<>
1001 class EnhancedNumberTraits<long int>{
1002 public:
1003  static inline long int min() { return std::numeric_limits<long int>::min(); }
1004  static inline long int max() { return std::numeric_limits<long int>::max(); }
1005  static inline long int defaultStep() { return 1; }
1006  static inline unsigned short defaultPrecision() { return 0; }
1007 };
1008 
1009 
1010 template<>
1011 class EnhancedNumberTraits<long unsigned int>{
1012 public:
1013  static inline long unsigned int min() { return std::numeric_limits<long unsigned int>::min(); }
1014  static inline long unsigned int max() { return std::numeric_limits<long unsigned int>::max(); }
1015  static inline long unsigned int defaultStep() { return 1; }
1016  static inline unsigned short defaultPrecision() { return 0; }
1017 };
1018 
1019 
1020 #ifdef HAVE_TEUCHOS_LONG_LONG_INT
1021 
1022 
1023 template<>
1024 class EnhancedNumberTraits<long long int>{
1025 public:
1026  static inline long long int min() { return std::numeric_limits<long long int>::min(); }
1027  static inline long long int max() { return std::numeric_limits<long long int>::max(); }
1028  static inline long long int defaultStep() { return 1; }
1029  static inline unsigned short defaultPrecision() { return 0; }
1030 };
1031 
1032 
1033 template<>
1034 class EnhancedNumberTraits<long long unsigned int>{
1035 public:
1036  static inline long long unsigned int min() { return std::numeric_limits<long long unsigned int>::min(); }
1037  static inline long long unsigned int max() { return std::numeric_limits<long long unsigned int>::max(); }
1038  static inline long long unsigned int defaultStep() { return 1; }
1039  static inline unsigned short defaultPrecision() { return 0; }
1040 };
1041 
1042 
1043 #endif // HAVE_TEUCHOS_LONG_LONG_INT
1044 
1045 
1046 template<>
1047 class EnhancedNumberTraits<double>{
1048 public:
1049  static inline double min() { return -std::numeric_limits<double>::max(); }
1050  static inline double max() { return std::numeric_limits<double>::max(); }
1051  static inline double defaultStep() { return 1; }
1052  static inline unsigned short defaultPrecision() { return 100; }
1053 };
1054 
1055 
1056 template<>
1058 public:
1059  static inline float min() { return -std::numeric_limits<float>::max(); }
1060  static inline float max() { return std::numeric_limits<float>::max(); }
1061  static inline float defaultStep() { return 1; }
1062  static inline unsigned short defaultPrecision() { return 100; }
1063 };
1064 
1065 
1071 template <class T>
1073 
1074 public:
1075 
1078 
1094  T min,
1095  T max,
1097  unsigned short precision=EnhancedNumberTraits<T>::defaultPrecision()):
1099  minVal(min), maxVal(max), step_(step), precision_(precision),
1100  containsMin(true), containsMax(true){}
1101 
1107  minVal(EnhancedNumberTraits<T>::min()),
1108  maxVal(EnhancedNumberTraits<T>::max()),
1109  step_(EnhancedNumberTraits<T>::defaultStep()),
1110  precision_(EnhancedNumberTraits<T>::defaultPrecision()),
1111  containsMin(false),
1112  containsMax(false){}
1113 
1115 
1117 
1118 
1123  void setMin(T min){
1124  minVal = min;
1125  containsMin = true;
1126  }
1127 
1132  void setMax(T max){
1133  maxVal = max;
1134  containsMax = true;
1135  }
1136 
1141  void setStep(T step){
1142  step_ = step;
1143  }
1144 
1149  void setPrecision(unsigned short precision){
1150  precision_ = precision;
1151  }
1152 
1154 
1157 
1162  T getMin() const{
1163  return minVal;
1164  }
1165 
1170  T getMax() const{
1171  return maxVal;
1172  }
1173 
1178  T getStep() const{
1179  return step_;
1180  }
1181 
1186  unsigned short getPrecision() const{
1187  return precision_;
1188  }
1189 
1191 
1193 
1194 
1199  bool hasMin() const{
1200  return containsMin;
1201  }
1202 
1207  bool hasMax() const{
1208  return containsMax;
1209  }
1210 
1212 
1215 
1218  return null;
1219  }
1220 
1222  void validate(ParameterEntry const &entry, std::string const &paramName,
1223  std::string const &sublistName) const;
1224 
1226  const std::string getXMLTypeName() const{
1227  return "EnhancedNumberValidator(" + TypeNameTraits<T>::name()+ ")";
1228  }
1229 
1231  void printDoc(std::string const &docString, std::ostream &out) const{
1232  StrUtils::printLines(out,"# ",docString);
1233  out << "#\tValidator Used: " << std::endl;
1234  out << "#\t\tNumber Validator" << std::endl;
1235  out << "#\t\tType: " << Teuchos::TypeNameTraits<T>::name() <<
1236  std::endl;
1237  out << "#\t\tMin (inclusive): " << minVal << std::endl;
1238  out << "#\t\tMax (inclusive): " << maxVal << std::endl;
1239  }
1240 
1242 
1243 private:
1244 
1247 
1251 
1255 
1259 
1263  unsigned short precision_;
1264 
1268 
1272 
1274 
1275 };
1276 
1277 template<class T>
1278 void EnhancedNumberValidator<T>::validate(ParameterEntry const &entry, std::string const &paramName,
1279  std::string const &sublistName) const
1280 {
1281  any anyValue = entry.getAny(true);
1282  const std::string &entryName = entry.getAny(false).typeName();
1283 
1284  TEUCHOS_TEST_FOR_EXCEPTION(anyValue.type() != typeid(T),
1286  "The \"" << paramName << "\"" <<
1287  " parameter in the \"" << sublistName <<
1288  "\" sublist is has an error." << std::endl << std::endl <<
1289  "Error: The value that you entered was the wrong type." << std::endl <<
1290  "Parameter: " << paramName << std::endl <<
1291  "Type specified: " << entryName << std::endl <<
1292  "Type accepted: " << Teuchos::TypeNameTraits<T>::name() << std::endl);
1293 
1294  bool isValueInRange;
1295  any_cast<T>(anyValue) >= minVal && any_cast<T>(anyValue) <= maxVal
1296  ? isValueInRange = true : isValueInRange=false;
1297  TEUCHOS_TEST_FOR_EXCEPTION(!(isValueInRange),
1299  "The \"" << paramName << "\"" <<
1300  " parameter in the \"" << sublistName <<
1301  "\" sublist is has an error." << std::endl << std::endl <<
1302  "Error: The value that was entered doesn't fall with in " <<
1303  "the range set by the validator" << std::endl <<
1304  "Parameter: " << paramName << std::endl <<
1305  "Min: " << minVal << std::endl <<
1306  "Max: " << maxVal << std::endl <<
1307  "Value entered: " <<
1308  (any_cast<T>(anyValue)) << std::endl << std::endl);
1309 }
1310 
1316 template<class T>
1318 
1319 public:
1320 
1323 
1328 
1330 };
1331 
1332 template<class T>
1335 {
1336  return rcp(new EnhancedNumberValidator<T>);
1337 }
1338 
1348 
1349 public:
1350 
1353 
1356  static bool mustAlreadyExistDefault() { return false; }
1357 
1359 
1362 
1368  FileNameValidator(bool mustAlreadyExist = mustAlreadyExistDefault());
1369 
1371 
1373 
1374 
1380  bool fileMustExist() const;
1381 
1383 
1385 
1386 
1395  bool setFileMustExist(bool shouldFileExist);
1396 
1398 
1401 
1403  ValidStringsList validStringValues() const;
1404 
1406  void validate(
1407  ParameterEntry const &entry,
1408  std::string const &paramName,
1409  std::string const &sublistName) const;
1410 
1412  const std::string getXMLTypeName() const;
1413 
1415  void printDoc(std::string const &docString, std::ostream &out) const;
1416 
1418 
1419 private:
1420 
1423 
1428 
1430 
1431 };
1432 
1438 template<>
1440 
1441 public:
1442 
1445 
1449  static RCP<FileNameValidator> getDummyObject();
1450 
1452 
1453 };
1454 
1463 
1464 public:
1465 
1468 
1471  StringValidator();
1472 
1477  StringValidator(const Teuchos::Array<std::string> &validStrings);
1478 
1480 
1482 
1483 
1491  ValidStringsList setValidStrings(
1492  const Teuchos::Array<std::string> &validStrings);
1493 
1495 
1498 
1500  ValidStringsList validStringValues() const;
1501 
1503  void validate(ParameterEntry const &entry, std::string const &paramName,
1504  std::string const &sublistName) const;
1505 
1507  const std::string getXMLTypeName() const;
1508 
1510  void printDoc(std::string const &docString, std::ostream &out) const;
1511 
1513 
1514 private:
1515 
1518 
1521  ValidStringsList validStrings_;
1522 
1524 
1525 };
1526 
1532 template<>
1534 
1535 public:
1536 
1539 
1543  static RCP<StringValidator> getDummyObject();
1544 
1546 
1547 };
1548 
1549 
1553 template<class ValidatorType, class EntryType>
1555 
1556 public:
1557 
1560 
1569  prototypeValidator_(prototypeValidator){}
1570 
1572 
1575 
1578  return prototypeValidator_;
1579  }
1580 
1582 
1585 
1588  return prototypeValidator_->validStringValues();
1589  }
1590 
1592 
1593 private:
1594 
1597 
1601 
1604 
1606 
1607 };
1608 
1621 template<class ValidatorType, class EntryType>
1622 class TwoDArrayValidator : public AbstractArrayValidator<ValidatorType, EntryType>{
1623 public:
1626 
1634  AbstractArrayValidator<ValidatorType, EntryType>(prototypeValidator){}
1635 
1637 
1640 
1642  virtual void validate(ParameterEntry const &entry, std::string const &paramName,
1643  std::string const &sublistName) const;
1644 
1646  const std::string getXMLTypeName() const{
1647  return "TwoDArrayValidator(" +
1648  this->getPrototype()->getXMLTypeName() + ", " +
1650  }
1651 
1653  virtual void printDoc(std::string const &docString, std::ostream &out) const
1654  {
1655  StrUtils::printLines(out,"# ",docString);
1656  std::string toPrint;
1657  toPrint += "TwoDArrayValidator:\n";
1658  toPrint += "Prototype Validator:\n";
1659  this->getPrototype()->printDoc(toPrint, out);
1660  }
1661 
1663 
1664 };
1665 
1666 template<class ValidatorType, class EntryType>
1667 void TwoDArrayValidator<ValidatorType, EntryType>::validate(ParameterEntry const &entry, std::string const &paramName,
1668  std::string const &sublistName) const
1669 {
1670  any anyValue = entry.getAny(true);
1671  const std::string &entryName = entry.getAny(false).typeName();
1674  "The \"" << paramName << "\"" <<
1675  " parameter in the \"" << sublistName <<
1676  "\" sublist is has an error." << std::endl << std::endl <<
1677  "Error: The value you entered was the wrong type." << std::endl <<
1678  "Parameter: " << paramName << std::endl <<
1679  "Type specified: " << entryName << std::endl <<
1680  "Type accepted: " << TypeNameTraits<TwoDArray<EntryType> >::name() <<
1681  std::endl << std::endl);
1682 
1683  TwoDArray<EntryType> extracted =
1684  getValue<Teuchos::TwoDArray<EntryType> >(entry);
1685  RCP<const ParameterEntryValidator> prototype = this->getPrototype();
1686  for(int i = 0; i<extracted.getNumRows(); ++i){
1687  for(int j = 0; j<extracted.getNumCols(); ++j){
1688  ParameterEntry dummyParameter;
1689  dummyParameter.setValue(extracted(i,j));
1690  try{
1691  prototype->validate(
1692  dummyParameter, paramName, sublistName);
1693  }
1695  std::stringstream oss;
1696  oss << "TwoDArray Validator Exception:" << std::endl <<
1697  "Bad Index: (" << i << "," << j << ")" << std::endl << e.what();
1698  throw Exceptions::InvalidParameterValue(oss.str());
1699  }
1700  }
1701  }
1702 }
1703 
1704 
1710 template<class ValidatorType, class EntryType>
1711 class DummyObjectGetter<TwoDArrayValidator<ValidatorType, EntryType> >{
1712 
1713 public:
1714 
1717 
1722 
1724 
1725 };
1726 
1727 template<class ValidatorType, class EntryType>
1730 {
1733 }
1734 
1739  public TwoDArrayValidator<StringValidator, std::string>{
1740 
1741 public:
1742 
1745 
1748  TwoDArrayValidator<StringValidator, std::string>(prototypeValidator){}
1749 
1751 
1752 };
1753 
1754 
1760  public TwoDArrayValidator<FileNameValidator, std::string>{
1761 
1762 public:
1763 
1766 
1769  TwoDArrayValidator<FileNameValidator, std::string>(prototypeValidator){}
1770 
1772 
1773 };
1774 
1775 
1779 template<class T>
1780 class TwoDArrayNumberValidator : public TwoDArrayValidator<EnhancedNumberValidator<T>, T>{
1781 public:
1784 
1787  RCP<const EnhancedNumberValidator<T> > prototypeValidator):
1788  TwoDArrayValidator<EnhancedNumberValidator<T>, T>(prototypeValidator){}
1789 
1791 
1792 };
1793 
1794 
1806 template<class ValidatorType, class EntryType>
1807 class ArrayValidator : public AbstractArrayValidator<ValidatorType, EntryType>{
1808 
1809 public:
1810 
1813 
1820  AbstractArrayValidator<ValidatorType, EntryType>(prototypeValidator){}
1821 
1823 
1826 
1828  virtual void validate(ParameterEntry const &entry, std::string const &paramName,
1829  std::string const &sublistName) const;
1830 
1832  const std::string getXMLTypeName() const{
1833  return "ArrayValidator(" +
1834  this->getPrototype()->getXMLTypeName() + ", " +
1836  }
1837 
1839  virtual void printDoc(std::string const &docString, std::ostream &out) const
1840  {
1841  StrUtils::printLines(out,"# ",docString);
1842  std::string toPrint;
1843  toPrint += "ArrayValidator:\n";
1844  toPrint += "Prototype Validator:\n";
1845  this->getPrototype()->printDoc(toPrint, out);
1846  }
1847 
1849 
1850 };
1851 
1852 template<class ValidatorType, class EntryType>
1853 void ArrayValidator<ValidatorType, EntryType>::validate(ParameterEntry const &entry, std::string const &paramName,
1854  std::string const &sublistName) const
1855 {
1856  any anyValue = entry.getAny(true);
1857  const std::string &entryName = entry.getAny(false).typeName();
1858  TEUCHOS_TEST_FOR_EXCEPTION(anyValue.type() != typeid(Array<EntryType>),
1860  "The \"" << paramName << "\"" <<
1861  " parameter in the \"" << sublistName <<
1862  "\" sublist is has an error." << std::endl << std::endl <<
1863  "Error: The value you entered was the wrong type." << std::endl <<
1864  "Parameter: " << paramName << std::endl <<
1865  "Type specified: " << entryName << std::endl <<
1866  "Type accepted: " << TypeNameTraits<Array<EntryType> >::name() <<
1867  std::endl << std::endl);
1868 
1869  Array<EntryType> extracted =
1870  getValue<Teuchos::Array<EntryType> >(entry);
1871  RCP<const ParameterEntryValidator> prototype = this->getPrototype();
1872  for(int i = 0; i<extracted.size(); ++i){
1873  ParameterEntry dummyParameter;
1874  dummyParameter.setValue(extracted[i]);
1875  try{
1876  prototype->validate(
1877  dummyParameter, paramName, sublistName);
1878  }
1880  std::stringstream oss;
1881  oss << "Array Validator Exception:" << std::endl <<
1882  "Bad Index: " << i << std::endl << e.what();
1883  throw Exceptions::InvalidParameterValue(oss.str());
1884  }
1885  }
1886 }
1887 
1893 template<class ValidatorType, class EntryType>
1894 class DummyObjectGetter<ArrayValidator<ValidatorType, EntryType> >{
1895 
1896 public:
1897 
1900 
1905 
1907 
1908 };
1909 
1910 template<class ValidatorType, class EntryType>
1913 {
1916 }
1917 
1918 
1928  public ArrayValidator<StringValidator, std::string>{
1929 
1930 public:
1931 
1934 
1937  ArrayValidator<StringValidator, std::string>(prototypeValidator){}
1938 
1940 
1941 };
1942 
1943 
1952 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT ArrayFileNameValidator : public ArrayValidator<FileNameValidator, std::string>{
1953 
1954 public:
1955 
1958 
1961  ArrayValidator<FileNameValidator, std::string>(prototypeValidator){}
1962 
1964 
1965 };
1966 
1967 
1975 template<class T>
1976 class ArrayNumberValidator : public ArrayValidator<EnhancedNumberValidator<T>, T>{
1977 public:
1980 
1983  RCP<const EnhancedNumberValidator<T> > prototypeValidator):
1984  ArrayValidator<EnhancedNumberValidator<T>, T>(prototypeValidator){}
1985 
1987 
1988 };
1989 
1990 
1991 
1992 // ///////////////////////////
1993 // Implementations
1994 
1995 
1996 //
1997 // StringToIntegralParameterEntryValidator
1998 //
1999 
2000 
2001 // Constructors
2002 
2003 
2004 template<class IntegralType>
2006  ArrayView<const std::string> const& strings, std::string const& defaultParameterName
2007  ):
2009  defaultParameterName_(defaultParameterName)
2010 {
2011  typedef typename map_t::value_type val_t;
2012  for( int i = 0; i < static_cast<int>(strings.size()); ++i ) {
2013  const bool unique = map_.insert( val_t( strings[i], (IntegralType)i ) ).second;
2015  !unique, std::logic_error
2016  ,"Error, the std::string \"" << strings[i] << "\" is a duplicate for parameter \""
2017  << defaultParameterName_ << "\"."
2018  );
2019  }
2020  setValidValues(strings);
2021 }
2022 
2023 
2024 template<class IntegralType>
2026  ArrayView<const std::string> const& strings, ArrayView<const IntegralType> const& integralValues
2027  ,std::string const& defaultParameterName
2028  ):
2030  defaultParameterName_(defaultParameterName)
2031 {
2032 #ifdef TEUCHOS_DEBUG
2033  TEUCHOS_ASSERT_EQUALITY( strings.size(), integralValues.size() );
2034 #endif
2036  strings.size() != integralValues.size(),
2037  std::logic_error,
2038  "Error, strings and integraValues must be of the same length."
2039  );
2040  typedef typename map_t::value_type val_t;
2041  for( int i = 0; i < static_cast<int>(strings.size()); ++i ) {
2042  const bool unique = map_.insert( val_t( strings[i], integralValues[i] ) ).second;
2044  !unique, std::logic_error
2045  ,"Error, the std::string \"" << strings[i] << "\" is a duplicate for parameter \""
2046  << defaultParameterName_ << "\""
2047  );
2048  }
2049  setValidValues(strings);
2050 }
2051 
2052 template<class IntegralType>
2054  ArrayView<const std::string> const& strings
2055  ,ArrayView<const std::string> const& stringsDocs
2056  ,ArrayView<const IntegralType> const& integralValues
2057  ,std::string const& defaultParameterName
2058  ):
2060  defaultParameterName_(defaultParameterName)
2061 {
2062 #ifdef TEUCHOS_DEBUG
2063  TEUCHOS_ASSERT_EQUALITY( strings.size(), stringsDocs.size() );
2064  TEUCHOS_ASSERT_EQUALITY( strings.size(), integralValues.size() );
2065 #endif
2067  strings.size() != integralValues.size(),
2068  std::logic_error,
2069  "Error, strings and integraValues must be of the same length."
2070  );
2072  strings.size() != stringsDocs.size(),
2073  std::logic_error,
2074  "Error, strings and stringsDocs must be of the same length."
2075  );
2076  typedef typename map_t::value_type val_t;
2077  for( int i = 0; i < static_cast<int>(strings.size()); ++i ) {
2078  const bool unique = map_.insert( val_t( strings[i], integralValues[i] ) ).second;
2080  !unique, std::logic_error
2081  ,"Error, the std::string \"" << strings[i] << "\" is a duplicate for parameter \""
2082  << defaultParameterName_ << "\""
2083  );
2084  }
2085  setValidValues(strings,&stringsDocs);
2086 }
2087 
2088 // Lookup functions
2089 
2090 
2091 template<class IntegralType>
2092 IntegralType
2094  const std::string &str, const std::string &paramName
2095  ,const std::string &sublistName
2096  ) const
2097 {
2098  typename map_t::const_iterator itr = map_.find(str);
2100  itr == map_.end(), Exceptions::InvalidParameterValue
2101  ,"Error, the value \"" << str << "\" is not recognized for the parameter \""
2102  << ( paramName.length() ? paramName : defaultParameterName_ ) << "\""
2103  << "\nin the sublist \"" << sublistName << "\"."
2104  << "\n\nValid values include:"
2105  << "\n {\n"
2106  << validValues_
2107  << " }"
2108  );
2109  return (*itr).second;
2110 }
2111 
2112 
2113 template<class IntegralType>
2114 IntegralType
2116  const ParameterEntry &entry, const std::string &paramName
2117  ,const std::string &sublistName, const bool activeQuery
2118  ) const
2119 {
2120  const bool validType = ( entry.getAny(activeQuery).type() == typeid(std::string) );
2123  ,"Error, the parameter {paramName=\""<<(paramName.length()?paramName:defaultParameterName_)
2124  << "\",type=\""<<entry.getAny(activeQuery).typeName()<<"\"}"
2125  << "\nin the sublist \"" << sublistName << "\""
2126  << "\nhas the wrong type."
2127  << "\n\nThe correct type is \"string\"!"
2128  );
2129  const std::string
2130  &strValue = any_cast<std::string>(entry.getAny(activeQuery)); // This cast should not fail!
2131  return getIntegralValue(strValue,paramName,sublistName); // This will validate the value and throw!
2132 }
2133 
2134 
2135 template<class IntegralType>
2136 std::string
2138  const ParameterEntry &entry, const std::string &paramName
2139  ,const std::string &sublistName, const bool activeQuery
2140  ) const
2141 {
2142  // Validate the parameter's type and value
2143  this->getIntegralValue(entry,paramName,sublistName,activeQuery);
2144  // Return the std::string value which is now validated!
2145  return any_cast<std::string>(entry.getAny(activeQuery)); // This cast should not fail!
2146 }
2147 
2148 
2149 template<class IntegralType>
2150 IntegralType
2152  ParameterList &paramList, const std::string &paramName
2153  ,const std::string &defaultValue
2154  ) const
2155 {
2156  const std::string
2157  &strValue = paramList.get(paramName,defaultValue);
2158  return getIntegralValue(strValue,paramName,paramList.name());
2159 }
2160 
2161 
2162 template<class IntegralType>
2163 std::string
2165  ParameterList &paramList, const std::string &paramName
2166  ,const std::string &defaultValue
2167  ) const
2168 {
2169  const std::string
2170  &strValue = paramList.get(paramName,defaultValue);
2171  getIntegralValue(strValue,paramName,paramList.name()); // Validate!
2172  return strValue;
2173 }
2174 
2175 template<class IntegralType>
2178 {
2179  return validStringValuesDocs_;
2180 }
2181 
2182 template<class IntegralType>
2183 const std::string&
2185 {
2186  return defaultParameterName_;
2187 }
2188 
2189 template<class IntegralType>
2190 std::string
2192  const std::string &str, const std::string &paramName
2193  ,const std::string &sublistName
2194  ) const
2195 {
2196  getIntegralValue(str,paramName,sublistName); // Validate!
2197  return str;
2198 }
2199 
2200 
2201 // Overridden from ParameterEntryValidator
2202 
2203 template<class IntegralType>
2204 const std::string
2206  return "StringIntegralValidator(" +
2208  ")";
2209 }
2210 
2211 template<class IntegralType>
2213  std::string const& docString
2214  ,std::ostream & out
2215  ) const
2216 {
2217  StrUtils::printLines(out,"# ",docString);
2218  out << "# Valid std::string values:\n";
2219  out << "# {\n";
2220  if(validStringValuesDocs_.get()) {
2221  for( int i = 0; i < static_cast<int>(validStringValues_->size()); ++i ) {
2222  out << "# \"" << (*validStringValues_)[i] << "\"\n";
2223  StrUtils::printLines(out,"# ",(*validStringValuesDocs_)[i] );
2224  }
2225  }
2226  else {
2227  StrUtils::printLines(out,"# ",validValues_);
2228  // Note: Above validValues_ has for initial spaces already so indent should
2229  // be correct!
2230  }
2231  out << "# }\n";
2232 }
2233 
2234 
2235 template<class IntegralType>
2238 {
2239  return validStringValues_;
2240 }
2241 
2242 
2243 template<class IntegralType>
2245  ParameterEntry const& entry
2246  ,std::string const& paramName
2247  ,std::string const& sublistName
2248  ) const
2249 {
2250  this->getIntegralValue(entry,paramName,sublistName,false);
2251 }
2252 
2253 
2254 // private
2255 
2256 template<class IntegralType>
2258  ArrayView<const std::string> const& strings
2259  ,ArrayView<const std::string> const* stringsDocs
2260  )
2261 {
2262  validStringValues_ = rcp(new Array<std::string>(strings));
2263  if(stringsDocs)
2264  validStringValuesDocs_ = rcp(new Array<std::string>(*stringsDocs));
2265  // Here I build the list of valid values in the same order as passed in by
2266  // the client!
2267  std::ostringstream oss;
2268  for( int i = 0; i < static_cast<int>(strings.size()); ++i ) {
2269  oss << " \""<<strings[i]<<"\"\n";
2270  }
2271  // Note: Above four spaces is designed for the error output above.
2272  validValues_ = oss.str();
2273 }
2274 
2275 
2276 } // namespace Teuchos
2277 
2278 
2279 //
2280 // Nonmember function implementations for StringToIntegralParameterEntryValidator
2281 //
2282 
2283 
2284 template<class IntegralType>
2285 inline
2287 Teuchos::stringToIntegralParameterEntryValidator(
2288  ArrayView<const std::string> const& strings,
2289  std::string const& defaultParameterName
2290  )
2291 {
2292  return rcp(
2293  new StringToIntegralParameterEntryValidator<IntegralType>(
2294  strings, defaultParameterName
2295  )
2296  );
2297 }
2298 
2299 
2300 template<class IntegralType>
2301 inline
2303 Teuchos::stringToIntegralParameterEntryValidator(
2304  ArrayView<const std::string> const& strings,
2305  ArrayView<const IntegralType> const& integralValues,
2306  std::string const& defaultParameterName
2307  )
2308 {
2309  return rcp(
2310  new StringToIntegralParameterEntryValidator<IntegralType>(
2311  strings, integralValues, defaultParameterName
2312  )
2313  );
2314 }
2315 
2316 
2317 template<class IntegralType>
2318 inline
2320 Teuchos::stringToIntegralParameterEntryValidator(
2321  ArrayView<const std::string> const& strings,
2322  ArrayView<const std::string> const& stringsDocs,
2323  ArrayView<const IntegralType> const& integralValues,
2324  std::string const& defaultParameterName
2325  )
2326 {
2327  return rcp(
2328  new StringToIntegralParameterEntryValidator<IntegralType>(
2329  strings, stringsDocs, integralValues, defaultParameterName
2330  )
2331  );
2332 }
2333 
2334 template<class IntegralType>
2335 void Teuchos::setStringToIntegralParameter(
2336  std::string const& paramName,
2337  std::string const& defaultValue,
2338  std::string const& docString,
2339  ArrayView<const std::string> const& strings,
2340  ParameterList * paramList
2341  )
2342 {
2343  typedef ParameterEntryValidator PEV;
2344  TEUCHOS_TEST_FOR_EXCEPT(0==paramList);
2345  paramList->set(
2346  paramName, defaultValue, docString,
2347  rcp_implicit_cast<const PEV>(
2348  stringToIntegralParameterEntryValidator<IntegralType>(
2349  strings, paramName
2350  )
2351  )
2352  );
2353 }
2354 
2355 
2356 template<class IntegralType>
2357 void Teuchos::setStringToIntegralParameter(
2358  std::string const& paramName,
2359  std::string const& defaultValue,
2360  std::string const& docString,
2361  ArrayView<const std::string> const& strings,
2362  ArrayView<const IntegralType> const& integralValues,
2363  ParameterList * paramList
2364  )
2365 {
2366  typedef ParameterEntryValidator PEV;
2367  TEUCHOS_TEST_FOR_EXCEPT(0==paramList);
2368  paramList->set(
2369  paramName, defaultValue, docString,
2370  rcp_implicit_cast<const PEV>(
2371  stringToIntegralParameterEntryValidator<IntegralType>(
2372  strings, integralValues, paramName
2373  )
2374  )
2375  );
2376 }
2377 
2378 
2379 template<class IntegralType>
2380 void Teuchos::setStringToIntegralParameter(
2381  std::string const& paramName,
2382  std::string const& defaultValue,
2383  std::string const& docString,
2384  ArrayView<const std::string> const& strings,
2385  ArrayView<const std::string> const& stringsDocs,
2386  ArrayView<const IntegralType> const& integralValues,
2387  ParameterList * paramList
2388  )
2389 
2390 {
2391  typedef ParameterEntryValidator PEV;
2392  TEUCHOS_TEST_FOR_EXCEPT(0==paramList);
2393  paramList->set(
2394  paramName, defaultValue, docString,
2395  rcp_implicit_cast<const PEV>(
2396  stringToIntegralParameterEntryValidator<IntegralType>(
2397  strings, stringsDocs, integralValues, paramName
2398  )
2399  )
2400  );
2401 }
2402 
2403 
2404 template<class IntegralType>
2405 IntegralType Teuchos::getIntegralValue(
2406  ParameterList const& paramList, std::string const& paramName
2407  )
2408 {
2409  const ParameterEntry &entry = paramList.getEntry(paramName);
2410  RCP<const StringToIntegralParameterEntryValidator<IntegralType> >
2411  integralValidator = getStringToIntegralParameterEntryValidator<IntegralType>(
2412  entry, paramList, paramName
2413  );
2414  return integralValidator->getIntegralValue(
2415  entry, paramName, paramList.name(), true );
2416 }
2417 
2418 
2419 template<class IntegralType>
2420 std::string Teuchos::getStringValue(
2421  ParameterList const& paramList, std::string const& paramName
2422  )
2423 {
2424  const ParameterEntry &entry = paramList.getEntry(paramName);
2425  RCP<const StringToIntegralParameterEntryValidator<IntegralType> >
2426  integralValidator = getStringToIntegralParameterEntryValidator<IntegralType>(
2427  entry, paramList, paramName
2428  );
2429  return integralValidator->getStringValue(
2430  entry, paramName, paramList.name(), true
2431  );
2432 }
2433 
2434 
2435 template<class IntegralType>
2438  ParameterEntry const& entry, ParameterList const& paramList,
2439  std::string const& paramName
2440  )
2441 {
2442  const RCP<const ParameterEntryValidator> validator = entry.validator();
2444  is_null(validator), Exceptions::InvalidParameterType,
2445  "Error! The parameter \""<<paramName<<"\" exists\n"
2446  "in the parameter (sub)list \""<<paramList.name()<<"\"\n"
2447  "but it does not contain any validator needed to extract\n"
2448  "an integral value of type \""<<TypeNameTraits<IntegralType>::name()<<"\"!"
2449  );
2450  const RCP<const StringToIntegralParameterEntryValidator<IntegralType> > integralValidator =
2451  rcp_dynamic_cast<const StringToIntegralParameterEntryValidator<IntegralType> >(
2452  validator
2453  );
2455  is_null(integralValidator), Exceptions::InvalidParameterType,
2456  "Error! The parameter \""<<paramName<<"\" exists\n"
2457  "in the parameter (sub)list \""<<paramList.name()<<"\"\n"
2458  "but it contains the wrong type of validator. The expected validator type\n"
2459  "is \""<<TypeNameTraits<StringToIntegralParameterEntryValidator<IntegralType> >::name()<<"\"\n"
2460  "but the contained validator type is \""<<typeName(*validator)<<"\"!"
2461  );
2462  return integralValidator;
2463 }
2464 
2465 
2466 #endif // TEUCHOS_STANDARD_PARAMETER_ENTRY_VALIDATORS_H
static bool mustAlreadyExistDefault()
The default value of the mustAlreadyExist parameter in the constructor.
A thin wrapper around the Teuchos Array class that allows for 2 dimensional arrays.
std::string validateString(const std::string &str, const std::string &paramName="", const std::string &sublistName="") const
Validate the std::string and pass it on.
RCP< T > rcp(const boost::shared_ptr< T > &sptr)
Conversion function that takes in a boost::shared_ptr object and spits out a Teuchos::RCP object...
const std::string & name() const
The name of this ParameterList.
T getMax() const
Gets the maximum acceptable value for the validator.
EVerbosityLevel
Verbosity level.
EnhancedNumberValidator()
Constructs a EnhancedNumberValidator without an explicit minimum or maximum.
std::string typeName(const T &t)
Template function for returning the concrete type name of a passed-in object.
Convience class for StringValidators that are to be applied to TwoDArrays.
void printDoc(std::string const &docString, std::ostream &out) const
static RCP< T > getDummyObject()
Retrieves a dummy object of type T.
RCP< const StringToIntegralParameterEntryValidator< IntegralType > > getStringToIntegralParameterEntryValidator(ParameterEntry const &entry, ParameterList const &paramList, std::string const &paramName)
Get a StringToIntegralParameterEntryValidator&lt;IntegralType&gt; object out of a ParameterEntry object...
void setValue(T value, bool isDefault=false, const std::string &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Templated set method that uses the input value type to determine the type of parameter.
Convience class for EnhancedNumberValidators that are to be applied to arrays.
RCP< T2 > rcp_dynamic_cast(const RCP< T1 > &p1, bool throw_on_fail=false)
Dynamic cast of underlying RCP type from T1* to T2*.
EPreferredType
Determines what type is the preferred type.
T & get(const std::string &name, T def_value)
Return the parameter&#39;s value, or the default value if it is not there.
This object is held as the &quot;value&quot; in the Teuchos::ParameterList std::map.
T minVal
The minimum value accepted by the validator.
virtual void validate(ParameterEntry const &entry, std::string const &paramName, std::string const &sublistName) const
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
void validate(ParameterEntry const &entry, std::string const &paramName, std::string const &sublistName) const
Default structure used by EnhancedNumberTraits&lt;T&gt; to produce a compile time error when the specializa...
void setMax(T max)
Sets the maximum acceptable value for the validator.
size_type size() const
The total number of items in the managed array.
Standard implementation of a ParameterEntryValidator that maps from a list of strings to some integra...
AcceptedTypes & allowString(bool _allowString)
Set allow an std::string value or not.
bool hasMax() const
Determines whether or not the validator has a maximum value.
T getMin() const
Gets the minimum acceptable value for the validator.
static std::ostream & printLines(std::ostream &os, const std::string &linePrefix, const std::string &lines)
Print lines with prefix first.
ValidStringsList validStrings_
An array containing a list of all the valid string values.
Modified boost::any class, which is a container for a templated value.
Definition: Teuchos_any.hpp:86
static EPreferredType getPrefferedTypeStringEnum(const std::string &enumString)
Gets the preferred type enum associated with a give string.
bool is_null(const ArrayRCP< T > &p)
Returns true if p.get()==NULL.
AcceptedTypes & allowInt(bool _allowInt)
Set allow an int value or not.
AbstractArrayValidator(RCP< const ValidatorType > prototypeValidator)
Constructs an AbstractArrayValidator.
Takes a validator, wraps it, and applies it to a TwoDArray.
bool hasMin() const
Determines whether or not the validator has a minimum value.
unsigned short getPrecision() const
Gets the precision specified for the validator.
A std::string utilities class for Teuchos.
A thin wrapper around the Array class which causes it to be interpurted as a 2D Array.
RCP< const ValidatorType > getPrototype() const
Returns the prototype validator for this Array Validator.
void printDoc(std::string const &docString, std::ostream &out) const
Convience class for StringValidators that are to be applied to arrays.
static T notDefined()
This function should not compile if there is an attempt to instantiate!
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
Templated Parameter List class.
static unsigned short defaultPrecision()
Gets the default precision with which the number type should be displayed.
void validate(ParameterEntry const &entry, std::string const &paramName, std::string const &sublistName) const
bool containsMax
Whetehr or not a maximum value has been specified for this validator.
std::string toString(const HashSet< Key > &h)
std::string getStringValue(const ParameterEntry &entry, const std::string &paramName="", const std::string &sublistName="", const bool activeQuery=true) const
Get and validate a std::string value embedded in a ParameterEntry object.
ArrayStringValidator(RCP< const StringValidator > prototypeValidator)
Convience class for EnhancedNumberValidators that are to be applied to TwoDArray. ...
An abstract base class for all ArrayValidators.
ArrayValidator(RCP< const ValidatorType > prototypeValidator)
Constructs a ArrayValidator.
Convience class for FileNameValidators that are to be applied to TwoDArrays.
AcceptedTypes(bool allowAllTypesByDefault=true)
Allow all types or not on construction.
void setStep(T step)
Sets the step being used for the validator.
Takes a validator, wraps it, and applies it to an array.
A list of parameters of arbitrary type.
bool mustAlreadyExist_
Whether or not the file specified in the parameter should already exist.
A simple validator that only allows certain string values to be choosen or simply enforces that a par...
static T min()
Gets the minimum possible value the number type can take on.
#define TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT
TwoDArrayValidator(RCP< const ValidatorType > prototypeValidator)
Constructs a ArrayValidator.
Abstract interface for an object that can validate a ParameterEntry&#39;s value.
any & getAny(bool activeQry=true)
Direct access to the Teuchos::any data value underlying this object. The bool argument activeQry (def...
void setPrecision(unsigned short precision)
Sets the precision specified for the validator.
IntegralType getIntegralValue(const std::string &str, const std::string &paramName="", const std::string &sublistName="") const
Perform a mapping from a std::string value to its integral value.
void setMin(T min)
Sets the minimum acceptable value for the validator.
EnhancedNumberValidator(T min, T max, T step=EnhancedNumberTraits< T >::defaultStep(), unsigned short precision=EnhancedNumberTraits< T >::defaultPrecision())
Constructs a EnhancedNumberValidator.
virtual void printDoc(std::string const &docString, std::ostream &out) const
Nonowning array view.
RCP< const Array< std::string > > ValidStringsList
Default traits class that just returns typeid(T).name().
Class for retrieving a dummy object of type T.
unsigned short precision_
The number of decimal places with which the nubmer will be displayed in a UI. This value is meaningle...
static const std::string & getPrefferedTypeString(EPreferredType enumValue)
Gets the string representation of a given preferred type enum.
ArrayFileNameValidator(RCP< const FileNameValidator > prototypeValidator)
static T defaultStep()
gets default amount a value of the number type should be incremented by when being utilizied in a UI...
static T max()
Gets the maximum possible value the number type can take on.
Class uesd to validate a particular type of number.
Convience class for FileNameValidators that are to be applied to arrays.
void setValidValues(ArrayView< const std::string > const &strings, ArrayView< const std::string > const *stringsDocs=NULL)
Class defining the traits of the number type being used in an EnhancedNumberValidator.
virtual void printDoc(std::string const &docString, std::ostream &out) const
std::string typeName() const
Return the name of the type.
TwoDArrayNumberValidator(RCP< const EnhancedNumberValidator< T > > prototypeValidator)
AcceptedTypes & allowDouble(bool _allowDouble)
Set allow a double value or not.
ValidStringsList getStringDocs() const
Get a pointer to the array containing all the documentation strings.
Smart reference counting pointer class for automatic garbage collection.
TwoDArrayStringValidator(RCP< const StringValidator > prototypeValidator)
const std::type_info & type() const
Return the type of value being stored.
TwoDArrayFileNameValidator(RCP< const FileNameValidator > prototypeValidator)
virtual void validate(ParameterEntry const &entry, std::string const &paramName, std::string const &sublistName) const
#define TEUCHOS_ASSERT_EQUALITY(val1, val2)
This macro is checks that to numbers are equal and if not then throws an exception with a good error ...
const std::string & getDefaultParameterName() const
Get the name of the default parameter for the validator.
T step_
The increment to use when increaseing or decreaseing the value the validator is validating.
Standard implementation of a ParameterEntryValidator that accepts numbers from a number of different ...
T getStep() const
Gets the step being used for the validator.
Defines basic traits returning the name of a type in a portable and readable way. ...
bool containsMin
Whether or not a minimum value has been specified for this validator.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
This macro is designed to be a short version of TEUCHOS_TEST_FOR_EXCEPTION() that is easier to call...
T maxVal
The maximum value accepted by the validator.
RCP< const ValidatorType > prototypeValidator_
The prototype validator to be applied to each entry in the Array.
#define TEUCHOS_TEST_FOR_EXCEPTION_PURE_MSG(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
ArrayNumberValidator(RCP< const EnhancedNumberValidator< T > > prototypeValidator)