|
Teuchos Package Browser (Single Doxygen Collection)
Version of the Day
|
Go to the documentation of this file.
55 return ( entry.
isList() ? std::string(
"...") :
toString(entry.getAny()) );
59 struct ListPlusValidList {
66 :list(_list),validList(_validList)
81 :name_(
"ANONYMOUS"), disableRecursiveValidation_(false)
86 :name_(name_in), disableRecursiveValidation_(false)
122 const std::string &name_i = this->
name(i);
126 getValue<ParameterList>(entry_i) );
142 const std::string &name_i = this->
name(i);
146 getValue<ParameterList>(entry_i) );
172 if (!(
entry(i).isUsed())) {
173 os <<
"WARNING: Parameter \"" <<
name(i) <<
"\" " <<
entry(i)
174 <<
" is unused" << std::endl;
182 std::ostringstream oss;
186 for( itr = this->
begin(), i = 0; itr != this->
end(); ++itr, ++i ) {
187 const std::string &entryName = this->
name(itr);
191 <<
" = "<<filterValueToString(theEntry) <<
"\n";
202 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
213 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
221 std::string
const& name_in,
bool throwIfNotExists
226 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
232 if (throwIfNotExists) {
240 const std::string& name_in,
bool mustAlreadyExist,
241 const std::string& docString
250 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
258 const Ordinal new_param_idx =
271 return any_cast<ParameterList>(sublist_entry_ptr->getAny(
false));
280 if (param_idx == SIOVOCB::getInvalidOrdinal()) {
287 return any_cast<ParameterList>(sublist_entry_ptr->getAny(
false));
299 const int indent = printOptions.
indent();
300 const bool showTypes = printOptions.
showTypes();
301 const bool showFlags = printOptions.
showFlags();
302 const bool showDoc = printOptions.
showDoc();
303 const std::string linePrefix(indent,
' ');
305 out = getFancyOStream(
rcp(&os,
false));
306 OSTab tab(out,indent);
308 *out <<
"[empty list]" << std::endl;
314 const std::string &name_i = this->
name(i);
321 const std::string &docString = entry_i.
docString();
324 *out <<
" = "; entry_i.
leftshift(os,showFlags); *out << std::endl;
327 validator->printDoc(docString,
OSTab(os).o());
329 else if (docString.length()) {
340 const std::string &docString = entry_i.
docString();
341 const std::string &name_i = this->
name(i);
342 *out << name_i <<
" -> " << std::endl;
343 if( docString.length() && showDoc ) {
346 getValue<ParameterList>(entry_i).print(
OSTab(out).o(), printOptions.
copy().
indent(0));
355 return this->
print(os,
PrintOptions().indent(indent).showTypes(showTypes).showFlags(showFlags));
366 typedef std::deque<ListPlusValidList> sublist_list_t;
367 #ifdef TEUCHOS_PARAMETER_LIST_SHOW_TRACE
370 *out <<
"\n*** Entering ParameterList::validateParameters(...) for "
371 "this->name()=\""<<this->
name()<<
"\"...\n";
378 sublist_list_t sublist_list;
380 for (itr = this->
begin(); itr != this->
end(); ++itr) {
381 const std::string &entryName = this->
name(itr);
383 #ifdef TEUCHOS_PARAMETER_LIST_SHOW_TRACE
385 *out <<
"\nentryName=\""<<entryName<<
"\"\n";
398 ,
"Error, the parameter {name=\""<<entryName<<
"\","
400 ",value=\""<<filterValueToString(theEntry)<<
"\"}"
401 "\nin the parameter (sub)list \""<<this->
name()<<
"\""
402 "\nwas not found in the list of valid parameters!"
403 "\n\nThe valid parameters and types are:\n"
408 validator->validate(theEntry, entryName, this->
name());
411 const bool validType =
418 ,
"Error, the parameter {name=\""<<entryName<<
"\","
420 ",value=\""<<filterValueToString(theEntry)<<
"\"}"
421 "\nin the parameter (sub)list \""<<this->
name()<<
"\""
422 "\nexists in the list of valid parameters but has the wrong type."
423 "\n\nThe correct type is \""
427 if( theEntry.
isList() && depth > 0 ) {
428 sublist_list.push_back(
430 &getValue<ParameterList>(theEntry),&getValue<ParameterList>(*validEntry)
439 sublist_list_t::const_iterator sl_itr = sublist_list.begin();
440 sl_itr != sublist_list.end();
444 if (!sl_itr->validList->disableRecursiveValidation_) {
445 sl_itr->list->validateParameters(
453 #ifdef TEUCHOS_PARAMETER_LIST_SHOW_TRACE
454 *out <<
"\n*** Existing ParameterList::validateParameters(...) for "
455 "this->name()=\""<<this->
name()<<
"\"...\n";
465 typedef std::deque<ListPlusValidList> sublist_list_t;
466 #ifdef TEUCHOS_PARAMETER_LIST_SHOW_TRACE
469 *out <<
"\n*** Entering ParameterList::validateParametersAndSetDefaults(...) "
470 "for this->name()=\""<<this->
name()<<
"\"...\n";
477 sublist_list_t sublist_list;
481 const std::string &entryName = this->
name(itr);
483 #ifdef TEUCHOS_PARAMETER_LIST_SHOW_TRACE
485 *out <<
"\nentryName=\""<<entryName<<
"\"\n";
490 ,
"Error, the parameter {name=\""<<entryName<<
"\","
492 ",value=\""<<filterValueToString(theEntry)<<
"\"}"
493 "\nin the parameter (sub)list \""<<this->
name()<<
"\""
494 "\nwas not found in the list of valid parameters!"
495 "\n\nThe valid parameters and types are:\n"
500 validator->validateAndModify(entryName, this->
name(), &theEntry);
504 const bool validType =
511 ,
"Error, the parameter {name=\""<<entryName<<
"\","
513 ",value=\""<<filterValueToString(theEntry)<<
"\"}"
514 "\nin the parameter (sub)list \""<<this->
name()<<
"\""
515 "\nexists in the list of valid parameters but has the wrong type."
516 "\n\nThe correct type is \""
522 if( theEntry.
isList() && depth > 0 ) {
523 sublist_list.push_back(
525 &getValue<ParameterList>(theEntry),
526 &getValue<ParameterList>(*validEntry)
538 for (itr = validParamList.
begin(); itr != validParamList.
end(); ++itr) {
539 const std::string &validEntryName = validParamList.
name(itr);
554 this->
setEntry(validEntryName,newEntry);
563 sublist_list_t::iterator sl_itr = sublist_list.begin();
564 sl_itr != sublist_list.end();
568 if (!sl_itr->validList->disableRecursiveValidation_) {
569 sl_itr->list->validateParametersAndSetDefaults(*sl_itr->validList,depth-1);
572 #ifdef TEUCHOS_PARAMETER_LIST_SHOW_TRACE
573 *out <<
"\n*** Existing ParameterList::validateParametersAndSetDefaults(...) "
574 "for this->name()=\""<<this->
name()<<
"\"...\n";
584 const std::string this_name = this->
name();
587 const std::string &entryName = this->
name(itr);
590 ParameterList &sublistEntry = getValue<ParameterList>(theEntry);
591 sublistEntry.
setName(this_name+std::string(
"->")+entryName);
600 const std::string & ,
const std::string &name_in,
606 ,
"Error! The parameter \""<<name_in<<
"\" does not exist"\
607 "\nin the parameter (sub)list \""<<this->
name()<<
"\"."
608 "\n\nThe current parameters set in (sub)list \""<<this->
name()<<
"\" are:\n\n"
620 ,
"Error, the parameter \"" << name_in <<
"\" is not a list, it is of type \""
626 const std::string &sublist_name,
const bool mustAlreadyExist)
const
630 ,
"The sublist "<<baselist_name<<
"->\""<<sublist_name<<
"\" does not exist!"
647 ParameterList::ConstIterator itr1, itr2;
649 itr1 = list1.begin(), itr2 = list2.begin();
650 itr1 != list1.end() && itr2 != list2.end();
654 const std::string &entryName1 = list1.name(itr1);
655 const std::string &entryName2 = list2.name(itr2);
656 const ParameterEntry &entry1 = list1.entry(itr1);
657 const ParameterEntry &entry2 = list2.entry(itr2);
658 if( entryName1 != entryName2 ) {
661 else if( entry1 != entry2 ) {
670 if ((itr1 != list1.end()) || (itr2 != list2.end())) {
677 bool Teuchos::haveSameValues(
const ParameterList& list1,
const ParameterList& list2,
bool verbose )
685 ParameterList::ConstIterator itr1, itr2;
687 itr1 = list1.begin(), itr2 = list2.begin();
688 itr1 != list1.end() && itr2 != list2.end();
692 const std::string &entryName1 = list1.name(itr1);
693 const std::string &entryName2 = list2.name(itr2);
694 const ParameterEntry &entry1 = list1.entry(itr1);
695 const ParameterEntry &entry2 = list2.entry(itr2);
696 if( entryName1 != entryName2 ) {
697 if (verbose) std::cerr <<
"entryName1 \"" << entryName1 <<
"\" != entryName2 \"" << entryName2 <<
"\"\n";
700 if( entry1.isList() && entry2.isList() ) {
703 getValue<ParameterList>(entry1),
704 getValue<ParameterList>(entry2),
712 if (verbose) std::cerr <<
"sublists \"" << entryName1 <<
"\" differ\n";
717 if( entry1.getAny() != entry2.getAny() ) {
718 if (verbose) std::cerr <<
"for key \"" << entryName1 <<
"\", value \"" << entry1.getAny() <<
"\" != \"" << entry2.getAny() <<
"\"\n";
724 if ((itr1 != list1.end()) || (itr2 != list2.end())) {
725 if (verbose) std::cerr <<
"lists are not the same size\n";
bool isUsed() const
Return whether or not the value has been used; i.e., whether or not the value has been retrieved via ...
EValidateDefaults
Validation defaults enum.
EValidateUsed
Validation used enum.
Templated Parameter List class.
Ptr< ObjType > getNonconstObjPtr(const Ordinal &idx)
Get a nonconst semi-persisting association with the stored object indexed by ordinal.
Ordinal numParams() const
Get the number of stored parameters.
PrintOptions copy() const
static RCP< FancyOStream > getDefaultOStream()
Get the default output stream object.
C++ Standard Library compatable filtered iterator.
ParameterList & setName(const std::string &name)
Set the name of *this list.
A std::string utilities class for Teuchos.
ParameterEntry * getEntryPtr(const std::string &name)
Retrieves the pointer for an entry with the name name if it exists.
#define TEUCHOS_TEST_FOR_EXCEPTION_PURE_MSG(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
RCP< const ParameterEntryValidator > validator() const
Return the (optional) validator object.
void validateEntryExists(const std::string &funcName, const std::string &name, const ParameterEntry *entry) const
Validate that a parameter exists.
ConstIterator end() const
An iterator pointing beyond the last entry.
void validateEntryIsList(const std::string &name, const ParameterEntry &entry) const
Validate a sublist param is indeed a sublist.
bool isList() const
Return whether or not the value itself is a list.
ParameterList & operator=(const ParameterList &source)
Replace the current parameter list with source.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
void removeObj(const Ordinal &idx)
Remove an object given its ordinal index.
bool remove(std::string const &name, bool throwIfNotExists=true)
Remove a parameter (does not depend on the type of the parameter).
Ordinal getObjOrdinalIndex(const std::string &key) const
Get the ordinal index given the string key.
void validateMissingSublistMustExist(const std::string &baselist_name, const std::string &sublist_name, const bool mustAlreadyExist) const
Throw a sublist does not exist exception.
const std::type_info & type() const
Return the type of value being stored.
Smart reference counting pointer class for automatic garbage collection.
Simple wrapper class for raw pointers to single objects where no persisting relationship exists.
Iterator nonconstBegin()
An iterator pointing to the first entry.
ParameterEntry & nonconstEntry(Iterator i)
Access to ParameterEntry (i.e., returns i->second)
Ordinal numObjects() const
basic_OSTab< char > OSTab
ParameterList & setParametersNotAlreadySet(const ParameterList &source)
bool isSublist(const std::string &name) const
Whether the given sublist exists in this list.
bool isDefault() const
Indicate whether this entry takes on the default value.
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.
std::string toString(const any &rhs)
Converts the value in any to a std::string.
any & getAny(bool activeQry=true)
Direct access to the Teuchos::any data value underlying this object. The bool argument activeQry (def...
bool isParameter(const std::string &name) const
Whether the given parameter exists in this list.
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.
void setValidator(RCP< const ParameterEntryValidator > const &validator)
Set the validator.
static std::ostream & printLines(std::ostream &os, const std::string &linePrefix, const std::string &lines)
Print lines with prefix first.
void unused(std::ostream &os) const
Print out unused parameters in the ParameterList.
PrintOptions & indent(int _indent)
Utility class for setting and passing in print options.
std::string name_
Name of the (sub)list.
Iterator nonconstEnd()
An iterator pointing beyond the last entry.
virtual ~ParameterList()
Destructor.
PrintOptions & showFlags(bool _showFlags)
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,...
bool disableRecursiveValidation_
Validate into list or not.
ParameterList & setParameters(const ParameterList &source)
std::string typeName() const
Return the name of the type.
std::string currentParametersString() const
Create a single formated std::string of all of the zero-level parameters in this list.
void updateSubListNames(int depth=0)
Update sublist names recursively.
Tabbing class for helping to create formated, indented output for a basic_FancyOStream object.
Base types for StringIndexedOrderedValueObjectContainer.
const std::string & name() const
The name of this 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...
Ordinal setObj(const std::string &key, const ObjType &obj)
Set (or reset) object by value and return its ordinal index.
PrintOptions & showTypes(bool _showTypes)
bool nonnull(const std::shared_ptr< T > &p)
Returns true if p.get()!=NULL.
A list of parameters of arbitrary type.
PrintOptions & showDoc(bool _showDoc)
ParameterList & disableRecursiveValidation()
params_t params_
Parameter list.
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)
std::ostream & leftshift(std::ostream &os, bool printFlags=true) const
Output a non-list parameter to the given output stream.
void setAnyValue(const any &value, bool isDefault=false)
Set the value as an any object.
Ptr< const ObjType > getObjPtr(const Ordinal &idx) const
Get a const semi-persisting association with the stored object indexed by ordinal.
bool operator==(BigUInt< n > const &a, BigUInt< n > const &b)
ConstIterator begin() const
An iterator pointing to the first entry.
std::string docString() const
Return the (optional) documentation std::string.
ParameterList()
Constructor.
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.