|
Teuchos - Trilinos Tools Package
Version of the Day
|
Go to the documentation of this file.
43 #ifndef TEUCHOS_PARAMETER_LIST_H
44 #define TEUCHOS_PARAMETER_LIST_H
50 #include "Teuchos_ParameterListExceptions.hpp"
52 #include "Teuchos_StringIndexedOrderedValueObjectContainer.hpp"
53 #include "Teuchos_Assert.hpp"
151 PrintOptions() : indent_(0), showTypes_(
false), showFlags_(
false), showDoc_(
false) {}
152 PrintOptions& indent(
int _indent) { indent_ = _indent;
return *
this; }
153 PrintOptions& showTypes(
bool _showTypes) { showTypes_ = _showTypes;
return *
this; }
154 PrintOptions& showFlags(
bool _showFlags) { showFlags_ = _showFlags;
return *
this; }
155 PrintOptions& showDoc(
bool _showDoc) { showDoc_ = _showDoc;
return *
this; }
156 PrintOptions& incrIndent(
int indents) { indent_ += indents;
return *
this; }
157 int indent()
const {
return indent_; }
158 bool showTypes()
const {
return showTypes_; }
159 bool showFlags()
const {
return showFlags_; }
160 bool showDoc()
const {
return showDoc_; }
187 Ordinal numParams ()
const;
252 std::string
const& docString =
"",
260 std::string
const& name,
char value[], std::string
const& docString =
"",
269 std::string
const& name,
const char value[], std::string
const& docString =
"",
277 std::string
const& name,
ParameterList const& value, std::string
const& docString =
""
307 T& get(
const std::string& name, T def_value);
312 std::string& get(
const std::string& name,
char def_value[]);
317 std::string& get(
const std::string& name,
const char def_value[]);
350 T& get (
const std::string& name);
380 const T& get (
const std::string& name)
const;
389 T* getPtr(
const std::string& name);
398 const T* getPtr(
const std::string& name)
const;
457 std::string
const& name,
bool throwIfNotExists =
true
471 const std::string& name,
bool mustAlreadyExist =
false
472 ,
const std::string& docString =
""
487 const std::string& name()
const;
493 bool isParameter (
const std::string& name)
const;
499 bool isSublist (
const std::string& name)
const;
507 bool isType (
const std::string& name)
const;
509 #ifndef DOXYGEN_SHOULD_SKIP_THIS
521 bool isType(
const std::string& name, T* ptr)
const;
538 std::ostream& print(std::ostream& os,
const PrintOptions &printOptions)
const;
542 std::ostream& print(std::ostream& os,
int indent = 0,
bool showTypes =
false,
bool showFlags =
true )
const;
545 void unused(std::ostream& os)
const;
548 std::string currentParametersString()
const;
616 void validateParameters(
618 int const depth = 1000,
660 void validateParametersAndSetDefaults(
662 int const depth = 1000
676 void validateEntryExists(
const std::string &funcName,
const std::string &name,
681 void validateEntryType(
const std::string &funcName,
const std::string &name,
684 void validateEntryIsList(
const std::string &name,
const ParameterEntry &entry)
const;
686 void validateMissingSublistMustExist(
const std::string &baselist_name,
687 const std::string &sublist_name,
const bool mustAlreadyExist)
const;
689 void updateSubListNames(
int depth = 0);
708 bool disableRecursiveValidation_;
775 static std::string name() {
return "ParameterList"; }
795 return !( list1 == list2 );
811 bool verbose =
false);
832 std::string
const& name_in, T
const& value_in, std::string
const& docString_in,
838 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
840 const std::string docString =
841 (docString_in.length() ? docString_in : param->docString());
843 (
nonnull(validator_in) ? validator_in : param->validator());
845 ParameterEntry param_new(value_in,
false,
false, docString, validator );
847 validator->validate(param_new, name_in, this->
name());
853 ParameterEntry param_new(value_in,
false,
false, docString_in, validator_in);
855 param_new.
validator()->validate(param_new, name_in, this->
name());
857 params_.
setObj(name_in, param_new);
865 std::string
const& name_in,
char value[], std::string
const& docString
868 {
return set(name_in, std::string(value), docString, validator); }
873 const std::string& name_in,
const char value[],
const std::string &docString
876 {
return set( name_in, std::string(value), docString, validator ); }
881 std::string
const& name_in,
ParameterList const& value, std::string
const&
892 params_.
setObj(name_in, entry_in);
905 if (param_idx == SIOVOCB::getInvalidOrdinal()) {
910 this->
template validateEntryType<T>(
"get", name_in, *param);
911 return getValue<T>(*param);
917 {
return get(name_in, std::string(def_value)); }
922 {
return get(name_in, std::string(def_value)); }
929 validateEntryExists(
"get",name_in,foundEntry);
930 this->
template validateEntryType<T>(
"get",name_in,*foundEntry);
931 return getValue<T>(*foundEntry);
939 validateEntryExists(
"get",name_in,foundEntry);
940 this->
template validateEntryType<T>(
"get",name_in,*foundEntry);
941 return getValue<T>(*foundEntry);
951 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
953 if (param_ptr->isType<T>()) {
954 return ¶m_ptr->getValue<T>(0);
972 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
974 if (param_ptr->isType<T>()) {
975 return ¶m_ptr->getValue<T>(0);
988 validateEntryExists(
"get", name_in, foundEntry);
997 validateEntryExists(
"get", name_in, foundEntry);
1008 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1021 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1033 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1045 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1046 return rcpFromPtr(params_.
getObjPtr(param_idx));
1062 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1063 template<
typename T>
1068 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1069 return params_.
getObjPtr(param_idx)->isType<T>();
1076 template<
typename T>
1079 return this->
isType(name_in, static_cast<T*>(0));
1088 return params_.
begin();
1094 return params_.
end();
1119 inline ParameterList::Iterator ParameterList::nonconstEnd()
1125 inline ParameterEntry& ParameterList::nonconstEntry(Iterator i)
1131 template<
typename T>
1133 void ParameterList::validateEntryType(
1134 const std::string &,
const std::string &name_in,
1135 const ParameterEntry &entry_in
1139 entry_in.getAny().type() !=
typeid(T), Exceptions::InvalidParameterType
1140 ,
"Error! An attempt was made to access parameter \""<<name_in<<
"\""
1141 " of type \""<<entry_in.getAny().typeName()<<
"\""
1142 "\nin the parameter (sub)list \""<<this->
name()<<
"\""
1158 template<
typename T>
1161 return l.template get<T>(name);
1170 template<
typename T>
1174 return getParameter<T>(l,name);
1184 template<
typename T>
1187 return l.template get<T>(name);
1198 template<
typename T>
1202 return l.template getPtr<T>(name);
1213 template<
typename T>
1217 return l.template getPtr<T>(name);
1227 template<
typename T>
1231 return l.
isType( name, (T*)NULL );
1241 template<
typename T>
1245 return l.
isType( name, (T*)NULL );
1260 template<
typename T>
1262 const std::string ¶mName
1268 paramList->
set(paramName,toString(array));
1336 template<
typename T>
1339 ,
const std::string ¶mName
1340 ,
const int arrayDim = -1
1341 ,
const bool mustExist =
true
1344 std::string arrayStr;
1346 arrayStr = getParameter<std::string>(paramList,paramName);
1350 *arrayStrPtr = getParameterPtr<std::string>(paramList,paramName);
1352 arrayStr = *arrayStrPtr;
1360 a = fromStringToArray<T>(arrayStr);
1365 ,
"Error! The parameter \""<<paramName<<
"\"\n"
1366 "in the sublist \""<<paramList.
name()<<
"\"\n"
1367 "exists, but the std::string value:\n"
1371 "is not a valid array represntation!"
1375 ( ( a.
size()>0 && arrayDim>=0 ) && static_cast<int>(a.
size())!=arrayDim )
1377 ,
"Error! The parameter \""<<paramName<<
"\"\n"
1378 "in the sublist \""<<paramList.
name()<<
"\"\n"
1379 "exists and is a valid array, but the dimension of\n"
1380 "the read in array a.size() = " << a.
size() <<
"\n"
1381 "was not equal to the expected size arrayDim = " << arrayDim <<
"!"
1393 bool mustAlreadyExist =
false,
const std::string& docString =
""
1396 return rcpWithEmbeddedObjPostDestroy(
1397 ¶mList->
sublist(name, mustAlreadyExist, docString), paramList, false );
1409 return rcpWithEmbeddedObjPostDestroy(
1410 ¶mList->
sublist(name), paramList, false );
EValidateDefaults
Validation defaults enum.
static std::string name()
EValidateUsed
Validation used enum.
Ptr< ObjType > getNonconstObjPtr(const Ordinal &idx)
Get a nonconst semi-persisting association with the stored object indexed by ordinal.
Reference-counted pointer class and non-member templated function implementations.
#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.
C++ Standard Library compatable filtered iterator.
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,...
ParameterList & setName(const std::string &name)
Set the name of *this list.
ParameterEntry * getEntryPtr(const std::string &name)
Retrieves the pointer for an entry with the name name if it exists.
Object held as the "value" in the Teuchos::ParameterList std::map.
#define TEUCHOS_TEST_FOR_EXCEPTION_PURE_MSG(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
std::ostream & operator<<(std::ostream &os, const ParameterList &l)
Output stream operator for handling the printing of the parameter list.
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 ParameterEntryValidator > validator() const
Return the (optional) validator object.
ConstIterator end() const
ConstIterator end() const
An iterator pointing beyond the last entry.
RCP< ParameterList > createParameterList(const std::string &name)
Nonmember constructor.
Default traits class that just returns typeid(T).name().
T & get(const std::string &name, T def_value)
Return the parameter's value, or the default value if it is not there.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
RCP< ParameterList > createParameterList()
Nonmember constructor.
RCP< ParameterEntry > getEntryRCP(const std::string &name)
Retrieves the RCP for an entry with the name name if it exists.
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...
Templated array class derived from the STL std::vector.
Ordinal getObjOrdinalIndex(const std::string &key) const
Get the ordinal index given the string key.
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....
Smart reference counting pointer class for automatic garbage collection.
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....
Simple wrapper class for raw pointers to single objects where no persisting relationship exists.
T * getParameterPtr(ParameterList &l, const std::string &name)
A templated helper function for getting a pointer to a parameter from a non-const list,...
Replacement for std::vector that is compatible with the Teuchos Memory Management classes.
T & get(ParameterList &l, const std::string &name)
A shorter name for getParameter().
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 isType(const std::string &name) const
Whether the given parameter exists in this list and has 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...
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 setStringParameterFromArray(const std::string ¶mName, const Array< T > &array, ParameterList *paramList)
Set a std::string parameter representation of an array.
ParameterList & setEntry(const std::string &name, const ParameterEntry &entry)
Set a parameter directly as a ParameterEntry.
void print() const
Print function to use in debugging in a debugger.
bool operator!=(const ParameterList &list1, const ParameterList &list2)
Returns true if two parameter lists are not the same.
Utility class for setting and passing in print options.
RCP< ParameterList > parameterList(const ParameterList &source)
Nonmember constructor.
params_t::ConstIterator ConstIterator
Parameter container const iterator typedef.
RCP< ParameterList > parameterList()
Nonmember constructor.
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,...
ParameterEntry & getEntry(const std::string &name)
Retrieves an entry with the name name.
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.
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 ...
Provides std::map class for deficient platforms.
Base types for StringIndexedOrderedValueObjectContainer.
RCP< ParameterList > parameterList(const std::string &name)
Nonmember constructor.
const std::string & name() const
The name of this ParameterList.
Ordinal setObj(const std::string &key, const ObjType &obj)
Set (or reset) object by value and return its ordinal index.
bool nonnull(const std::shared_ptr< T > &p)
Returns true if p.get()!=NULL.
A list of parameters of arbitrary type.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...
ConstIterator begin() const
This object is held as the "value" in the Teuchos::ParameterList std::map.
const ParameterEntry & entry(ConstIterator i) const
Access to ParameterEntry (i.e., returns i->second)
Ptr< const ObjType > getObjPtr(const Ordinal &idx) const
Get a const semi-persisting association with the stored object indexed by ordinal.
ConstIterator begin() const
An iterator pointing to the first entry.