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 ) {
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";
732 bool Teuchos::haveSameValuesSorted(
const ParameterList& list1,
const ParameterList& list2,
bool verbose )
740 ParameterList::ConstIterator itr1, itr2;
741 Array<std::string> arr1, arr2;
742 for(itr1 = list1.begin(); itr1 != list1.end(); ++itr1){
743 arr1.push_back(list1.name(itr1));
745 for(itr2 = list2.begin(); itr2 != list2.end(); ++itr2){
746 arr2.push_back(list2.name(itr2));
749 if (arr1.size() != arr2.size()) {
750 if (verbose) std::cerr <<
"lists are not the same size\n";
753 std::sort(arr1.begin(), arr1.end());
754 std::sort(arr2.begin(), arr2.end());
757 iarr1 = arr1.begin(), iarr2 = arr2.begin();
758 iarr1 != arr1.end() && iarr2 != arr2.end();
762 const std::string &entryName1 = *iarr1;
763 const std::string &entryName2 = *iarr2;
764 const ParameterEntry &entry1 = list1.getEntry(entryName1);
765 const ParameterEntry &entry2 = list2.getEntry(entryName2);
766 if( entryName1 != entryName2 ) {
767 if (verbose) std::cerr <<
"entryName1 \"" << entryName1 <<
"\" != entryName2 \"" << entryName2 <<
"\"\n";
770 if( entry1.isList() && entry2.isList() ) {
773 getValue<ParameterList>(entry1),
774 getValue<ParameterList>(entry2),
782 if (verbose) std::cerr <<
"sublists \"" << entryName1 <<
"\" differ\n";
787 if( entry1.getAny() != entry2.getAny() ) {
788 if (verbose) std::cerr <<
"for key \"" << entryName1 <<
"\", value \"" << entry1.getAny() <<
"\" != \"" << entry2.getAny() <<
"\"\n";
void print() const
Print function to use in debugging in a debugger.
void validateEntryIsList(const std::string &name, const ParameterEntry &entry) const
Validate a sublist param is indeed a sublist.
const std::string & name() const
The name of this ParameterList.
C++ Standard Library compatable filtered iterator.
Ordinal getObjOrdinalIndex(const std::string &key) const
Get the ordinal index given the string key.
ConstIterator end() const
An iterator pointing beyond the last entry.
PrintOptions & showTypes(bool _showTypes)
ParameterList & disableRecursiveValidation()
void setValidator(RCP< const ParameterEntryValidator > const &validator)
Set the validator.
RCP< const ParameterEntryValidator > validator() const
Return the (optional) validator object.
std::ostream & leftshift(std::ostream &os, bool printFlags=true) const
Output a non-list parameter to the given output stream.
std::string currentParametersString() const
Create a single formated std::string of all of the zero-level parameters in this list.
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.
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.
Iterator nonconstBegin()
An iterator pointing to the first entry.
void validateEntryExists(const std::string &funcName, const std::string &name, const ParameterEntry *entry) const
Validate that a parameter exists.
PrintOptions & showDoc(bool _showDoc)
void setAnyValue(const any &value, bool isDefault=false)
Set the value as an any object.
Ordinal numParams() const
Get the number of stored parameters.
static std::ostream & printLines(std::ostream &os, const std::string &linePrefix, const std::string &lines)
Print lines with prefix first.
bool isDefault() const
Indicate whether this entry takes on the default value.
Tabbing class for helping to create formated, indented output for a basic_FancyOStream object...
basic_OSTab< char > OSTab
ParameterEntry * getEntryPtr(const std::string &name)
Retrieves the pointer for an entry with the name name if it exists.
std::string toString(const any &rhs)
Converts the value in any to a std::string.
A std::string utilities class for Teuchos.
ParameterList & setEntry(const std::string &name, const ParameterEntry &entry)
Set a parameter directly as a ParameterEntry.
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.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
Templated Parameter List class.
bool isSublist(const std::string &name) const
Whether the given sublist exists in this list.
ParameterList & operator=(const ParameterList &source)
Replace the current parameter list with source.
static RCP< FancyOStream > getDefaultOStream()
Get the default output stream object.
std::string name_
Name of the (sub)list.
PrintOptions copy() const
ParameterEntry & nonconstEntry(Iterator i)
Access to ParameterEntry (i.e., returns i->second)
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...
Utility class for setting and passing in print options.
ConstIterator begin() const
An iterator pointing to the first entry.
bool isList() const
Return whether or not the value itself is a list.
Ptr< const ObjType > getObjPtr(const Ordinal &idx) const
Get a const semi-persisting association with the stored object indexed by ordinal.
void updateSubListNames(int depth=0)
Update sublist names recursively.
A list of parameters of arbitrary type.
void validateMissingSublistMustExist(const std::string &baselist_name, const std::string &sublist_name, const bool mustAlreadyExist) const
Throw a sublist does not exist exception.
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.
ParameterList & setParameters(const ParameterList &source)
params_t params_
Parameter list.
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...
Ordinal setObj(const std::string &key, const ObjType &obj)
Set (or reset) object by value and return its ordinal index.
ParameterList & setParametersNotAlreadySet(const ParameterList &source)
ParameterList()
Constructor.
EValidateDefaults
Validation defaults enum.
void unused(std::ostream &os) const
Print out unused parameters in the ParameterList.
std::string typeName() const
Return the name of the type.
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.
void removeObj(const Ordinal &idx)
Remove an object given its ordinal index.
const std::type_info & type() const
Return the type of value being stored.
virtual ~ParameterList()
Destructor.
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. ...
std::string docString() const
Return the (optional) documentation std::string.
bool operator==(BigUInt< n > const &a, BigUInt< n > const &b)
bool isUsed() const
Return whether or not the value has been used; i.e., whether or not the value has been retrieved via ...
Ordinal numObjects() const
std::vector< std::string >::iterator iterator
The type of a forward iterator.
Ptr< ObjType > getNonconstObjPtr(const Ordinal &idx)
Get a nonconst semi-persisting association with the stored object indexed by ordinal.
EValidateUsed
Validation used enum.
Base types for StringIndexedOrderedValueObjectContainer.
Simple wrapper class for raw pointers to single objects where no persisting relationship exists...
bool disableRecursiveValidation_
Validate into list or not.
PrintOptions & indent(int _indent)
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.