Teuchos Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
Teuchos_ParameterList.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
43#ifndef TEUCHOS_PARAMETER_LIST_H
44#define TEUCHOS_PARAMETER_LIST_H
45
49
54#include "Teuchos_Assert.hpp"
55#include "Teuchos_RCP.hpp"
56#include "Teuchos_Array.hpp"
57#include "Teuchos_map.hpp"
58
59
63
64namespace Teuchos {
65
77
89
134
137
140
141public:
142
144
145
148
151 public:
152 PrintOptions() : indent_(0), showTypes_(false), showFlags_(false), showDoc_(false), showDefault_(true) {}
153 PrintOptions& indent(int _indent) { indent_ = _indent; return *this; }
154 PrintOptions& showTypes(bool _showTypes) { showTypes_ = _showTypes; return *this; }
155 PrintOptions& showFlags(bool _showFlags) { showFlags_ = _showFlags; return *this; }
156 PrintOptions& showDoc(bool _showDoc) { showDoc_ = _showDoc; return *this; }
157 PrintOptions& showDefault(bool _showDefault) { showDefault_ = _showDefault; return *this; }
158 PrintOptions& incrIndent(int indents) { indent_ += indents; return *this; }
159 int indent() const { return indent_; }
160 bool showTypes() const { return showTypes_; }
161 bool showFlags() const { return showFlags_; }
162 bool showDoc() const { return showDoc_; }
163 bool showDefault() const { return showDefault_; }
164 PrintOptions copy() const { return PrintOptions(*this); }
165 private:
171 };
172
174
176
177
179 ParameterList() = default;
180
182 ParameterList(const std::string &name,
183 RCP<const ParameterListModifier> const& modifier = null);
184
186 ParameterList(const ParameterList& source);
187
189 virtual ~ParameterList();
190
192
194
196 ParameterList& setName( const std::string &name );
197
201 ParameterList& operator= (const ParameterList& source);
202
203 void setModifier(
205 );
206
216
227
236
246
256
265
284 template<typename T>
285 ParameterList& set (std::string const& name,
286 T const& value,
287 std::string const& docString = "",
288 RCP<const ParameterEntryValidator> const& validator = null);
289
295 std::string const& name, char value[], std::string const& docString = "",
297 );
298
304 std::string const& name, const char value[], std::string const& docString = "",
306 );
307
312 std::string const& name, ParameterList const& value, std::string const& docString = ""
313 );
314
319 template <typename U, typename = std::enable_if_t<std::is_same_v<std::decay_t<U>, ParameterEntry>>>
320 ParameterList& setEntry(const std::string& name, U&& entry);
321
327 template<typename T>
329 int const depth = 1000);
330
332
334
351 template<typename T>
352 T& get(const std::string& name, T def_value);
353
357 std::string& get(const std::string& name, char def_value[]);
358
362 std::string& get(const std::string& name, const char def_value[]);
363
394 template<typename T>
395 T& get (const std::string& name);
396
424 template<typename T>
425 const T& get (const std::string& name) const;
426
432 template<typename T>
433 inline
434 T* getPtr(const std::string& name);
435
441 template<typename T>
442 inline
443 const T* getPtr(const std::string& name) const;
444
445 // ToDo: Add getSafePtr() functions to return Ptr<T> instead of raw T*
446
452 ParameterEntry& getEntry(const std::string& name);
453
459 inline
460 const ParameterEntry& getEntry(const std::string& name) const;
461
464 inline
465 ParameterEntry* getEntryPtr(const std::string& name);
466
467 // ToDo: Add function called getEntrySafePtr() to return Ptr<> as the main
468 // implementation and deprecate getEntryPtr()
469
472 inline
473 const ParameterEntry* getEntryPtr(const std::string& name) const;
474
477 inline RCP<ParameterEntry> getEntryRCP(const std::string& name);
478
481 inline RCP<const ParameterEntry> getEntryRCP(const std::string& name) const;
482
485
487
489
490
504 bool remove(
505 std::string const& name, bool throwIfNotExists = true
506 );
507
509
511
512
519 const std::string& name, bool mustAlreadyExist = false,
520 const std::string& docString = ""
521 );
522
528 const std::string& name, RCP<const ParameterListModifier> const& modifier,
529 const std::string& docString = ""
530 );
531
536 const ParameterList& sublist(const std::string& name) const;
537
539
541
542
544 const std::string& name() const;
545
550 bool isParameter (const std::string& name) const;
551
556 bool isSublist (const std::string& name) const;
557
563 template<typename T>
564 bool isType (const std::string& name) const;
565
566#ifndef DOXYGEN_SHOULD_SKIP_THIS
577 template<typename T>
578 bool isType(const std::string& name, T* ptr) const;
579#endif
580
582 Ordinal numParams () const;
583
585
587
588
594 void print() const;
595
598 std::ostream& print(std::ostream& os, const PrintOptions &printOptions) const;
599
602 std::ostream& print(std::ostream& os, int indent = 0, bool showTypes = false, bool showFlags = true, bool showDefault = true ) const;
603
605 void unused(std::ostream& os) const;
606
608 std::string currentParametersString() const;
609
611
613
614
616 inline ConstIterator begin() const;
617
619 inline ConstIterator end() const;
620
622 inline const std::string& name(ConstIterator i) const;
623
625 inline const ParameterEntry& entry(ConstIterator i) const;
626
628
630
631
677 ParameterList const& validParamList,
678 int const depth = 1000,
679 EValidateUsed const validateUsed = VALIDATE_USED_ENABLED,
680 EValidateDefaults const validateDefaults = VALIDATE_DEFAULTS_ENABLED
681 ) const;
682
721 ParameterList const& validParamList,
722 int const depth = 1000
723 );
724
739 void modifyParameterList(ParameterList &validParamList, int const depth = 1000);
740
751 void reconcileParameterList(ParameterList &validParamList,
752 const bool left_to_right = true);
753
755
756private: // Functions
757
759 inline Iterator nonconstBegin();
761 inline Iterator nonconstEnd();
765 void validateEntryExists(const std::string &funcName, const std::string &name,
766 const ParameterEntry *entry) const;
767 // ToDo: Change above function to take Ptr<> instead of raw pointer.
769 template<typename T>
770 void validateEntryType(const std::string &funcName, const std::string &name,
771 const ParameterEntry &entry ) const;
773 void validateEntryIsList(const std::string &name, const ParameterEntry &entry) const;
775 void validateMissingSublistMustExist(const std::string &baselist_name,
776 const std::string &sublist_name, const bool mustAlreadyExist) const;
778 void updateSubListNames(int depth = 0);
779
780private: // Data members
781
783 std::string name_ = "ANONYMOUS";
784
786//use pragmas to disable some false-positive warnings for windows sharedlibs export
787//#ifdef _MSC_VER
788//#pragma warning(push)
789//#pragma warning(disable:4251)
790//#endif
792//#ifdef _MSC_VER
793//#pragma warning(pop)
794//#endif
795
798
801
804
806};
807
808
813inline
818
819
824inline
826{
827 return rcp(new ParameterList(name));
828}
829
830
835inline
837{
838 return rcp(new ParameterList(source));
839}
840
841
846inline
851
852
857inline
859{
860 return rcp(new ParameterList(name));
861}
862
863
868template<>
870public:
871 static std::string name() { return "ParameterList"; }
872 static std::string concreteName( const ParameterList& /*t2*/ )
873 { return name(); }
874};
875
876
882
883
888inline
889bool operator!=( const ParameterList& list1, const ParameterList& list2 )
890{
891 return !( list1 == list2 );
892}
893
894
901
905 const ParameterList& list2);
906
907
920 bool verbose = false);
921
922
935 const ParameterList& list2, bool verbose = false);
936
937
938// /////////////////////////////////////////////////////
939// Inline and Template Function Definitions
940
941
942inline
943ParameterList& ParameterList::setName( const std::string &name_in )
944{
945 name_ = name_in;
946 return *this;
947}
948
949
950// Set functions
951
952
953template<typename T>
954inline
956 std::string const& name_in, T const& value_in, std::string const& docString_in,
957 RCP<const ParameterEntryValidator> const& validator_in
958 )
959{
961 const Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
962 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
963 Ptr<ParameterEntry> param = params_.getNonconstObjPtr(param_idx);
964 const std::string docString =
965 (docString_in.length() ? docString_in : param->docString());
966 const RCP<const ParameterEntryValidator> validator =
967 (nonnull(validator_in) ? validator_in : param->validator());
968 // Create temp param to validate before setting
969 ParameterEntry param_new(value_in, false, false, docString, validator );
970 if (nonnull(validator)) {
971 validator->validate(param_new, name_in, this->name());
972 }
973 // Strong guarantee: (if exception is thrown, the value is not changed)
974 *param = param_new;
975 }
976 else {
977 ParameterEntry param_new(value_in, false, false, docString_in, validator_in);
978 if (nonnull(param_new.validator())) {
979 param_new.validator()->validate(param_new, name_in, this->name());
980 }
981 params_.setObj(name_in, param_new);
982 }
983 return *this;
984}
985
986
987inline
989 std::string const& name_in, char value[], std::string const& docString
990 ,RCP<const ParameterEntryValidator> const& validator
991 )
992{ return set(name_in, std::string(value), docString, validator); }
993
994
995inline
997 const std::string& name_in, const char value[], const std::string &docString
998 ,RCP<const ParameterEntryValidator> const& validator
999 )
1000{ return set( name_in, std::string(value), docString, validator ); }
1001
1002
1003inline
1005 std::string const& name_in, ParameterList const& value, std::string const& /*docString*/
1006 )
1007{
1008 sublist(name_in) = value;
1009 return *this;
1010}
1011
1012
1013template <typename U, typename>
1014inline
1015ParameterList& ParameterList::setEntry(std::string const& name_in, U&& entry_in)
1016{
1017 params_.setObj(name_in, std::forward<U>(entry_in));
1018 return *this;
1019}
1020
1021template<typename T>
1023 RCP<const ParameterEntryValidator> const& validator, int const depth)
1024{
1025 ConstIterator itr;
1026 for (itr = this->begin(); itr != this->end(); ++itr){
1027 const std::string &entry_name = itr->first;
1028 if (this->isSublist(entry_name) && depth > 0){
1029 this->sublist(entry_name).recursivelySetValidator<T>(validator, depth - 1);
1030 } else{
1031 ParameterEntry *theEntry = this->getEntryPtr(entry_name);
1032 if (theEntry->isType<T>()){
1033 theEntry->setValidator(validator);
1034 }
1035 }
1036 }
1037}
1038
1039
1040// Get functions
1041
1042
1043template<typename T>
1044T& ParameterList::get(const std::string& name_in, T def_value)
1045{
1047 Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
1048 if (param_idx == SIOVOCB::getInvalidOrdinal()) {
1049 // Param does not exist
1050 param_idx = params_.setObj(name_in, ParameterEntry(def_value, true));
1051 }
1052 Ptr<ParameterEntry> param = params_.getNonconstObjPtr(param_idx);
1053 this->template validateEntryType<T>("get", name_in, *param);
1054 return getValue<T>(*param);
1055}
1056
1057
1058inline
1059std::string& ParameterList::get(const std::string& name_in, char def_value[])
1060{ return get(name_in, std::string(def_value)); }
1061
1062
1063inline
1064std::string& ParameterList::get(const std::string& name_in, const char def_value[])
1065{ return get(name_in, std::string(def_value)); }
1066
1067
1068template<typename T>
1069T& ParameterList::get(const std::string& name_in)
1070{
1071 ParameterEntry *foundEntry = this->getEntryPtr(name_in);
1072 validateEntryExists("get",name_in,foundEntry);
1073 this->template validateEntryType<T>("get",name_in,*foundEntry);
1074 return getValue<T>(*foundEntry);
1075}
1076
1077
1078template<typename T>
1079const T& ParameterList::get(const std::string& name_in) const
1080{
1081 const ParameterEntry *foundEntry = this->getEntryPtr(name_in);
1082 validateEntryExists("get",name_in,foundEntry);
1083 this->template validateEntryType<T>("get",name_in,*foundEntry);
1084 return getValue<T>(*foundEntry);
1085}
1086
1087
1088template<typename T>
1089inline
1090T* ParameterList::getPtr(const std::string& name_in)
1091{
1093 const Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
1094 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1095 const Ptr<ParameterEntry> param_ptr = params_.getNonconstObjPtr(param_idx);
1096 if (param_ptr->isType<T>()) {
1097 return &param_ptr->getValue<T>(0);
1098 }
1099 // Note: The above is inefficinet. You have to do the dynamic_cast twice
1100 // (once to see if it is the type and once to do the cast). This could be
1101 // made more efficinet by upgrading Teuchos::any to add a any_cast_ptr()
1102 // function but I don't think anyone actually uses this function.
1103 return 0;
1104 }
1105 return 0;
1106}
1107
1108
1109template<typename T>
1110inline
1111const T* ParameterList::getPtr(const std::string& name_in) const
1112{
1114 const Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
1115 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1116 const Ptr<const ParameterEntry> param_ptr = params_.getObjPtr(param_idx);
1117 if (param_ptr->isType<T>()) {
1118 return &param_ptr->getValue<T>(0);
1119 }
1120 // Note: The above is inefficinet, see above non-const getPtr() function.
1121 return 0;
1122 }
1123 return 0;
1124}
1125
1126
1127inline
1128ParameterEntry& ParameterList::getEntry(const std::string& name_in)
1129{
1130 ParameterEntry *foundEntry = this->getEntryPtr(name_in);
1131 validateEntryExists("get", name_in, foundEntry);
1132 return *foundEntry;
1133}
1134
1135
1136inline
1137const ParameterEntry& ParameterList::getEntry(const std::string& name_in) const
1138{
1139 const ParameterEntry *foundEntry = this->getEntryPtr(name_in);
1140 validateEntryExists("get", name_in, foundEntry);
1141 return *foundEntry;
1142}
1143
1144
1145inline
1147ParameterList::getEntryPtr(const std::string& name_in)
1148{
1150 const Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
1151 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1152 return &*params_.getNonconstObjPtr(param_idx);
1153 }
1154 return 0;
1155}
1156
1157
1158inline
1159const ParameterEntry*
1160ParameterList::getEntryPtr(const std::string& name_in) const
1161{
1163 const Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
1164 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1165 return &*params_.getObjPtr(param_idx);
1166 }
1167 return 0;
1168}
1169
1170
1172ParameterList::getEntryRCP(const std::string& name_in)
1173{
1175 const Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
1176 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1177 return rcpFromPtr(params_.getNonconstObjPtr(param_idx));
1178 }
1179 return null;
1180}
1181
1182
1184ParameterList::getEntryRCP(const std::string& name_in) const
1185{
1187 const Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
1188 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1189 return rcpFromPtr(params_.getObjPtr(param_idx));
1190 }
1191 return null;
1192}
1193
1194
1198
1199
1200// Attribute Functions
1201
1202
1203inline
1204const std::string& ParameterList::name() const
1205{
1206 return name_;
1207}
1208
1209
1210#ifndef DOXYGEN_SHOULD_SKIP_THIS
1211template<typename T>
1212bool ParameterList::isType(const std::string& name_in, T* /*ptr*/) const
1213{
1215 const Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
1216 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1217 return params_.getObjPtr(param_idx)->isType<T>();
1218 }
1219 return false;
1220}
1221#endif
1222
1223
1224template<typename T>
1225bool ParameterList::isType(const std::string& name_in) const
1226{
1227 return this->isType(name_in, static_cast<T*>(0));
1228}
1229
1230
1231// Read-only access to the iterator
1232
1233
1235{
1236 return params_.begin();
1237}
1238
1239
1241{
1242 return params_.end();
1243}
1244
1245
1246inline const std::string& ParameterList::name(ConstIterator i) const
1247{
1248 return (i->first);
1249}
1250
1251
1253{
1254 return (i->second);
1255}
1256
1257
1258// private
1259
1260
1262{
1263 return params_.nonconstBegin();
1264}
1265
1266
1268{
1269 return params_.nonconstEnd();
1270}
1271
1272
1274{
1275 return (i->second);
1276}
1277
1278
1279template<typename T>
1280inline
1282 const std::string &/*funcName*/, const std::string &name_in,
1283 const ParameterEntry &entry_in
1284 ) const
1285{
1287 entry_in.getAny().type() != typeid(T), Exceptions::InvalidParameterType
1288 ,"Error! An attempt was made to access parameter \""<<name_in<<"\""
1289 " of type \""<<entry_in.getAny().typeName()<<"\""
1290 "\nin the parameter (sub)list \""<<this->name()<<"\""
1291 "\nusing the incorrect type \""<<TypeNameTraits<T>::name()<<"\"!"
1292 );
1293}
1294
1295
1296// //////////////////////////////////////
1297// Helper functions
1298
1299
1306template<typename T>
1307T& getParameter( ParameterList& l, const std::string& name )
1308{
1309 return l.template get<T>(name);
1310}
1311
1312
1318template<typename T>
1319inline
1320T& get( ParameterList& l, const std::string& name )
1321{
1322 return getParameter<T>(l,name);
1323}
1324
1325
1332template<typename T>
1333const T& getParameter( const ParameterList& l, const std::string& name )
1334{
1335 return l.template get<T>(name);
1336}
1337
1338
1346template<typename T>
1347inline
1348T* getParameterPtr( ParameterList& l, const std::string& name )
1349{
1350 return l.template getPtr<T>(name);
1351}
1352
1353
1361template<typename T>
1362inline
1363const T* getParameterPtr( const ParameterList& l, const std::string& name )
1364{
1365 return l.template getPtr<T>(name);
1366}
1367
1368
1375template<typename T>
1376inline
1377bool isParameterType( ParameterList& l, const std::string& name )
1378{
1379 return l.isType( name, (T*)NULL );
1380}
1381
1382
1389template<typename T>
1390inline
1391bool isParameterType( const ParameterList& l, const std::string& name )
1392{
1393 return l.isType( name, (T*)NULL );
1394}
1395
1396
1408template<typename T>
1410 const std::string &paramName
1411 ,const Array<T> &array
1412 ,ParameterList *paramList
1413 )
1414{
1415 TEUCHOS_TEST_FOR_EXCEPT(!paramList);
1416 paramList->set(paramName,toString(array));
1417}
1418
1419
1484template<typename T>
1486 const ParameterList &paramList
1487 ,const std::string &paramName
1488 ,const int arrayDim = -1
1489 ,const bool mustExist = true
1490 )
1491{
1492 std::string arrayStr;
1493 if(mustExist) {
1494 arrayStr = getParameter<std::string>(paramList,paramName);
1495 }
1496 else {
1497 const std::string
1498 *arrayStrPtr = getParameterPtr<std::string>(paramList,paramName);
1499 if(arrayStrPtr) {
1500 arrayStr = *arrayStrPtr;
1501 }
1502 else {
1503 return Array<T>(); // Return an empty array
1504 }
1505 }
1506 Array<T> a;
1507 try {
1508 a = fromStringToArray<T>(arrayStr);
1509 }
1510 catch( const InvalidArrayStringRepresentation&) {
1513 ,"Error! The parameter \""<<paramName<<"\"\n"
1514 "in the sublist \""<<paramList.name()<<"\"\n"
1515 "exists, but the std::string value:\n"
1516 "----------\n"
1517 <<arrayStr<<
1518 "\n----------\n"
1519 "is not a valid array represntation!"
1520 );
1521 }
1523 ( ( a.size()>0 && arrayDim>=0 ) && static_cast<int>(a.size())!=arrayDim )
1525 ,"Error! The parameter \""<<paramName<<"\"\n"
1526 "in the sublist \""<<paramList.name()<<"\"\n"
1527 "exists and is a valid array, but the dimension of\n"
1528 "the read in array a.size() = " << a.size() << "\n"
1529 "was not equal to the expected size arrayDim = " << arrayDim << "!"
1530 );
1531 return a;
1532}
1533
1534
1547template<typename T>
1548bool replaceParameterWithArray(const std::string &paramName, const std::string &newName,
1549 ParameterList &pl)
1550{
1551 bool param_exists = false;
1552 bool overwrite = false;
1553 if (paramName == newName){
1554 overwrite = true;
1555 }
1556 if (pl.isParameter(paramName)){
1557 param_exists = true;
1558 TEUCHOS_TEST_FOR_EXCEPTION(!pl.isType<T>(paramName), std::logic_error,
1559 "The parameter " << paramName << " is not of type " << typeid(T).name());
1560 TEUCHOS_TEST_FOR_EXCEPTION(pl.isParameter(newName) && !overwrite,
1561 std::logic_error, "The parameter " << newName << " already exists in this "
1562 "parameter list.");
1563 Array<T> params = tuple<T>(pl.get<T>(paramName));
1564 pl.remove(paramName);
1565 pl.set(newName, params);
1566 }
1567 return param_exists;
1568}
1569
1570
1574inline
1576 const RCP<ParameterList> &paramList, const std::string& name,
1577 bool mustAlreadyExist = false, const std::string& docString = ""
1578 )
1579{
1581 &paramList->sublist(name, mustAlreadyExist, docString), paramList, false );
1582}
1583
1584
1588inline
1590 const RCP<const ParameterList> &paramList, const std::string& name
1591 )
1592{
1594 &paramList->sublist(name), paramList, false );
1595}
1596
1597
1601inline std::ostream& operator<<(std::ostream& os, const ParameterList& l)
1602{
1603 return l.print(os);
1604}
1605
1606
1607} // end of Teuchos namespace
1608
1609
1610#endif
Templated array class derived from the STL std::vector.
#define TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT
Object held as the "value" in the Teuchos::ParameterList std::map.
Parameter List Modifier class.
Reference-counted pointer class and non-member templated function implementations.
Provides std::map class for deficient platforms.
ParameterList()=default
Constructor.
Replacement for std::vector that is compatible with the Teuchos Memory Management classes.
size_type size() const
Array< T > fromStringToArray(const std::string &arrayStr)
Converts from std::string representation (as created by toString()) back into the array object.
This object is held as the "value" in the Teuchos::ParameterList std::map.
void setValidator(RCP< const ParameterEntryValidator > const &validator)
Set the validator.
bool isType() const
Test the type of the data being contained.
any & getAny(bool activeQry=true)
Direct access to the Teuchos::any data value underlying this object. The bool argument activeQry (def...
RCP< const ParameterEntryValidator > validator() const
Return the (optional) validator object.
T & getValue(const ParameterEntry &entry)
A templated helper function for returning the value of type T held in the ParameterEntry object,...
Utility class for setting and passing in print options.
PrintOptions & showFlags(bool _showFlags)
PrintOptions & showTypes(bool _showTypes)
PrintOptions & showDefault(bool _showDefault)
A list of parameters of arbitrary type.
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT bool operator==(const ParameterList &list1, const ParameterList &list2)
Returns true if two parameter lists are the same.
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....
T & get(ParameterList &l, const std::string &name)
A shorter name for getParameter().
void reconcileParameterList(ParameterList &validParamList, const bool left_to_right=true)
Reconcile a parameter list after validation.
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT bool haveSameValues(const ParameterList &list1, const ParameterList &list2, bool verbose=false)
Returns true if two parameter lists have the same values.
ParameterList & setEntry(const std::string &name, U &&entry)
Set a parameter directly as a ParameterEntry.
ParameterList & setParameters(const ParameterList &source)
const ParameterEntry & entry(ConstIterator i) const
Access to ParameterEntry (i.e., returns i->second).
RCP< const ParameterListModifier > modifier_
ConstIterator end() const
An iterator pointing beyond the last entry.
bool isType(const std::string &name) const
Whether the given parameter exists in this list and has type T.
Ordinal numParams() const
Get the number of stored parameters.
ParameterEntry & nonconstEntry(Iterator i)
Access to ParameterEntry (i.e., returns i->second).
void validateEntryIsList(const std::string &name, const ParameterEntry &entry) const
Validate a sublist param is indeed a sublist.
ParameterList & setParametersNotAlreadySet(const ParameterList &source)
void setStringParameterFromArray(const std::string &paramName, const Array< T > &array, ParameterList *paramList)
Set a std::string parameter representation of an array.
params_t params_
Parameter list.
RCP< const ParameterListModifier > getModifier() const
Return the optional modifier object.
void validateParameters(ParameterList const &validParamList, int const depth=1000, EValidateUsed const validateUsed=VALIDATE_USED_ENABLED, EValidateDefaults const validateDefaults=VALIDATE_DEFAULTS_ENABLED) const
Validate the parameters in this list given valid selections in the input list.
void unused(std::ostream &os) const
Print out unused parameters in the ParameterList.
void validateParametersAndSetDefaults(ParameterList const &validParamList, int const depth=1000)
Validate the parameters in this list given valid selections in the input list and set defaults for th...
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 & 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 & 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.
RCP< ParameterList > createParameterList(const std::string &name)
Nonmember constructor.
bool disableRecursiveModification_
Modify into list or not.
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 ...
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...
Iterator nonconstEnd()
An iterator pointing beyond the last 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.
RCP< ParameterList > parameterList(const ParameterList &source)
Nonmember constructor.
void print() const
Print function to use in debugging in a debugger.
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT bool haveSameValuesSorted(const ParameterList &list1, const ParameterList &list2, bool verbose=false)
Returns true if two parameter lists have the same values independent of ordering.
const std::string & name() const
The name of this ParameterList.
ParameterList()=default
Constructor.
void modifyParameterList(ParameterList &validParamList, int const depth=1000)
Modify the valid parameter list prior to validation.
bool replaceParameterWithArray(const std::string &paramName, const std::string &newName, ParameterList &pl)
Replace a parameter with an array containing the parameter.
bool isSublist(const std::string &name) const
Whether the given sublist exists in this list.
params_t::Iterator Iterator
Parameter container iterator typedef.
std::string & get(const std::string &name, const char def_value[])
Specialization of get(), where the nominal value is a character string. Both char* and std::string ar...
ParameterList & disableRecursiveValidation()
ParameterList & disableRecursiveReconciliation()
bool disableRecursiveValidation_
Validate into list or not.
ParameterList & set(std::string const &name, const char value[], std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Specialization of set() for a parameter which is a const char[].
ParameterEntry * getEntryPtr(const std::string &name)
Retrieves the pointer for an entry with the name name if it exists.
params_t::ConstIterator ConstIterator
Parameter container const iterator typedef.
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,...
std::string name_
Name of the (sub)list.
ConstIterator begin() const
An iterator pointing to the first entry.
StringIndexedOrderedValueObjectContainer< ParameterEntry > params_t
Internal data-structure.
RCP< ParameterList > createParameterList()
Nonmember constructor.
ParameterList & disableRecursiveModification()
RCP< ParameterList > parameterList()
Nonmember constructor.
void validateEntryExists(const std::string &funcName, const std::string &name, const ParameterEntry *entry) const
Validate that a parameter exists.
void validateMissingSublistMustExist(const std::string &baselist_name, const std::string &sublist_name, const bool mustAlreadyExist) const
Throw a sublist does not exist exception.
bool disableRecursiveReconciliation_
Reconcile into list or not.
ParameterEntry & getEntry(const std::string &name)
Retrieves an entry with the name name.
std::string currentParametersString() const
Create a single formated std::string of all of the zero-level parameters in this list.
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 validateEntryType(const std::string &funcName, const std::string &name, const ParameterEntry &entry) const
Validate that a type is the same.
RCP< ParameterList > parameterList(const std::string &name)
Nonmember constructor.
bool operator!=(const ParameterList &list1, const ParameterList &list2)
Returns true if two parameter lists are not the same.
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...
void recursivelySetValidator(RCP< const ParameterEntryValidator > const &validator, int const depth=1000)
Recursively attach a validator to parameters of type T.
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...
bool isParameter(const std::string &name) const
Whether the given parameter exists in this list.
T & get(const std::string &name, T def_value)
Return the parameter's value, or the default value if it is not there.
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT bool haveSameModifiers(const ParameterList &list1, const ParameterList &list2)
Returns true if two parameter lists have the same modifiers.
T * getParameterPtr(ParameterList &l, const std::string &name)
A templated helper function for getting a pointer to a parameter from a non-const list,...
ParameterList & setName(const std::string &name)
Set the name of *this list.
RCP< ParameterEntry > getEntryRCP(const std::string &name)
Retrieves the RCP for an entry with the name name if it exists.
ParameterList & disableRecursiveAll()
bool remove(std::string const &name, bool throwIfNotExists=true)
Remove a parameter (does not depend on the type of the parameter).
void updateSubListNames(int depth=0)
Update sublist names recursively.
Iterator nonconstBegin()
An iterator pointing to the first entry.
void setModifier(RCP< const ParameterListModifier > const &modifier)
EValidateDefaults
Validation defaults enum.
EValidateUsed
Validation used enum.
std::ostream & operator<<(std::ostream &os, const ParameterList &l)
Output stream operator for handling the printing of the parameter list.
Simple wrapper class for raw pointers to single objects where no persisting relationship exists.
Ptr< T > ptr(T *p)
Create a pointer to an object from a raw pointer.
Smart reference counting pointer class for automatic garbage collection.
RCP< T > rcpFromPtr(const Ptr< T > &ptr)
Create an RCP<T> from a Ptr<T> object.
RCP< T > rcpWithEmbeddedObjPostDestroy(T *p, const Embedded &embedded, bool owns_mem=true)
Create an RCP with and also put in an embedded object.
Ordinal getObjOrdinalIndex(const std::string &key) const
Get the ordinal index given the string key.
FilteredIterator< typename key_and_obj_array_t::const_iterator, SelectActive< ParameterEntry > > ConstIterator
FilteredIterator< typename key_and_obj_array_t::iterator, SelectActive< ParameterEntry > > Iterator
Ptr< const ObjType > getObjPtr(const Ordinal &idx) const
Get a const semi-persisting association with the stored object indexed by ordinal.
Tuple< T, 1 > tuple(const T &a)
Create a Tuple<T,1>.
static std::string concreteName(const ParameterList &)
Default traits class that just returns typeid(T).name().
std::string typeName() const
Return the name of the type.
const std::type_info & type() const
Return the type of value being stored.
#define TEUCHOS_TEST_FOR_EXCEPTION_PURE_MSG(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
#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.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
bool nonnull(const std::shared_ptr< T > &p)
Returns true if p.get()!=NULL.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
std::string toString(const HashSet< Key > &h)