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&& value,
255  std::string const& docString = "",
256  RCP<const ParameterEntryValidator> const& validator = null);
257 
263  template<typename T, typename S, typename = std::enable_if_t<std::is_convertible_v<S, std::remove_const_t<T>>>>
264  ParameterList& set (std::string const& name,
265  const S& value,
266  std::string const& docString = "",
267  RCP<const ParameterEntryValidator> const& validator = null);
268 
273  ParameterList& set(
274  std::string const& name, char value[], std::string const& docString = "",
275  RCP<const ParameterEntryValidator> const& validator = null
276  );
277 
282  ParameterList& set(
283  std::string const& name, const char value[], std::string const& docString = "",
284  RCP<const ParameterEntryValidator> const& validator = null
285  );
286 
290  ParameterList& set(
291  std::string const& name, ParameterList const& value, std::string const& docString = ""
292  );
293 
298  template <typename U, typename = std::enable_if_t<std::is_same_v<std::decay_t<U>, ParameterEntry>>>
299  ParameterList& setEntry(const std::string& name, U&& entry);
300 
306  template<typename T>
307  void recursivelySetValidator(RCP<const ParameterEntryValidator> const& validator,
308  int const depth = 1000);
309 
311 
313 
330  template<typename T>
331  T& get(const std::string& name, T def_value);
332 
336  std::string& get(const std::string& name, char def_value[]);
337 
341  std::string& get(const std::string& name, const char def_value[]);
342 
373  template<typename T>
374  T& get (const std::string& name);
375 
403  template<typename T>
404  const T& get (const std::string& name) const;
405 
411  template<typename T>
412  inline
413  T* getPtr(const std::string& name);
414 
420  template<typename T>
421  inline
422  const T* getPtr(const std::string& name) const;
423 
424  // ToDo: Add getSafePtr() functions to return Ptr<T> instead of raw T*
425 
431  ParameterEntry& getEntry(const std::string& name);
432 
438  inline
439  const ParameterEntry& getEntry(const std::string& name) const;
440 
443  inline
444  ParameterEntry* getEntryPtr(const std::string& name);
445 
446  // ToDo: Add function called getEntrySafePtr() to return Ptr<> as the main
447  // implementation and deprecate getEntryPtr()
448 
451  inline
452  const ParameterEntry* getEntryPtr(const std::string& name) const;
453 
456  inline RCP<ParameterEntry> getEntryRCP(const std::string& name);
457 
460  inline RCP<const ParameterEntry> getEntryRCP(const std::string& name) const;
461 
463  inline RCP<const ParameterListModifier> getModifier() const;
464 
466 
468 
469 
483  bool remove(
484  std::string const& name, bool throwIfNotExists = true
485  );
486 
488 
490 
491 
497  ParameterList& sublist(
498  const std::string& name, bool mustAlreadyExist = false,
499  const std::string& docString = ""
500  );
501 
506  ParameterList& sublist(
507  const std::string& name, RCP<const ParameterListModifier> const& modifier,
508  const std::string& docString = ""
509  );
510 
515  const ParameterList& sublist(const std::string& name) const;
516 
518 
520 
521 
523  const std::string& name() const;
524 
529  bool isParameter (const std::string& name) const;
530 
535  bool isSublist (const std::string& name) const;
536 
542  template<typename T>
543  bool isType (const std::string& name) const;
544 
545 #ifndef DOXYGEN_SHOULD_SKIP_THIS
546 
556  template<typename T>
557  bool isType(const std::string& name, T* ptr) const;
558 #endif
559 
561  Ordinal numParams () const;
562 
564 
566 
567 
573  void print() const;
574 
577  std::ostream& print(std::ostream& os, const PrintOptions &printOptions) const;
578 
581  std::ostream& print(std::ostream& os, int indent = 0, bool showTypes = false, bool showFlags = true, bool showDefault = true ) const;
582 
584  void unused(std::ostream& os) const;
585 
587  std::string currentParametersString() const;
588 
590 
592 
593 
595  inline ConstIterator begin() const;
596 
598  inline ConstIterator end() const;
599 
601  inline const std::string& name(ConstIterator i) const;
602 
604  inline const ParameterEntry& entry(ConstIterator i) const;
605 
607 
609 
610 
655  void validateParameters(
656  ParameterList const& validParamList,
657  int const depth = 1000,
658  EValidateUsed const validateUsed = VALIDATE_USED_ENABLED,
659  EValidateDefaults const validateDefaults = VALIDATE_DEFAULTS_ENABLED
660  ) const;
661 
699  void validateParametersAndSetDefaults(
700  ParameterList const& validParamList,
701  int const depth = 1000
702  );
703 
718  void modifyParameterList(ParameterList &validParamList, int const depth = 1000);
719 
730  void reconcileParameterList(ParameterList &validParamList,
731  const bool left_to_right = true);
732 
734 
735 private: // Functions
736 
738  inline Iterator nonconstBegin();
740  inline Iterator nonconstEnd();
742  inline ParameterEntry& nonconstEntry(Iterator i);
744  void validateEntryExists(const std::string &funcName, const std::string &name,
745  const ParameterEntry *entry) const;
746  // ToDo: Change above function to take Ptr<> instead of raw pointer.
748  template<typename T>
749  void validateEntryType(const std::string &funcName, const std::string &name,
750  const ParameterEntry &entry ) const;
752  void validateEntryIsList(const std::string &name, const ParameterEntry &entry) const;
754  void validateMissingSublistMustExist(const std::string &baselist_name,
755  const std::string &sublist_name, const bool mustAlreadyExist) const;
757  void updateSubListNames(int depth = 0);
758 
759 private: // Data members
760 
762  std::string name_ = "ANONYMOUS";
763 
765 //use pragmas to disable some false-positive warnings for windows sharedlibs export
766 //#ifdef _MSC_VER
767 //#pragma warning(push)
768 //#pragma warning(disable:4251)
769 //#endif
771 //#ifdef _MSC_VER
772 //#pragma warning(pop)
773 //#endif
774 
776  bool disableRecursiveValidation_ = false;
777 
779  bool disableRecursiveModification_ = false;
780 
782  bool disableRecursiveReconciliation_ = false;
783 
785 };
786 
787 
792 inline
794 {
795  return rcp(new ParameterList);
796 }
797 
798 
803 inline
804 RCP<ParameterList> parameterList(const std::string &name)
805 {
806  return rcp(new ParameterList(name));
807 }
808 
809 
814 inline
816 {
817  return rcp(new ParameterList(source));
818 }
819 
820 
825 inline
827 {
828  return rcp(new ParameterList);
829 }
830 
831 
836 inline
837 RCP<ParameterList> createParameterList(const std::string &name)
838 {
839  return rcp(new ParameterList(name));
840 }
841 
842 
847 template<>
849 public:
850  static std::string name() { return "ParameterList"; }
851  static std::string concreteName( const ParameterList& /*t2*/ )
852  { return name(); }
853 };
854 
855 
860 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT bool operator==( const ParameterList& list1, const ParameterList& list2 );
861 
862 
867 inline
868 bool operator!=( const ParameterList& list1, const ParameterList& list2 )
869 {
870  return !( list1 == list2 );
871 }
872 
873 
881 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT bool haveSameModifiers (const ParameterList& list1,
884  const ParameterList& list2);
885 
886 
898 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT bool haveSameValues( const ParameterList& list1, const ParameterList& list2,
899  bool verbose = false);
900 
901 
913 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT bool haveSameValuesSorted( const ParameterList& list1,
914  const ParameterList& list2, bool verbose = false);
915 
916 
917 // /////////////////////////////////////////////////////
918 // Inline and Template Function Definitions
919 
920 
921 inline
922 ParameterList& ParameterList::setName( const std::string &name_in )
923 {
924  name_ = name_in;
925  return *this;
926 }
927 
928 
929 // Set functions
930 
931 
932 template<typename T>
933 inline
935  std::string const& name_in, T&& value_in, std::string const& docString_in,
936  RCP<const ParameterEntryValidator> const& validator_in
937  )
938 {
940  const Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
941  if (param_idx != SIOVOCB::getInvalidOrdinal()) {
942  Ptr<ParameterEntry> param = params_.getNonconstObjPtr(param_idx);
943  const std::string docString =
944  (docString_in.length() ? docString_in : param->docString());
945  const RCP<const ParameterEntryValidator> validator =
946  (nonnull(validator_in) ? validator_in : param->validator());
947  // Create temp param to validate before setting
948  ParameterEntry param_new(std::forward<T>(value_in), false, false, docString, validator );
949  if (nonnull(validator)) {
950  validator->validate(param_new, name_in, this->name());
951  }
952  // Strong guarantee: (if exception is thrown, the value is not changed)
953  *param = param_new;
954  }
955  else {
956  ParameterEntry param_new(std::forward<T>(value_in), false, false, docString_in, validator_in);
957  if (nonnull(param_new.validator())) {
958  param_new.validator()->validate(param_new, name_in, this->name());
959  }
960  params_.setObj(name_in, param_new);
961  }
962  return *this;
963 }
964 
965 template<typename T, typename S, typename>
966 inline
968  std::string const& name_in, const S& value_in, std::string const& docString_in,
969  RCP<const ParameterEntryValidator> const& validator_in
970  )
971 {
972  return set(name_in, static_cast<const T&>(value_in), docString_in, validator_in);
973 }
974 
975 inline
977  std::string const& name_in, char value[], std::string const& docString
978  ,RCP<const ParameterEntryValidator> const& validator
979  )
980 { return set(name_in, std::string(value), docString, validator); }
981 
982 
983 inline
985  const std::string& name_in, const char value[], const std::string &docString
986  ,RCP<const ParameterEntryValidator> const& validator
987  )
988 { return set( name_in, std::string(value), docString, validator ); }
989 
990 
991 inline
993  std::string const& name_in, ParameterList const& value, std::string const& /*docString*/
994  )
995 {
996  sublist(name_in) = value;
997  return *this;
998 }
999 
1000 
1001 template <typename U, typename>
1002 inline
1003 ParameterList& ParameterList::setEntry(std::string const& name_in, U&& entry_in)
1004 {
1005  params_.setObj(name_in, std::forward<U>(entry_in));
1006  return *this;
1007 }
1008 
1009 template<typename T>
1011  RCP<const ParameterEntryValidator> const& validator, int const depth)
1012 {
1013  ConstIterator itr;
1014  for (itr = this->begin(); itr != this->end(); ++itr){
1015  const std::string &entry_name = itr->first;
1016  if (this->isSublist(entry_name) && depth > 0){
1017  this->sublist(entry_name).recursivelySetValidator<T>(validator, depth - 1);
1018  } else{
1019  ParameterEntry *theEntry = this->getEntryPtr(entry_name);
1020  if (theEntry->isType<T>()){
1021  theEntry->setValidator(validator);
1022  }
1023  }
1024  }
1025 }
1026 
1027 
1028 // Get functions
1029 
1030 
1031 template<typename T>
1032 T& ParameterList::get(const std::string& name_in, T def_value)
1033 {
1035  Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
1036  if (param_idx == SIOVOCB::getInvalidOrdinal()) {
1037  // Param does not exist
1038  param_idx = params_.setObj(name_in, ParameterEntry(def_value, true));
1039  }
1040  Ptr<ParameterEntry> param = params_.getNonconstObjPtr(param_idx);
1041  this->template validateEntryType<T>("get", name_in, *param);
1042  return getValue<T>(*param);
1043 }
1044 
1045 
1046 inline
1047 std::string& ParameterList::get(const std::string& name_in, char def_value[])
1048 { return get(name_in, std::string(def_value)); }
1049 
1050 
1051 inline
1052 std::string& ParameterList::get(const std::string& name_in, const char def_value[])
1053 { return get(name_in, std::string(def_value)); }
1054 
1055 
1056 template<typename T>
1057 T& ParameterList::get(const std::string& name_in)
1058 {
1059  ParameterEntry *foundEntry = this->getEntryPtr(name_in);
1060  validateEntryExists("get",name_in,foundEntry);
1061  this->template validateEntryType<T>("get",name_in,*foundEntry);
1062  return getValue<T>(*foundEntry);
1063 }
1064 
1065 
1066 template<typename T>
1067 const T& ParameterList::get(const std::string& name_in) const
1068 {
1069  const ParameterEntry *foundEntry = this->getEntryPtr(name_in);
1070  validateEntryExists("get",name_in,foundEntry);
1071  this->template validateEntryType<T>("get",name_in,*foundEntry);
1072  return getValue<T>(*foundEntry);
1073 }
1074 
1075 
1076 template<typename T>
1077 inline
1078 T* ParameterList::getPtr(const std::string& name_in)
1079 {
1081  const Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
1082  if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1083  const Ptr<ParameterEntry> param_ptr = params_.getNonconstObjPtr(param_idx);
1084  if (param_ptr->isType<T>()) {
1085  return &param_ptr->getValue<T>(0);
1086  }
1087  // Note: The above is inefficinet. You have to do the dynamic_cast twice
1088  // (once to see if it is the type and once to do the cast). This could be
1089  // made more efficinet by upgrading Teuchos::any to add a any_cast_ptr()
1090  // function but I don't think anyone actually uses this function.
1091  return 0;
1092  }
1093  return 0;
1094 }
1095 
1096 
1097 template<typename T>
1098 inline
1099 const T* ParameterList::getPtr(const std::string& name_in) const
1100 {
1102  const Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
1103  if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1104  const Ptr<const ParameterEntry> param_ptr = params_.getObjPtr(param_idx);
1105  if (param_ptr->isType<T>()) {
1106  return &param_ptr->getValue<T>(0);
1107  }
1108  // Note: The above is inefficinet, see above non-const getPtr() function.
1109  return 0;
1110  }
1111  return 0;
1112 }
1113 
1114 
1115 inline
1116 ParameterEntry& ParameterList::getEntry(const std::string& name_in)
1117 {
1118  ParameterEntry *foundEntry = this->getEntryPtr(name_in);
1119  validateEntryExists("get", name_in, foundEntry);
1120  return *foundEntry;
1121 }
1122 
1123 
1124 inline
1125 const ParameterEntry& ParameterList::getEntry(const std::string& name_in) const
1126 {
1127  const ParameterEntry *foundEntry = this->getEntryPtr(name_in);
1128  validateEntryExists("get", name_in, foundEntry);
1129  return *foundEntry;
1130 }
1131 
1132 
1133 inline
1135 ParameterList::getEntryPtr(const std::string& name_in)
1136 {
1138  const Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
1139  if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1140  return &*params_.getNonconstObjPtr(param_idx);
1141  }
1142  return 0;
1143 }
1144 
1145 
1146 inline
1147 const ParameterEntry*
1148 ParameterList::getEntryPtr(const std::string& name_in) const
1149 {
1151  const Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
1152  if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1153  return &*params_.getObjPtr(param_idx);
1154  }
1155  return 0;
1156 }
1157 
1158 
1159 inline RCP<ParameterEntry>
1160 ParameterList::getEntryRCP(const std::string& name_in)
1161 {
1163  const Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
1164  if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1165  return rcpFromPtr(params_.getNonconstObjPtr(param_idx));
1166  }
1167  return null;
1168 }
1169 
1170 
1172 ParameterList::getEntryRCP(const std::string& name_in) const
1173 {
1175  const Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
1176  if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1177  return rcpFromPtr(params_.getObjPtr(param_idx));
1178  }
1179  return null;
1180 }
1181 
1182 
1185 { return modifier_; }
1186 
1187 
1188 // Attribute Functions
1189 
1190 
1191 inline
1192 const std::string& ParameterList::name() const
1193 {
1194  return name_;
1195 }
1196 
1197 
1198 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1199 template<typename T>
1200 bool ParameterList::isType(const std::string& name_in, T* /*ptr*/) const
1201 {
1203  const Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
1204  if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1205  return params_.getObjPtr(param_idx)->isType<T>();
1206  }
1207  return false;
1208 }
1209 #endif
1210 
1211 
1212 template<typename T>
1213 bool ParameterList::isType(const std::string& name_in) const
1214 {
1215  return this->isType(name_in, static_cast<T*>(0));
1216 }
1217 
1218 
1219 // Read-only access to the iterator
1220 
1221 
1223 {
1224  return params_.begin();
1225 }
1226 
1227 
1229 {
1230  return params_.end();
1231 }
1232 
1233 
1234 inline const std::string& ParameterList::name(ConstIterator i) const
1235 {
1236  return (i->first);
1237 }
1238 
1239 
1241 {
1242  return (i->second);
1243 }
1244 
1245 
1246 // private
1247 
1248 
1250 {
1251  return params_.nonconstBegin();
1252 }
1253 
1254 
1256 {
1257  return params_.nonconstEnd();
1258 }
1259 
1260 
1262 {
1263  return (i->second);
1264 }
1265 
1266 
1267 template<typename T>
1268 inline
1270  const std::string &/*funcName*/, const std::string &name_in,
1271  const ParameterEntry &entry_in
1272  ) const
1273 {
1275  entry_in.getAny().type() != typeid(T), Exceptions::InvalidParameterType
1276  ,"Error! An attempt was made to access parameter \""<<name_in<<"\""
1277  " of type \""<<entry_in.getAny().typeName()<<"\""
1278  "\nin the parameter (sub)list \""<<this->name()<<"\""
1279  "\nusing the incorrect type \""<<TypeNameTraits<T>::name()<<"\"!"
1280  );
1281 }
1282 
1283 
1284 // //////////////////////////////////////
1285 // Helper functions
1286 
1287 
1294 template<typename T>
1295 T& getParameter( ParameterList& l, const std::string& name )
1296 {
1297  return l.template get<T>(name);
1298 }
1299 
1300 
1306 template<typename T>
1307 inline
1308 T& get( ParameterList& l, const std::string& name )
1309 {
1310  return getParameter<T>(l,name);
1311 }
1312 
1313 
1320 template<typename T>
1321 const T& getParameter( const ParameterList& l, const std::string& name )
1322 {
1323  return l.template get<T>(name);
1324 }
1325 
1326 
1334 template<typename T>
1335 inline
1336 T* getParameterPtr( ParameterList& l, const std::string& name )
1337 {
1338  return l.template getPtr<T>(name);
1339 }
1340 
1341 
1349 template<typename T>
1350 inline
1351 const T* getParameterPtr( const ParameterList& l, const std::string& name )
1352 {
1353  return l.template getPtr<T>(name);
1354 }
1355 
1356 
1363 template<typename T>
1364 inline
1365 bool isParameterType( ParameterList& l, const std::string& name )
1366 {
1367  return l.isType( name, (T*)NULL );
1368 }
1369 
1370 
1377 template<typename T>
1378 inline
1379 bool isParameterType( const ParameterList& l, const std::string& name )
1380 {
1381  return l.isType( name, (T*)NULL );
1382 }
1383 
1384 
1396 template<typename T>
1398  const std::string &paramName
1399  ,const Array<T> &array
1400  ,ParameterList *paramList
1401  )
1402 {
1403  TEUCHOS_TEST_FOR_EXCEPT(!paramList);
1404  paramList->set(paramName,toString(array));
1405 }
1406 
1407 
1472 template<typename T>
1474  const ParameterList &paramList
1475  ,const std::string &paramName
1476  ,const int arrayDim = -1
1477  ,const bool mustExist = true
1478  )
1479 {
1480  std::string arrayStr;
1481  if(mustExist) {
1482  arrayStr = getParameter<std::string>(paramList,paramName);
1483  }
1484  else {
1485  const std::string
1486  *arrayStrPtr = getParameterPtr<std::string>(paramList,paramName);
1487  if(arrayStrPtr) {
1488  arrayStr = *arrayStrPtr;
1489  }
1490  else {
1491  return Array<T>(); // Return an empty array
1492  }
1493  }
1494  Array<T> a;
1495  try {
1496  a = fromStringToArray<T>(arrayStr);
1497  }
1498  catch( const InvalidArrayStringRepresentation&) {
1501  ,"Error! The parameter \""<<paramName<<"\"\n"
1502  "in the sublist \""<<paramList.name()<<"\"\n"
1503  "exists, but the std::string value:\n"
1504  "----------\n"
1505  <<arrayStr<<
1506  "\n----------\n"
1507  "is not a valid array represntation!"
1508  );
1509  }
1511  ( ( a.size()>0 && arrayDim>=0 ) && static_cast<int>(a.size())!=arrayDim )
1513  ,"Error! The parameter \""<<paramName<<"\"\n"
1514  "in the sublist \""<<paramList.name()<<"\"\n"
1515  "exists and is a valid array, but the dimension of\n"
1516  "the read in array a.size() = " << a.size() << "\n"
1517  "was not equal to the expected size arrayDim = " << arrayDim << "!"
1518  );
1519  return a;
1520 }
1521 
1522 
1535 template<typename T>
1536 bool replaceParameterWithArray(const std::string &paramName, const std::string &newName,
1537  ParameterList &pl)
1538 {
1539  bool param_exists = false;
1540  bool overwrite = false;
1541  if (paramName == newName){
1542  overwrite = true;
1543  }
1544  if (pl.isParameter(paramName)){
1545  param_exists = true;
1546  TEUCHOS_TEST_FOR_EXCEPTION(!pl.isType<T>(paramName), std::logic_error,
1547  "The parameter " << paramName << " is not of type " << typeid(T).name());
1548  TEUCHOS_TEST_FOR_EXCEPTION(pl.isParameter(newName) && !overwrite,
1549  std::logic_error, "The parameter " << newName << " already exists in this "
1550  "parameter list.");
1551  Array<T> params = tuple<T>(pl.get<T>(paramName));
1552  pl.remove(paramName);
1553  pl.set(newName, params);
1554  }
1555  return param_exists;
1556 }
1557 
1558 
1562 inline
1564  const RCP<ParameterList> &paramList, const std::string& name,
1565  bool mustAlreadyExist = false, const std::string& docString = ""
1566  )
1567 {
1568  return rcpWithEmbeddedObjPostDestroy(
1569  &paramList->sublist(name, mustAlreadyExist, docString), paramList, false );
1570 }
1571 
1572 
1576 inline
1578  const RCP<const ParameterList> &paramList, const std::string& name
1579  )
1580 {
1581  return rcpWithEmbeddedObjPostDestroy(
1582  &paramList->sublist(name), paramList, false );
1583 }
1584 
1585 
1589 inline std::ostream& operator<<(std::ostream& os, const ParameterList& l)
1590 {
1591  return l.print(os);
1592 }
1593 
1594 
1595 } // end of Teuchos namespace
1596 
1597 
1598 #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.
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.
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Templated set method.
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...