43 #ifndef TEUCHOS_PARAMETER_LIST_H
44 #define TEUCHOS_PARAMETER_LIST_H
152 PrintOptions() : indent_(0), showTypes_(false), showFlags_(false), showDoc_(false) {}
189 Ordinal numParams ()
const;
287 std::string
const& docString =
"",
295 std::string
const& name,
char value[], std::string
const& docString =
"",
304 std::string
const& name,
const char value[], std::string
const& docString =
"",
312 std::string
const& name,
ParameterList const& value, std::string
const& docString =
""
328 int const depth = 1000);
351 T& get(
const std::string& name, T def_value);
356 std::string& get(
const std::string& name,
char def_value[]);
361 std::string&
get(
const std::string& name,
const char def_value[]);
394 T& get (
const std::string& name);
424 const T& get (
const std::string& name)
const;
433 T* getPtr(
const std::string& name);
442 const T* getPtr(
const std::string& name)
const;
504 std::string
const& name,
bool throwIfNotExists =
true
518 const std::string& name,
bool mustAlreadyExist =
false,
519 const std::string& docString =
""
528 const std::string& docString =
""
543 const std::string& name()
const;
549 bool isParameter (
const std::string& name)
const;
555 bool isSublist (
const std::string& name)
const;
563 bool isType (
const std::string& name)
const;
565 #ifndef DOXYGEN_SHOULD_SKIP_THIS
577 bool isType(
const std::string& name, T* ptr)
const;
598 std::ostream&
print(std::ostream& os,
int indent = 0,
bool showTypes =
false,
bool showFlags =
true )
const;
601 void unused(std::ostream& os)
const;
604 std::string currentParametersString()
const;
672 void validateParameters(
674 int const depth = 1000,
716 void validateParametersAndSetDefaults(
718 int const depth = 1000
735 void modifyParameterList(
ParameterList &validParamList,
int const depth = 1000);
748 const bool left_to_right =
true);
761 void validateEntryExists(
const std::string &funcName,
const std::string &name,
766 void validateEntryType(
const std::string &funcName,
const std::string &name,
769 void validateEntryIsList(
const std::string &name,
const ParameterEntry &entry)
const;
771 void validateMissingSublistMustExist(
const std::string &baselist_name,
772 const std::string &sublist_name,
const bool mustAlreadyExist)
const;
774 void updateSubListNames(
int depth = 0);
779 std::string name_ =
"ANONYMOUS";
793 bool disableRecursiveValidation_ =
false;
796 bool disableRecursiveModification_ =
false;
799 bool disableRecursiveReconciliation_ =
false;
867 static std::string
name() {
return "ParameterList"; }
887 return !( list1 == list2 );
916 bool verbose =
false);
952 std::string
const& name_in, T
const& value_in, std::string
const& docString_in,
958 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
960 const std::string docString =
961 (docString_in.length() ? docString_in : param->docString());
963 (
nonnull(validator_in) ? validator_in : param->validator());
965 ParameterEntry param_new(value_in,
false,
false, docString, validator );
967 validator->validate(param_new, name_in, this->
name());
973 ParameterEntry param_new(value_in,
false,
false, docString_in, validator_in);
975 param_new.
validator()->validate(param_new, name_in, this->
name());
985 std::string
const& name_in,
char value[], std::string
const& docString
988 {
return set(name_in, std::string(value), docString, validator); }
993 const std::string& name_in,
const char value[],
const std::string &docString
996 {
return set( name_in, std::string(value), docString, validator ); }
1001 std::string
const& name_in,
ParameterList const& value, std::string
const&
1017 template<
typename T>
1022 for (itr = this->
begin(); itr != this->
end(); ++itr){
1023 const std::string &entry_name = itr->first;
1024 if (this->
isSublist(entry_name) && depth > 0){
1028 if (theEntry->
isType<T>()){
1039 template<
typename T>
1044 if (param_idx == SIOVOCB::getInvalidOrdinal()) {
1049 this->
template validateEntryType<T>(
"get", name_in, *param);
1050 return getValue<T>(*param);
1056 {
return get(name_in, std::string(def_value)); }
1061 {
return get(name_in, std::string(def_value)); }
1064 template<
typename T>
1069 this->
template validateEntryType<T>(
"get",name_in,*foundEntry);
1070 return getValue<T>(*foundEntry);
1074 template<
typename T>
1079 this->
template validateEntryType<T>(
"get",name_in,*foundEntry);
1080 return getValue<T>(*foundEntry);
1084 template<
typename T>
1090 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1092 if (param_ptr->isType<T>()) {
1093 return ¶m_ptr->getValue<T>(0);
1105 template<
typename T>
1111 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1113 if (param_ptr->isType<T>()) {
1114 return ¶m_ptr->getValue<T>(0);
1147 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1160 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1172 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1184 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1206 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1207 template<
typename T>
1212 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1220 template<
typename T>
1223 return this->
isType(name_in,
static_cast<T*
>(0));
1275 template<
typename T>
1278 const std::string &,
const std::string &name_in,
1284 ,
"Error! An attempt was made to access parameter \""<<name_in<<
"\""
1286 "\nin the parameter (sub)list \""<<this->name()<<
"\""
1302 template<
typename T>
1305 return l.template get<T>(name);
1314 template<
typename T>
1318 return getParameter<T>(l,name);
1328 template<
typename T>
1331 return l.template get<T>(name);
1342 template<
typename T>
1346 return l.template getPtr<T>(name);
1357 template<
typename T>
1361 return l.template getPtr<T>(name);
1371 template<
typename T>
1375 return l.
isType( name, (T*)NULL );
1385 template<
typename T>
1389 return l.
isType( name, (T*)NULL );
1404 template<
typename T>
1406 const std::string ¶mName
1480 template<
typename T>
1483 ,
const std::string ¶mName
1484 ,
const int arrayDim = -1
1485 ,
const bool mustExist =
true
1488 std::string arrayStr;
1490 arrayStr = getParameter<std::string>(paramList,paramName);
1494 *arrayStrPtr = getParameterPtr<std::string>(paramList,paramName);
1496 arrayStr = *arrayStrPtr;
1504 a = fromStringToArray<T>(arrayStr);
1509 ,
"Error! The parameter \""<<paramName<<
"\"\n"
1510 "in the sublist \""<<paramList.
name()<<
"\"\n"
1511 "exists, but the std::string value:\n"
1515 "is not a valid array represntation!"
1519 ( ( a.
size()>0 && arrayDim>=0 ) &&
static_cast<int>(a.
size())!=arrayDim )
1521 ,
"Error! The parameter \""<<paramName<<
"\"\n"
1522 "in the sublist \""<<paramList.
name()<<
"\"\n"
1523 "exists and is a valid array, but the dimension of\n"
1524 "the read in array a.size() = " << a.
size() <<
"\n"
1525 "was not equal to the expected size arrayDim = " << arrayDim <<
"!"
1543 template<
typename T>
1547 bool param_exists =
false;
1548 bool overwrite =
false;
1549 if (paramName == newName){
1553 param_exists =
true;
1555 "The parameter " << paramName <<
" is not of type " <<
typeid(T).name());
1557 std::logic_error,
"The parameter " << newName <<
" already exists in this "
1561 pl.
set(newName, params);
1563 return param_exists;
1573 bool mustAlreadyExist =
false,
const std::string& docString =
""
1576 return rcpWithEmbeddedObjPostDestroy(
1577 ¶mList->sublist(name, mustAlreadyExist, docString), paramList,
false );
1589 return rcpWithEmbeddedObjPostDestroy(
1590 ¶mList->sublist(name), paramList,
false );
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.
Replacement for std::vector that is compatible with the Teuchos Memory Management classes.
C++ Standard Library compatable filtered iterator.
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.
Utility class for setting and passing in print options.
PrintOptions & showDoc(bool _showDoc)
PrintOptions & incrIndent(int indents)
PrintOptions & showFlags(bool _showFlags)
PrintOptions copy() const
PrintOptions & showTypes(bool _showTypes)
PrintOptions & indent(int _indent)
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().
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[].
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.
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.
ParameterEntry & nonconstEntry(Iterator i)
Access to ParameterEntry (i.e., returns i->second)
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...
void setStringParameterFromArray(const std::string ¶mName, 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.
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,...
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.
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...
Iterator nonconstEnd()
An iterator pointing beyond the last 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.
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.
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.
params_t::Iterator Iterator
Parameter container iterator typedef.
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.
RCP< ParameterList > parameterList()
Nonmember constructor.
void validateEntryExists(const std::string &funcName, const std::string &name, const ParameterEntry *entry) const
Validate that a parameter exists.
ParameterEntry & getEntry(const std::string &name)
Retrieves an entry with the name name.
ParameterList & setEntry(const std::string &name, const ParameterEntry &entry)
Set a parameter directly as a ParameterEntry.
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.
bool remove(std::string const &name, bool throwIfNotExists=true)
Remove a parameter (does not depend on the type of the parameter).
Iterator nonconstBegin()
An iterator pointing to the first entry.
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.
Smart reference counting pointer class for automatic garbage collection.
Base types for StringIndexedOrderedValueObjectContainer.
ConstIterator end() const
Ordinal getObjOrdinalIndex(const std::string &key) const
Get the ordinal index given the string key.
ConstIterator begin() const
Ptr< ObjType > getNonconstObjPtr(const Ordinal &idx)
Get a nonconst semi-persisting association with the stored object indexed by ordinal.
Ordinal setObj(const std::string &key, const ObjType &obj)
Set (or reset) object by value and return its ordinal index.
Ptr< const ObjType > getObjPtr(const Ordinal &idx) const
Get a const semi-persisting association with the stored object indexed by ordinal.
static std::string concreteName(const ParameterList &)
static std::string name()
Default traits class that just returns typeid(T).name().
const std::type_info & type() const
Return the type of value being stored.
std::string typeName() const
Return the name of the type.
#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.
@ VALIDATE_DEFAULTS_ENABLED
@ VALIDATE_DEFAULTS_DISABLED
std::string toString(const HashSet< Key > &h)
myDepList set(dependee1, "val1")
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.