10#ifndef TEUCHOS_PARAMETER_LIST_H
11#define TEUCHOS_PARAMETER_LIST_H
17#include "TeuchosParameterList_config.h"
18#include "Teuchos_ParameterListExceptions.hpp"
21#include "Teuchos_StringIndexedOrderedValueObjectContainer.hpp"
22#include "Teuchos_Assert.hpp"
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); }
255 std::string
const& docString =
"",
263 template<
typename T,
typename S,
typename = std::enable_if_t<std::is_convertible_v<S, std::remove_const_t<T>>>>
266 std::string
const& docString =
"",
274 std::string
const&
name,
char value[], std::string
const& docString =
"",
283 std::string
const&
name,
const char value[], std::string
const& docString =
"",
291 std::string
const&
name,
ParameterList const& value, std::string
const& docString =
""
298 template <
typename U,
typename = std::enable_if_t<std::is_same_v<std::decay_t<U>, ParameterEntry>>>
308 int const depth = 1000);
331 T&
get(
const std::string&
name, T def_value);
336 std::string&
get(
const std::string&
name,
char def_value[]);
341 std::string&
get(
const std::string&
name,
const char def_value[]);
374 T&
get (
const std::string&
name);
404 const T&
get (
const std::string&
name)
const;
422 const T*
getPtr(
const std::string&
name)
const;
484 std::string
const&
name,
bool throwIfNotExists =
true
498 const std::string&
name,
bool mustAlreadyExist =
false,
499 const std::string& docString =
""
508 const std::string& docString =
""
523 const std::string&
name()
const;
545#ifndef DOXYGEN_SHOULD_SKIP_THIS
581 std::ostream&
print(std::ostream& os,
int indent = 0,
bool showTypes =
false,
bool showFlags =
true,
bool showDefault =
true )
const;
584 void unused(std::ostream& os)
const;
657 int const depth = 1000,
701 int const depth = 1000
731 const bool left_to_right =
true);
738 inline Iterator nonconstBegin();
740 inline Iterator nonconstEnd();
744 void validateEntryExists(
const std::string &funcName,
const std::string &
name,
749 void validateEntryType(
const std::string &funcName,
const std::string &
name,
754 void validateMissingSublistMustExist(
const std::string &baselist_name,
755 const std::string &sublist_name,
const bool mustAlreadyExist)
const;
757 void updateSubListNames(
int depth = 0);
762 std::string name_ =
"ANONYMOUS";
776 bool disableRecursiveValidation_ =
false;
779 bool disableRecursiveModification_ =
false;
782 bool disableRecursiveReconciliation_ =
false;
850 static std::string name() {
return "ParameterList"; }
870 return !( list1 == list2 );
899 bool verbose =
false);
935 std::string
const& name_in, T&& value_in, std::string
const& docString_in,
940 const Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
941 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
943 const std::string docString =
944 (docString_in.length() ? docString_in : param->docString());
946 (
nonnull(validator_in) ? validator_in : param->validator());
948 ParameterEntry param_new(std::forward<T>(value_in),
false,
false, docString, validator );
950 validator->validate(param_new, name_in, this->
name());
956 ParameterEntry param_new(std::forward<T>(value_in),
false,
false, docString_in, validator_in);
958 param_new.
validator()->validate(param_new, name_in, this->
name());
960 params_.setObj(name_in, param_new);
965template<
typename T,
typename S,
typename>
968 std::string
const& name_in,
const S& value_in, std::string
const& docString_in,
972 return set(name_in,
static_cast<const T&
>(value_in), docString_in, validator_in);
977 std::string
const& name_in,
char value[], std::string
const& docString
980{
return set(name_in, std::string(value), docString, validator); }
985 const std::string& name_in,
const char value[],
const std::string &docString
988{
return set( name_in, std::string(value), docString, validator ); }
993 std::string
const& name_in,
ParameterList const& value, std::string
const&
1001template <
typename U,
typename>
1005 params_.setObj(name_in, std::forward<U>(entry_in));
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){
1020 if (theEntry->
isType<T>()){
1035 Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
1036 if (param_idx == SIOVOCB::getInvalidOrdinal()) {
1038 param_idx = params_.setObj(name_in,
ParameterEntry(def_value,
true));
1041 this->
template validateEntryType<T>(
"get", name_in, *param);
1048{
return get(name_in, std::string(def_value)); }
1053{
return get(name_in, std::string(def_value)); }
1060 validateEntryExists(
"get",name_in,foundEntry);
1061 this->
template validateEntryType<T>(
"get",name_in,*foundEntry);
1070 validateEntryExists(
"get",name_in,foundEntry);
1071 this->
template validateEntryType<T>(
"get",name_in,*foundEntry);
1081 const Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
1082 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1084 if (param_ptr->isType<T>()) {
1085 return ¶m_ptr->getValue<T>(0);
1102 const Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
1103 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1105 if (param_ptr->isType<T>()) {
1106 return ¶m_ptr->getValue<T>(0);
1119 validateEntryExists(
"get", name_in, foundEntry);
1128 validateEntryExists(
"get", name_in, foundEntry);
1138 const Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
1139 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1140 return &*params_.getNonconstObjPtr(param_idx);
1151 const Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
1152 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1153 return &*params_.getObjPtr(param_idx);
1163 const Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
1164 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1165 return rcpFromPtr(params_.getNonconstObjPtr(param_idx));
1175 const Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
1176 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1177 return rcpFromPtr(params_.getObjPtr(param_idx));
1185{
return modifier_; }
1198#ifndef DOXYGEN_SHOULD_SKIP_THIS
1204 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1205 return params_.
getObjPtr(param_idx)->isType<T>();
1215 return this->
isType(name_in,
static_cast<T*
>(0));
1224 return params_.begin();
1230 return params_.end();
1249inline ParameterList::Iterator ParameterList::nonconstBegin()
1255inline ParameterList::Iterator ParameterList::nonconstEnd()
1269void ParameterList::validateEntryType(
1270 const std::string &,
const std::string &name_in,
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()<<
"\""
1398 const std::string ¶mName
1404 paramList->
set(paramName,toString(array));
1475 ,
const std::string ¶mName
1476 ,
const int arrayDim = -1
1477 ,
const bool mustExist =
true
1480 std::string arrayStr;
1488 arrayStr = *arrayStrPtr;
1501 ,
"Error! The parameter \""<<paramName<<
"\"\n"
1502 "in the sublist \""<<paramList.
name()<<
"\"\n"
1503 "exists, but the std::string value:\n"
1507 "is not a valid array represntation!"
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 <<
"!"
1539 bool param_exists =
false;
1540 bool overwrite =
false;
1541 if (paramName == newName){
1545 param_exists =
true;
1547 "The parameter " << paramName <<
" is not of type " <<
typeid(T).name());
1549 std::logic_error,
"The parameter " << newName <<
" already exists in this "
1553 pl.
set(newName, params);
1555 return param_exists;
1565 bool mustAlreadyExist =
false,
const std::string& docString =
""
1569 ¶mList->sublist(
name, mustAlreadyExist, docString), paramList,
false );
1582 ¶mList->sublist(
name), paramList,
false );
Templated array class derived from the STL std::vector.
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.
Replacement for std::vector that is compatible with the Teuchos Memory Management classes.
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.
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.
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).
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.
ParameterList & setParametersNotAlreadySet(const ParameterList &source)
void setStringParameterFromArray(const std::string ¶mName, const Array< T > &array, ParameterList *paramList)
Set a std::string parameter representation of an array.
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 > ¶mList, 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,...
RCP< ParameterList > createParameterList(const std::string &name)
Nonmember constructor.
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 ¶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...
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.
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.
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Templated set method.
void modifyParameterList(ParameterList &validParamList, int const depth=1000)
Modify the valid parameter list prior to validation.
bool replaceParameterWithArray(const std::string ¶mName, 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.
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()
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,...
ConstIterator begin() const
An iterator pointing to the first entry.
RCP< ParameterList > createParameterList()
Nonmember constructor.
ParameterList & disableRecursiveModification()
RCP< ParameterList > parameterList()
Nonmember constructor.
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....
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).
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.
Base types for StringIndexedOrderedValueObjectContainer.
String indexed ordered value-type object container class.
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>.
Default traits class that just returns typeid(T).name().
static std::string name()
#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.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...
@ VALIDATE_DEFAULTS_ENABLED
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
@ VALIDATE_DEFAULTS_DISABLED