43 #ifndef TEUCHOS_PARAMETER_LIST_H
44 #define TEUCHOS_PARAMETER_LIST_H
50 #include "TeuchosParameterList_config.h"
153 PrintOptions() : indent_(0), showTypes_(false), showFlags_(false), showDoc_(false), showDefault_(true) {}
288 std::string
const& docString =
"",
296 std::string
const& name,
char value[], std::string
const& docString =
"",
305 std::string
const& name,
const char value[], std::string
const& docString =
"",
313 std::string
const& name,
ParameterList const& value, std::string
const& docString =
""
320 template <
typename U,
typename = std::enable_if_t<std::is_same_v<std::decay_t<U>, ParameterEntry>>>
330 int const depth = 1000);
353 T&
get(
const std::string& name, T def_value);
358 std::string&
get(
const std::string& name,
char def_value[]);
363 std::string&
get(
const std::string& name,
const char def_value[]);
396 T&
get (
const std::string& name);
426 const T&
get (
const std::string& name)
const;
435 T* getPtr(
const std::string& name);
444 const T* getPtr(
const std::string& name)
const;
506 std::string
const& name,
bool throwIfNotExists = true
520 const std::string& name,
bool mustAlreadyExist =
false,
521 const std::string& docString =
""
530 const std::string& docString =
""
545 const std::string& name()
const;
551 bool isParameter (
const std::string& name)
const;
557 bool isSublist (
const std::string& name)
const;
565 bool isType (
const std::string& name)
const;
567 #ifndef DOXYGEN_SHOULD_SKIP_THIS
579 bool isType(
const std::string& name, T* ptr)
const;
583 Ordinal numParams ()
const;
603 std::ostream&
print(std::ostream& os,
int indent = 0,
bool showTypes =
false,
bool showFlags =
true,
bool showDefault =
true )
const;
606 void unused(std::ostream& os)
const;
609 std::string currentParametersString()
const;
677 void validateParameters(
679 int const depth = 1000,
721 void validateParametersAndSetDefaults(
723 int const depth = 1000
740 void modifyParameterList(
ParameterList &validParamList,
int const depth = 1000);
753 const bool left_to_right =
true);
766 void validateEntryExists(
const std::string &funcName,
const std::string &name,
771 void validateEntryType(
const std::string &funcName,
const std::string &name,
774 void validateEntryIsList(
const std::string &name,
const ParameterEntry &entry)
const;
776 void validateMissingSublistMustExist(
const std::string &baselist_name,
777 const std::string &sublist_name,
const bool mustAlreadyExist)
const;
779 void updateSubListNames(
int depth = 0);
784 std::string name_ =
"ANONYMOUS";
798 bool disableRecursiveValidation_ =
false;
801 bool disableRecursiveModification_ =
false;
804 bool disableRecursiveReconciliation_ =
false;
872 static std::string
name() {
return "ParameterList"; }
892 return !( list1 == list2 );
921 bool verbose =
false);
957 std::string
const& name_in, T
const& value_in, std::string
const& docString_in,
963 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
965 const std::string docString =
966 (docString_in.length() ? docString_in : param->docString());
968 (
nonnull(validator_in) ? validator_in : param->validator());
970 ParameterEntry param_new(value_in,
false,
false, docString, validator );
972 validator->validate(param_new, name_in, this->
name());
978 ParameterEntry param_new(value_in,
false,
false, docString_in, validator_in);
980 param_new.
validator()->validate(param_new, name_in, this->
name());
990 std::string
const& name_in,
char value[], std::string
const& docString
993 {
return set(name_in, std::string(value), docString, validator); }
998 const std::string& name_in,
const char value[],
const std::string &docString
1001 {
return set( name_in, std::string(value), docString, validator ); }
1006 std::string
const& name_in,
ParameterList const& value, std::string
const&
1014 template <
typename U,
typename>
1022 template<
typename T>
1027 for (itr = this->
begin(); itr != this->
end(); ++itr){
1028 const std::string &entry_name = itr->first;
1029 if (this->
isSublist(entry_name) && depth > 0){
1033 if (theEntry->
isType<T>()){
1044 template<
typename T>
1049 if (param_idx == SIOVOCB::getInvalidOrdinal()) {
1054 this->
template validateEntryType<T>(
"get", name_in, *param);
1055 return getValue<T>(*param);
1061 {
return get(name_in, std::string(def_value)); }
1066 {
return get(name_in, std::string(def_value)); }
1069 template<
typename T>
1074 this->
template validateEntryType<T>(
"get",name_in,*foundEntry);
1075 return getValue<T>(*foundEntry);
1079 template<
typename T>
1084 this->
template validateEntryType<T>(
"get",name_in,*foundEntry);
1085 return getValue<T>(*foundEntry);
1089 template<
typename T>
1095 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1097 if (param_ptr->isType<T>()) {
1098 return ¶m_ptr->getValue<T>(0);
1110 template<
typename T>
1116 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1118 if (param_ptr->isType<T>()) {
1119 return ¶m_ptr->getValue<T>(0);
1152 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1165 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1177 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1189 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1211 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1212 template<
typename T>
1217 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1225 template<
typename T>
1228 return this->
isType(name_in, static_cast<T*>(0));
1280 template<
typename T>
1283 const std::string &,
const std::string &name_in,
1289 ,
"Error! An attempt was made to access parameter \""<<name_in<<
"\""
1291 "\nin the parameter (sub)list \""<<this->
name()<<
"\""
1307 template<
typename T>
1310 return l.template get<T>(name);
1319 template<
typename T>
1323 return getParameter<T>(l,name);
1333 template<
typename T>
1336 return l.template get<T>(name);
1347 template<
typename T>
1351 return l.template getPtr<T>(name);
1362 template<
typename T>
1366 return l.template getPtr<T>(name);
1376 template<
typename T>
1380 return l.
isType( name, (T*)NULL );
1390 template<
typename T>
1394 return l.
isType( name, (T*)NULL );
1409 template<
typename T>
1411 const std::string ¶mName
1485 template<
typename T>
1488 ,
const std::string ¶mName
1489 ,
const int arrayDim = -1
1490 ,
const bool mustExist =
true
1493 std::string arrayStr;
1495 arrayStr = getParameter<std::string>(paramList,paramName);
1499 *arrayStrPtr = getParameterPtr<std::string>(paramList,paramName);
1501 arrayStr = *arrayStrPtr;
1509 a = fromStringToArray<T>(arrayStr);
1514 ,
"Error! The parameter \""<<paramName<<
"\"\n"
1515 "in the sublist \""<<paramList.
name()<<
"\"\n"
1516 "exists, but the std::string value:\n"
1520 "is not a valid array represntation!"
1524 ( ( a.
size()>0 && arrayDim>=0 ) && static_cast<int>(a.
size())!=arrayDim )
1526 ,
"Error! The parameter \""<<paramName<<
"\"\n"
1527 "in the sublist \""<<paramList.
name()<<
"\"\n"
1528 "exists and is a valid array, but the dimension of\n"
1529 "the read in array a.size() = " << a.
size() <<
"\n"
1530 "was not equal to the expected size arrayDim = " << arrayDim <<
"!"
1548 template<
typename T>
1552 bool param_exists =
false;
1553 bool overwrite =
false;
1554 if (paramName == newName){
1558 param_exists =
true;
1560 "The parameter " << paramName <<
" is not of type " <<
typeid(T).name());
1562 std::logic_error,
"The parameter " << newName <<
" already exists in this "
1566 pl.
set(newName, params);
1568 return param_exists;
1578 bool mustAlreadyExist =
false,
const std::string& docString =
""
1581 return rcpWithEmbeddedObjPostDestroy(
1582 ¶mList->
sublist(name, mustAlreadyExist, docString), paramList, false );
1594 return rcpWithEmbeddedObjPostDestroy(
1595 ¶mList->
sublist(name), paramList, false );
void print() const
Print function to use in debugging in a debugger.
bool replaceParameterWithArray(const std::string ¶mName, const std::string &newName, ParameterList &pl)
Replace a parameter with an array containing the parameter.
Object held as the "value" in the Teuchos::ParameterList std::map.
const std::string & name() const
The name of this ParameterList.
C++ Standard Library compatable filtered iterator.
static std::string name()
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 ¶mList, const std::string ¶mName, 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'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 "value" 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.
PrintOptions & showDoc(bool _showDoc)
bool isType() const
Test the type of the data being contained.
RCP< ParameterList > sublist(const RCP< ParameterList > ¶mList, 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.
ConstIterator end() const
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.
PrintOptions copy() const
ParameterEntry & nonconstEntry(Iterator i)
Access to ParameterEntry (i.e., returns i->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 > ¶mList, 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->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().
ConstIterator begin() const
void setStringParameterFromArray(const std::string ¶mName, const Array< T > &array, ParameterList *paramList)
Set a std::string parameter representation of an array.
PrintOptions & incrIndent(int indents)
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 &)
Base types for StringIndexedOrderedValueObjectContainer.
#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 & indent(int _indent)
static std::string name()
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...