Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_ParameterList.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Teuchos: Common Tools Package
4 //
5 // Copyright 2004 NTESS and the Teuchos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef TEUCHOS_PARAMETER_LIST_H
11 #define TEUCHOS_PARAMETER_LIST_H
12 
17 #include "TeuchosParameterList_config.h"
22 #include "Teuchos_Assert.hpp"
23 #include "Teuchos_RCP.hpp"
24 #include "Teuchos_Array.hpp"
25 #include "Teuchos_map.hpp"
26 
27 
32 namespace Teuchos {
33 
44 };
45 
56 };
57 
102 
105 
108 
109 public:
110 
112 
113 
116 
118  class PrintOptions {
119  public:
120  PrintOptions() : indent_(0), showTypes_(false), showFlags_(false), showDoc_(false), showDefault_(true) {}
121  PrintOptions& indent(int _indent) { indent_ = _indent; return *this; }
122  PrintOptions& showTypes(bool _showTypes) { showTypes_ = _showTypes; return *this; }
123  PrintOptions& showFlags(bool _showFlags) { showFlags_ = _showFlags; return *this; }
124  PrintOptions& showDoc(bool _showDoc) { showDoc_ = _showDoc; return *this; }
125  PrintOptions& showDefault(bool _showDefault) { showDefault_ = _showDefault; return *this; }
126  PrintOptions& incrIndent(int indents) { indent_ += indents; return *this; }
127  int indent() const { return indent_; }
128  bool showTypes() const { return showTypes_; }
129  bool showFlags() const { return showFlags_; }
130  bool showDoc() const { return showDoc_; }
131  bool showDefault() const { return showDefault_; }
132  PrintOptions copy() const { return PrintOptions(*this); }
133  private:
134  int indent_;
137  bool showDoc_;
139  };
140 
142 
144 
145 
147  ParameterList() = default;
148 
150  ParameterList(const std::string &name,
151  RCP<const ParameterListModifier> const& modifier = null);
152 
154  ParameterList(const ParameterList& source);
155 
157  virtual ~ParameterList();
158 
160 
162 
164  ParameterList& setName( const std::string &name );
165 
169  ParameterList& operator= (const ParameterList& source);
170 
171  void setModifier(
172  RCP<const ParameterListModifier> const& modifier
173  );
174 
183  ParameterList& setParameters(const ParameterList& source);
184 
194  ParameterList& setParametersNotAlreadySet(const ParameterList& source);
195 
203  ParameterList& disableRecursiveValidation();
204 
213  ParameterList& disableRecursiveModification();
214 
223  ParameterList& disableRecursiveReconciliation();
224 
232  ParameterList& disableRecursiveAll();
233 
252  template<typename T>
253  ParameterList& set (std::string const& name,
254  T const& value,
255  std::string const& docString = "",
256  RCP<const ParameterEntryValidator> const& validator = null);
257 
262  ParameterList& set(
263  std::string const& name, char value[], std::string const& docString = "",
264  RCP<const ParameterEntryValidator> const& validator = null
265  );
266 
271  ParameterList& set(
272  std::string const& name, const char value[], std::string const& docString = "",
273  RCP<const ParameterEntryValidator> const& validator = null
274  );
275 
279  ParameterList& set(
280  std::string const& name, ParameterList const& value, std::string const& docString = ""
281  );
282 
287  template <typename U, typename = std::enable_if_t<std::is_same_v<std::decay_t<U>, ParameterEntry>>>
288  ParameterList& setEntry(const std::string& name, U&& entry);
289 
295  template<typename T>
296  void recursivelySetValidator(RCP<const ParameterEntryValidator> const& validator,
297  int const depth = 1000);
298 
300 
302 
319  template<typename T>
320  T& get(const std::string& name, T def_value);
321 
325  std::string& get(const std::string& name, char def_value[]);
326 
330  std::string& get(const std::string& name, const char def_value[]);
331 
362  template<typename T>
363  T& get (const std::string& name);
364 
392  template<typename T>
393  const T& get (const std::string& name) const;
394 
400  template<typename T>
401  inline
402  T* getPtr(const std::string& name);
403 
409  template<typename T>
410  inline
411  const T* getPtr(const std::string& name) const;
412 
413  // ToDo: Add getSafePtr() functions to return Ptr<T> instead of raw T*
414 
420  ParameterEntry& getEntry(const std::string& name);
421 
427  inline
428  const ParameterEntry& getEntry(const std::string& name) const;
429 
432  inline
433  ParameterEntry* getEntryPtr(const std::string& name);
434 
435  // ToDo: Add function called getEntrySafePtr() to return Ptr<> as the main
436  // implementation and deprecate getEntryPtr()
437 
440  inline
441  const ParameterEntry* getEntryPtr(const std::string& name) const;
442 
445  inline RCP<ParameterEntry> getEntryRCP(const std::string& name);
446 
449  inline RCP<const ParameterEntry> getEntryRCP(const std::string& name) const;
450 
452  inline RCP<const ParameterListModifier> getModifier() const;
453 
455 
457 
458 
472  bool remove(
473  std::string const& name, bool throwIfNotExists = true
474  );
475 
477 
479 
480 
486  ParameterList& sublist(
487  const std::string& name, bool mustAlreadyExist = false,
488  const std::string& docString = ""
489  );
490 
495  ParameterList& sublist(
496  const std::string& name, RCP<const ParameterListModifier> const& modifier,
497  const std::string& docString = ""
498  );
499 
504  const ParameterList& sublist(const std::string& name) const;
505 
507 
509 
510 
512  const std::string& name() const;
513 
518  bool isParameter (const std::string& name) const;
519 
524  bool isSublist (const std::string& name) const;
525 
531  template<typename T>
532  bool isType (const std::string& name) const;
533 
534 #ifndef DOXYGEN_SHOULD_SKIP_THIS
535 
545  template<typename T>
546  bool isType(const std::string& name, T* ptr) const;
547 #endif
548 
550  Ordinal numParams () const;
551 
553 
555 
556 
562  void print() const;
563 
566  std::ostream& print(std::ostream& os, const PrintOptions &printOptions) const;
567 
570  std::ostream& print(std::ostream& os, int indent = 0, bool showTypes = false, bool showFlags = true, bool showDefault = true ) const;
571 
573  void unused(std::ostream& os) const;
574 
576  std::string currentParametersString() const;
577 
579 
581 
582 
584  inline ConstIterator begin() const;
585 
587  inline ConstIterator end() const;
588 
590  inline const std::string& name(ConstIterator i) const;
591 
593  inline const ParameterEntry& entry(ConstIterator i) const;
594 
596 
598 
599 
644  void validateParameters(
645  ParameterList const& validParamList,
646  int const depth = 1000,
647  EValidateUsed const validateUsed = VALIDATE_USED_ENABLED,
648  EValidateDefaults const validateDefaults = VALIDATE_DEFAULTS_ENABLED
649  ) const;
650 
688  void validateParametersAndSetDefaults(
689  ParameterList const& validParamList,
690  int const depth = 1000
691  );
692 
707  void modifyParameterList(ParameterList &validParamList, int const depth = 1000);
708 
719  void reconcileParameterList(ParameterList &validParamList,
720  const bool left_to_right = true);
721 
723 
724 private: // Functions
725 
727  inline Iterator nonconstBegin();
729  inline Iterator nonconstEnd();
731  inline ParameterEntry& nonconstEntry(Iterator i);
733  void validateEntryExists(const std::string &funcName, const std::string &name,
734  const ParameterEntry *entry) const;
735  // ToDo: Change above function to take Ptr<> instead of raw pointer.
737  template<typename T>
738  void validateEntryType(const std::string &funcName, const std::string &name,
739  const ParameterEntry &entry ) const;
741  void validateEntryIsList(const std::string &name, const ParameterEntry &entry) const;
743  void validateMissingSublistMustExist(const std::string &baselist_name,
744  const std::string &sublist_name, const bool mustAlreadyExist) const;
746  void updateSubListNames(int depth = 0);
747 
748 private: // Data members
749 
751  std::string name_ = "ANONYMOUS";
752 
754 //use pragmas to disable some false-positive warnings for windows sharedlibs export
755 //#ifdef _MSC_VER
756 //#pragma warning(push)
757 //#pragma warning(disable:4251)
758 //#endif
760 //#ifdef _MSC_VER
761 //#pragma warning(pop)
762 //#endif
763 
765  bool disableRecursiveValidation_ = false;
766 
768  bool disableRecursiveModification_ = false;
769 
771  bool disableRecursiveReconciliation_ = false;
772 
774 };
775 
776 
781 inline
783 {
784  return rcp(new ParameterList);
785 }
786 
787 
792 inline
793 RCP<ParameterList> parameterList(const std::string &name)
794 {
795  return rcp(new ParameterList(name));
796 }
797 
798 
803 inline
805 {
806  return rcp(new ParameterList(source));
807 }
808 
809 
814 inline
816 {
817  return rcp(new ParameterList);
818 }
819 
820 
825 inline
826 RCP<ParameterList> createParameterList(const std::string &name)
827 {
828  return rcp(new ParameterList(name));
829 }
830 
831 
836 template<>
838 public:
839  static std::string name() { return "ParameterList"; }
840  static std::string concreteName( const ParameterList& /*t2*/ )
841  { return name(); }
842 };
843 
844 
849 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT bool operator==( const ParameterList& list1, const ParameterList& list2 );
850 
851 
856 inline
857 bool operator!=( const ParameterList& list1, const ParameterList& list2 )
858 {
859  return !( list1 == list2 );
860 }
861 
862 
870 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT bool haveSameModifiers (const ParameterList& list1,
873  const ParameterList& list2);
874 
875 
887 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT bool haveSameValues( const ParameterList& list1, const ParameterList& list2,
888  bool verbose = false);
889 
890 
902 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT bool haveSameValuesSorted( const ParameterList& list1,
903  const ParameterList& list2, bool verbose = false);
904 
905 
906 // /////////////////////////////////////////////////////
907 // Inline and Template Function Definitions
908 
909 
910 inline
911 ParameterList& ParameterList::setName( const std::string &name_in )
912 {
913  name_ = name_in;
914  return *this;
915 }
916 
917 
918 // Set functions
919 
920 
921 template<typename T>
922 inline
924  std::string const& name_in, T const& value_in, std::string const& docString_in,
925  RCP<const ParameterEntryValidator> const& validator_in
926  )
927 {
929  const Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
930  if (param_idx != SIOVOCB::getInvalidOrdinal()) {
931  Ptr<ParameterEntry> param = params_.getNonconstObjPtr(param_idx);
932  const std::string docString =
933  (docString_in.length() ? docString_in : param->docString());
934  const RCP<const ParameterEntryValidator> validator =
935  (nonnull(validator_in) ? validator_in : param->validator());
936  // Create temp param to validate before setting
937  ParameterEntry param_new(value_in, false, false, docString, validator );
938  if (nonnull(validator)) {
939  validator->validate(param_new, name_in, this->name());
940  }
941  // Strong guarantee: (if exception is thrown, the value is not changed)
942  *param = param_new;
943  }
944  else {
945  ParameterEntry param_new(value_in, false, false, docString_in, validator_in);
946  if (nonnull(param_new.validator())) {
947  param_new.validator()->validate(param_new, name_in, this->name());
948  }
949  params_.setObj(name_in, param_new);
950  }
951  return *this;
952 }
953 
954 
955 inline
957  std::string const& name_in, char value[], std::string const& docString
958  ,RCP<const ParameterEntryValidator> const& validator
959  )
960 { return set(name_in, std::string(value), docString, validator); }
961 
962 
963 inline
965  const std::string& name_in, const char value[], const std::string &docString
966  ,RCP<const ParameterEntryValidator> const& validator
967  )
968 { return set( name_in, std::string(value), docString, validator ); }
969 
970 
971 inline
973  std::string const& name_in, ParameterList const& value, std::string const& /*docString*/
974  )
975 {
976  sublist(name_in) = value;
977  return *this;
978 }
979 
980 
981 template <typename U, typename>
982 inline
983 ParameterList& ParameterList::setEntry(std::string const& name_in, U&& entry_in)
984 {
985  params_.setObj(name_in, std::forward<U>(entry_in));
986  return *this;
987 }
988 
989 template<typename T>
991  RCP<const ParameterEntryValidator> const& validator, int const depth)
992 {
993  ConstIterator itr;
994  for (itr = this->begin(); itr != this->end(); ++itr){
995  const std::string &entry_name = itr->first;
996  if (this->isSublist(entry_name) && depth > 0){
997  this->sublist(entry_name).recursivelySetValidator<T>(validator, depth - 1);
998  } else{
999  ParameterEntry *theEntry = this->getEntryPtr(entry_name);
1000  if (theEntry->isType<T>()){
1001  theEntry->setValidator(validator);
1002  }
1003  }
1004  }
1005 }
1006 
1007 
1008 // Get functions
1009 
1010 
1011 template<typename T>
1012 T& ParameterList::get(const std::string& name_in, T def_value)
1013 {
1015  Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
1016  if (param_idx == SIOVOCB::getInvalidOrdinal()) {
1017  // Param does not exist
1018  param_idx = params_.setObj(name_in, ParameterEntry(def_value, true));
1019  }
1020  Ptr<ParameterEntry> param = params_.getNonconstObjPtr(param_idx);
1021  this->template validateEntryType<T>("get", name_in, *param);
1022  return getValue<T>(*param);
1023 }
1024 
1025 
1026 inline
1027 std::string& ParameterList::get(const std::string& name_in, char def_value[])
1028 { return get(name_in, std::string(def_value)); }
1029 
1030 
1031 inline
1032 std::string& ParameterList::get(const std::string& name_in, const char def_value[])
1033 { return get(name_in, std::string(def_value)); }
1034 
1035 
1036 template<typename T>
1037 T& ParameterList::get(const std::string& name_in)
1038 {
1039  ParameterEntry *foundEntry = this->getEntryPtr(name_in);
1040  validateEntryExists("get",name_in,foundEntry);
1041  this->template validateEntryType<T>("get",name_in,*foundEntry);
1042  return getValue<T>(*foundEntry);
1043 }
1044 
1045 
1046 template<typename T>
1047 const T& ParameterList::get(const std::string& name_in) const
1048 {
1049  const ParameterEntry *foundEntry = this->getEntryPtr(name_in);
1050  validateEntryExists("get",name_in,foundEntry);
1051  this->template validateEntryType<T>("get",name_in,*foundEntry);
1052  return getValue<T>(*foundEntry);
1053 }
1054 
1055 
1056 template<typename T>
1057 inline
1058 T* ParameterList::getPtr(const std::string& name_in)
1059 {
1061  const Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
1062  if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1063  const Ptr<ParameterEntry> param_ptr = params_.getNonconstObjPtr(param_idx);
1064  if (param_ptr->isType<T>()) {
1065  return &param_ptr->getValue<T>(0);
1066  }
1067  // Note: The above is inefficinet. You have to do the dynamic_cast twice
1068  // (once to see if it is the type and once to do the cast). This could be
1069  // made more efficinet by upgrading Teuchos::any to add a any_cast_ptr()
1070  // function but I don't think anyone actually uses this function.
1071  return 0;
1072  }
1073  return 0;
1074 }
1075 
1076 
1077 template<typename T>
1078 inline
1079 const T* ParameterList::getPtr(const std::string& name_in) const
1080 {
1082  const Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
1083  if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1084  const Ptr<const ParameterEntry> param_ptr = params_.getObjPtr(param_idx);
1085  if (param_ptr->isType<T>()) {
1086  return &param_ptr->getValue<T>(0);
1087  }
1088  // Note: The above is inefficinet, see above non-const getPtr() function.
1089  return 0;
1090  }
1091  return 0;
1092 }
1093 
1094 
1095 inline
1096 ParameterEntry& ParameterList::getEntry(const std::string& name_in)
1097 {
1098  ParameterEntry *foundEntry = this->getEntryPtr(name_in);
1099  validateEntryExists("get", name_in, foundEntry);
1100  return *foundEntry;
1101 }
1102 
1103 
1104 inline
1105 const ParameterEntry& ParameterList::getEntry(const std::string& name_in) const
1106 {
1107  const ParameterEntry *foundEntry = this->getEntryPtr(name_in);
1108  validateEntryExists("get", name_in, foundEntry);
1109  return *foundEntry;
1110 }
1111 
1112 
1113 inline
1115 ParameterList::getEntryPtr(const std::string& name_in)
1116 {
1118  const Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
1119  if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1120  return &*params_.getNonconstObjPtr(param_idx);
1121  }
1122  return 0;
1123 }
1124 
1125 
1126 inline
1127 const ParameterEntry*
1128 ParameterList::getEntryPtr(const std::string& name_in) const
1129 {
1131  const Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
1132  if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1133  return &*params_.getObjPtr(param_idx);
1134  }
1135  return 0;
1136 }
1137 
1138 
1139 inline RCP<ParameterEntry>
1140 ParameterList::getEntryRCP(const std::string& name_in)
1141 {
1143  const Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
1144  if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1145  return rcpFromPtr(params_.getNonconstObjPtr(param_idx));
1146  }
1147  return null;
1148 }
1149 
1150 
1152 ParameterList::getEntryRCP(const std::string& name_in) const
1153 {
1155  const Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
1156  if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1157  return rcpFromPtr(params_.getObjPtr(param_idx));
1158  }
1159  return null;
1160 }
1161 
1162 
1165 { return modifier_; }
1166 
1167 
1168 // Attribute Functions
1169 
1170 
1171 inline
1172 const std::string& ParameterList::name() const
1173 {
1174  return name_;
1175 }
1176 
1177 
1178 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1179 template<typename T>
1180 bool ParameterList::isType(const std::string& name_in, T* /*ptr*/) const
1181 {
1183  const Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
1184  if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1185  return params_.getObjPtr(param_idx)->isType<T>();
1186  }
1187  return false;
1188 }
1189 #endif
1190 
1191 
1192 template<typename T>
1193 bool ParameterList::isType(const std::string& name_in) const
1194 {
1195  return this->isType(name_in, static_cast<T*>(0));
1196 }
1197 
1198 
1199 // Read-only access to the iterator
1200 
1201 
1203 {
1204  return params_.begin();
1205 }
1206 
1207 
1209 {
1210  return params_.end();
1211 }
1212 
1213 
1214 inline const std::string& ParameterList::name(ConstIterator i) const
1215 {
1216  return (i->first);
1217 }
1218 
1219 
1221 {
1222  return (i->second);
1223 }
1224 
1225 
1226 // private
1227 
1228 
1230 {
1231  return params_.nonconstBegin();
1232 }
1233 
1234 
1236 {
1237  return params_.nonconstEnd();
1238 }
1239 
1240 
1242 {
1243  return (i->second);
1244 }
1245 
1246 
1247 template<typename T>
1248 inline
1250  const std::string &/*funcName*/, const std::string &name_in,
1251  const ParameterEntry &entry_in
1252  ) const
1253 {
1255  entry_in.getAny().type() != typeid(T), Exceptions::InvalidParameterType
1256  ,"Error! An attempt was made to access parameter \""<<name_in<<"\""
1257  " of type \""<<entry_in.getAny().typeName()<<"\""
1258  "\nin the parameter (sub)list \""<<this->name()<<"\""
1259  "\nusing the incorrect type \""<<TypeNameTraits<T>::name()<<"\"!"
1260  );
1261 }
1262 
1263 
1264 // //////////////////////////////////////
1265 // Helper functions
1266 
1267 
1274 template<typename T>
1275 T& getParameter( ParameterList& l, const std::string& name )
1276 {
1277  return l.template get<T>(name);
1278 }
1279 
1280 
1286 template<typename T>
1287 inline
1288 T& get( ParameterList& l, const std::string& name )
1289 {
1290  return getParameter<T>(l,name);
1291 }
1292 
1293 
1300 template<typename T>
1301 const T& getParameter( const ParameterList& l, const std::string& name )
1302 {
1303  return l.template get<T>(name);
1304 }
1305 
1306 
1314 template<typename T>
1315 inline
1316 T* getParameterPtr( ParameterList& l, const std::string& name )
1317 {
1318  return l.template getPtr<T>(name);
1319 }
1320 
1321 
1329 template<typename T>
1330 inline
1331 const T* getParameterPtr( const ParameterList& l, const std::string& name )
1332 {
1333  return l.template getPtr<T>(name);
1334 }
1335 
1336 
1343 template<typename T>
1344 inline
1345 bool isParameterType( ParameterList& l, const std::string& name )
1346 {
1347  return l.isType( name, (T*)NULL );
1348 }
1349 
1350 
1357 template<typename T>
1358 inline
1359 bool isParameterType( const ParameterList& l, const std::string& name )
1360 {
1361  return l.isType( name, (T*)NULL );
1362 }
1363 
1364 
1376 template<typename T>
1378  const std::string &paramName
1379  ,const Array<T> &array
1380  ,ParameterList *paramList
1381  )
1382 {
1383  TEUCHOS_TEST_FOR_EXCEPT(!paramList);
1384  paramList->set(paramName,toString(array));
1385 }
1386 
1387 
1452 template<typename T>
1454  const ParameterList &paramList
1455  ,const std::string &paramName
1456  ,const int arrayDim = -1
1457  ,const bool mustExist = true
1458  )
1459 {
1460  std::string arrayStr;
1461  if(mustExist) {
1462  arrayStr = getParameter<std::string>(paramList,paramName);
1463  }
1464  else {
1465  const std::string
1466  *arrayStrPtr = getParameterPtr<std::string>(paramList,paramName);
1467  if(arrayStrPtr) {
1468  arrayStr = *arrayStrPtr;
1469  }
1470  else {
1471  return Array<T>(); // Return an empty array
1472  }
1473  }
1474  Array<T> a;
1475  try {
1476  a = fromStringToArray<T>(arrayStr);
1477  }
1478  catch( const InvalidArrayStringRepresentation&) {
1481  ,"Error! The parameter \""<<paramName<<"\"\n"
1482  "in the sublist \""<<paramList.name()<<"\"\n"
1483  "exists, but the std::string value:\n"
1484  "----------\n"
1485  <<arrayStr<<
1486  "\n----------\n"
1487  "is not a valid array represntation!"
1488  );
1489  }
1491  ( ( a.size()>0 && arrayDim>=0 ) && static_cast<int>(a.size())!=arrayDim )
1493  ,"Error! The parameter \""<<paramName<<"\"\n"
1494  "in the sublist \""<<paramList.name()<<"\"\n"
1495  "exists and is a valid array, but the dimension of\n"
1496  "the read in array a.size() = " << a.size() << "\n"
1497  "was not equal to the expected size arrayDim = " << arrayDim << "!"
1498  );
1499  return a;
1500 }
1501 
1502 
1515 template<typename T>
1516 bool replaceParameterWithArray(const std::string &paramName, const std::string &newName,
1517  ParameterList &pl)
1518 {
1519  bool param_exists = false;
1520  bool overwrite = false;
1521  if (paramName == newName){
1522  overwrite = true;
1523  }
1524  if (pl.isParameter(paramName)){
1525  param_exists = true;
1526  TEUCHOS_TEST_FOR_EXCEPTION(!pl.isType<T>(paramName), std::logic_error,
1527  "The parameter " << paramName << " is not of type " << typeid(T).name());
1528  TEUCHOS_TEST_FOR_EXCEPTION(pl.isParameter(newName) && !overwrite,
1529  std::logic_error, "The parameter " << newName << " already exists in this "
1530  "parameter list.");
1531  Array<T> params = tuple<T>(pl.get<T>(paramName));
1532  pl.remove(paramName);
1533  pl.set(newName, params);
1534  }
1535  return param_exists;
1536 }
1537 
1538 
1542 inline
1544  const RCP<ParameterList> &paramList, const std::string& name,
1545  bool mustAlreadyExist = false, const std::string& docString = ""
1546  )
1547 {
1548  return rcpWithEmbeddedObjPostDestroy(
1549  &paramList->sublist(name, mustAlreadyExist, docString), paramList, false );
1550 }
1551 
1552 
1556 inline
1558  const RCP<const ParameterList> &paramList, const std::string& name
1559  )
1560 {
1561  return rcpWithEmbeddedObjPostDestroy(
1562  &paramList->sublist(name), paramList, false );
1563 }
1564 
1565 
1569 inline std::ostream& operator<<(std::ostream& os, const ParameterList& l)
1570 {
1571  return l.print(os);
1572 }
1573 
1574 
1575 } // end of Teuchos namespace
1576 
1577 
1578 #endif
void print() const
Print function to use in debugging in a debugger.
bool replaceParameterWithArray(const std::string &paramName, const std::string &newName, ParameterList &pl)
Replace a parameter with an array containing the parameter.
Object held as the &quot;value&quot; in the Teuchos::ParameterList std::map.
const std::string & name() const
The name of this ParameterList.
C++ Standard Library compatable filtered iterator.
Ordinal getObjOrdinalIndex(const std::string &key) const
Get the ordinal index given the string key.
ParameterList & setEntry(const std::string &name, U &&entry)
Set a parameter directly as a ParameterEntry.
ConstIterator end() const
An iterator pointing beyond the last entry.
Array< T > getArrayFromStringParameter(const ParameterList &paramList, const std::string &paramName, const int arrayDim=-1, const bool mustExist=true)
Get an Array object (with entries of type T) from a parameter holding a std::string representation of...
PrintOptions & showTypes(bool _showTypes)
RCP< ParameterEntry > getEntryRCP(const std::string &name)
Retrieves the RCP for an entry with the name name if it exists.
void setValidator(RCP< const ParameterEntryValidator > const &validator)
Set the validator.
RCP< const ParameterEntryValidator > validator() const
Return the (optional) validator object.
RCP< ParameterList > createParameterList()
Nonmember constructor.
RCP< ParameterList > createParameterList(const std::string &name)
Nonmember constructor.
T & get(const std::string &name, T def_value)
Return the parameter&#39;s value, or the default value if it is not there.
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Set a parameter whose value has type T.
bool nonnull(const std::shared_ptr< T > &p)
Returns true if p.get()!=NULL.
This object is held as the &quot;value&quot; in the Teuchos::ParameterList std::map.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
Iterator nonconstBegin()
An iterator pointing to the first entry.
bool isParameterType(ParameterList &l, const std::string &name)
A templated helper function for determining the type of a parameter entry for a non-const list...
void validateEntryExists(const std::string &funcName, const std::string &name, const ParameterEntry *entry) const
Validate that a parameter exists.
Ordinal setObj(const std::string &key, U &&obj)
Set (or reset) object by value and return its ordinal index.
bool isType() const
Test the type of the data being contained.
RCP< ParameterList > sublist(const RCP< ParameterList > &paramList, const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
Return a RCP to a sublist in another RCP-ed parameter list.
void recursivelySetValidator(RCP< const ParameterEntryValidator > const &validator, int const depth=1000)
Recursively attach a validator to parameters of type T.
const T * getParameterPtr(const ParameterList &l, const std::string &name)
A templated helper function for getting a pointer to a parameter from a non-const list...
void validateEntryType(const std::string &funcName, const std::string &name, const ParameterEntry &entry) const
Validate that a type is the same.
ParameterEntry * getEntryPtr(const std::string &name)
Retrieves the pointer for an entry with the name name if it exists.
RCP< ParameterList > parameterList()
Nonmember constructor.
PrintOptions & showDefault(bool _showDefault)
bool isParameter(const std::string &name) const
Whether the given parameter exists in this list.
bool remove(std::string const &name, bool throwIfNotExists=true)
Remove a parameter (does not depend on the type of the parameter).
Iterator nonconstEnd()
An iterator pointing beyond the last entry.
std::ostream & operator<<(std::ostream &os, const ParameterList &l)
Output stream operator for handling the printing of the parameter list.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
bool isSublist(const std::string &name) const
Whether the given sublist exists in this list.
bool isParameterType(const ParameterList &l, const std::string &name)
A templated helper function for determining the type of a parameter entry for a const list...
bool operator!=(const ParameterList &list1, const ParameterList &list2)
Returns true if two parameter lists are not the same.
std::string toString(const HashSet< Key > &h)
RCP< ParameterList > parameterList(const ParameterList &source)
Nonmember constructor.
params_t::ConstIterator ConstIterator
Parameter container const iterator typedef.
std::string name_
Name of the (sub)list.
ParameterEntry & nonconstEntry(Iterator i)
Access to ParameterEntry (i.e., returns i-&gt;second)
const T & getParameter(const ParameterList &l, const std::string &name)
A templated helper function for getting a parameter from a const list. This helper function prevents ...
Utility class for setting and passing in print options.
T & getParameter(ParameterList &l, const std::string &name)
A templated helper function for getting a parameter from a non-const list. This helper function preve...
ConstIterator begin() const
An iterator pointing to the first entry.
RCP< const ParameterList > sublist(const RCP< const ParameterList > &paramList, const std::string &name)
Return a RCP to a sublist in another RCP-ed parameter list.
T * getParameterPtr(ParameterList &l, const std::string &name)
A templated helper function for getting a pointer to a parameter from a non-const list...
Ptr< const ObjType > getObjPtr(const Ordinal &idx) const
Get a const semi-persisting association with the stored object indexed by ordinal.
T * getPtr(const std::string &name)
Retrieves the pointer for parameter name of type T from a list. A null pointer is returned if this pa...
A list of parameters of arbitrary type.
RCP< const ParameterListModifier > modifier_
#define TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT
params_t params_
Parameter list.
Provides std::map class for deficient platforms.
Parameter List Modifier class.
const ParameterEntry & entry(ConstIterator i) const
Access to ParameterEntry (i.e., returns i-&gt;second)
any & getAny(bool activeQry=true)
Direct access to the Teuchos::any data value underlying this object. The bool argument activeQry (def...
Templated array class derived from the STL std::vector.
RCP< const ParameterListModifier > getModifier() const
Return the optional modifier object.
Default traits class that just returns typeid(T).name().
void setStringParameterFromArray(const std::string &paramName, const Array< T > &array, ParameterList *paramList)
Set a std::string parameter representation of an array.
size_type size() const
bool isType(const std::string &name) const
Whether the given parameter exists in this list and has type T.
EValidateDefaults
Validation defaults enum.
std::string typeName() const
Return the name of the type.
params_t::Iterator Iterator
Parameter container iterator typedef.
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
Creates an empty sublist and returns a reference to the sublist name. If the list already exists...
ParameterList & setName(const std::string &name)
Set the name of *this list.
Smart reference counting pointer class for automatic garbage collection.
const std::type_info & type() const
Return the type of value being stored.
bool operator==(BigUInt< n > const &a, BigUInt< n > const &b)
ParameterEntry & getEntry(const std::string &name)
Retrieves an entry with the name name.
StringIndexedOrderedValueObjectContainer< ParameterEntry > params_t
Internal data-structure.
Ptr< ObjType > getNonconstObjPtr(const Ordinal &idx)
Get a nonconst semi-persisting association with the stored object indexed by ordinal.
EValidateUsed
Validation used enum.
RCP< ParameterList > parameterList(const std::string &name)
Nonmember constructor.
Reference-counted pointer class and non-member templated function implementations.
static std::string concreteName(const ParameterList &)
#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...
Simple wrapper class for raw pointers to single objects where no persisting relationship exists...
PrintOptions & showFlags(bool _showFlags)
#define TEUCHOS_TEST_FOR_EXCEPTION_PURE_MSG(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
Replacement for std::vector that is compatible with the Teuchos Memory Management classes...