46#include "Teuchos_FancyOStream.hpp"
48#include "Teuchos_VerboseObject.hpp"
56 return ( entry.
isList() ? std::string(
"...") : toString(entry.getAny()) );
60struct ListPlusValidList {
67 :list(_list),validList(_validList)
90 params_ = source.params_;
91 disableRecursiveValidation_ = source.disableRecursiveValidation_;
92 disableRecursiveModification_= source.disableRecursiveModification_;
93 disableRecursiveReconciliation_ = source.disableRecursiveReconciliation_;
94 modifier_ = source.modifier_;
112 name_ = source.name_;
113 params_ = source.params_;
114 disableRecursiveValidation_ = source.disableRecursiveValidation_;
115 disableRecursiveModification_= source.disableRecursiveModification_;
116 disableRecursiveReconciliation_ = source.disableRecursiveReconciliation_;
117 modifier_ = source.modifier_;
122void ParameterList::setModifier(
142 this->updateSubListNames();
167 this->updateSubListNames();
174 disableRecursiveValidation_ =
true;
181 disableRecursiveModification_ =
true;
188 disableRecursiveReconciliation_ =
true;
205 if (!(
entry(
i).isUsed())) {
206 os <<
"WARNING: Parameter \"" <<
name(
i) <<
"\" " <<
entry(
i)
207 <<
" is unused" << std::endl;
215 std::ostringstream
oss;
235 if (
param_idx != SIOVOCB::getInvalidOrdinal()) {
246 if (
param_idx != SIOVOCB::getInvalidOrdinal()) {
259 if (
param_idx != SIOVOCB::getInvalidOrdinal()) {
266 validateEntryExists(
"get",
name_in, 0);
274 const std::string& docString
283 if (
param_idx != SIOVOCB::getInvalidOrdinal()) {
310 const std::string& docString
316 ,
"The parameter "<<this->
name()<<
"->\""<<name_in<<
"\" already exists."
329 if (
param_idx == SIOVOCB::getInvalidOrdinal()) {
330 validateMissingSublistMustExist(this->
name(), name_in,
true);
355 out = getFancyOStream(
rcp(&os,
false));
356 OSTab tab(out,indent);
358 *out <<
"[empty list]" << std::endl;
367 validator =
entry_i.validator();
370 if(!showDefault &&
entry_i.isDefault())
373 const std::string &docString =
entry_i.docString();
375 *out <<
" : " <<
entry_i.getAny(
false).typeName();
376 *out <<
" = ";
entry_i.leftshift(os,showFlags); *out << std::endl;
379 validator->printDoc(docString,
OSTab(os).o());
381 else if (docString.length()) {
392 const std::string &docString =
entry_i.docString();
394 *out <<
name_i <<
" -> " << std::endl;
395 if( docString.length() && showDoc ) {
405std::ostream&
ParameterList::print(std::ostream& os,
int indent,
bool showTypes,
bool showFlags,
bool showDefault)
const
407 return this->
print(os,
PrintOptions().indent(indent).showTypes(showTypes).showFlags(showFlags).showDefault(showDefault));
419#ifdef TEUCHOS_PARAMETER_LIST_SHOW_TRACE
422 *out <<
"\n*** Entering ParameterList::validateParameters(...) for "
423 "this->name()=\""<<this->
name()<<
"\"...\n";
432 for (
itr = this->
begin(); itr != this->
end(); ++itr) {
435#ifdef TEUCHOS_PARAMETER_LIST_SHOW_TRACE
437 *out <<
"\nentryName=\""<<
entryName<<
"\"\n";
450 ,
"Error, the parameter {name=\""<<
entryName<<
"\","
451 "type=\""<<
theEntry.getAny(
false).typeName()<<
"\""
453 "\nin the parameter (sub)list \""<<this->
name()<<
"\""
454 "\nwas not found in the list of valid parameters!"
455 "\n\nThe valid parameters and types are:\n"
470 ,
"Error, the parameter {name=\""<<
entryName<<
"\","
471 "type=\""<<
theEntry.getAny(
false).typeName()<<
"\""
473 "\nin the parameter (sub)list \""<<this->
name()<<
"\""
474 "\nexists in the list of valid parameters but has the wrong type."
475 "\n\nThe correct type is \""
496 if (!
sl_itr->validList->disableRecursiveValidation_) {
497 sl_itr->list->validateParameters(
505#ifdef TEUCHOS_PARAMETER_LIST_SHOW_TRACE
506 *out <<
"\n*** Existing ParameterList::validateParameters(...) for "
507 "this->name()=\""<<this->
name()<<
"\"...\n";
529 ,
"Error, the parameter {name=\""<<
entry_name<<
"\","
530 "type=\""<<
cur_entry.getAny(
false).typeName()<<
"\""
532 "\nin the parameter (sub)list \""<<this->
name()<<
"\""
533 "\nwas not found in the list of parameters during modification."
534 "\n\nThe parameters and types are:\n"
551 tmp.push_back(*
this);
569 ,
"Error, the parameter {name=\"" <<
entry_name <<
"\","
570 "type=\"" <<
cur_entry.getAny(
false).typeName() <<
"\""
572 "\nin the parameter (sub)list \"" <<
cur_node.name() <<
"\""
573 "\nwas not found in the list of parameters during reconciliation."
574 "\n\nThe parameters and types are:\n"
575 <<
cur_node.currentParametersString()
591 std::deque<std::reference_wrapper<ParameterList>>::reverse_iterator
ref,
valid_ref;
608#ifdef TEUCHOS_PARAMETER_LIST_SHOW_TRACE
611 *out <<
"\n*** Entering ParameterList::validateParametersAndSetDefaults(...) "
612 "for this->name()=\""<<this->
name()<<
"\"...\n";
622 for (
itr = this->nonconstBegin();
itr != this->nonconstEnd(); ++
itr) {
625#ifdef TEUCHOS_PARAMETER_LIST_SHOW_TRACE
627 *out <<
"\nentryName=\""<<
entryName<<
"\"\n";
632 ,
"Error, the parameter {name=\""<<
entryName<<
"\","
633 "type=\""<<
theEntry.getAny(
false).typeName()<<
"\""
635 "\nin the parameter (sub)list \""<<this->
name()<<
"\""
636 "\nwas not found in the list of valid parameters!"
637 "\n\nThe valid parameters and types are:\n"
642 validator->validateAndModify(
entryName, this->
name(), &theEntry);
653 ,
"Error, the parameter {name=\""<<
entryName<<
"\","
654 "type=\""<<
theEntry.getAny(
false).typeName()<<
"\""
656 "\nin the parameter (sub)list \""<<this->
name()<<
"\""
657 "\nexists in the list of valid parameters but has the wrong type."
658 "\n\nThe correct type is \""
710 if (!
sl_itr->validList->disableRecursiveValidation_) {
714#ifdef TEUCHOS_PARAMETER_LIST_SHOW_TRACE
715 *out <<
"\n*** Existing ParameterList::validateParametersAndSetDefaults(...) "
716 "for this->name()=\""<<this->
name()<<
"\"...\n";
724void ParameterList::updateSubListNames(
int depth)
728 for(
itr = this->nonconstBegin();
itr != this->nonconstEnd(); ++
itr ) {
741void ParameterList::validateEntryExists(
742 const std::string & ,
const std::string &name_in,
743 const ParameterEntry *entry_in
747 entry_in==NULL, Exceptions::InvalidParameterName
748 ,
"Error! The parameter \""<<name_in<<
"\" does not exist"\
749 "\nin the parameter (sub)list \""<<this->
name()<<
"\"."
750 "\n\nThe current parameters set in (sub)list \""<<this->
name()<<
"\" are:\n\n"
756void ParameterList::validateEntryIsList(
757 const std::string &name_in,
const ParameterEntry &entry_in
761 !entry_in.isList(), Exceptions::InvalidParameterType
762 ,
"Error, the parameter \"" << name_in <<
"\" is not a list, it is of type \""
763 <<entry_in.getAny(
false).typeName()<<
"\"!" );
767void ParameterList::validateMissingSublistMustExist(
const std::string &baselist_name,
768 const std::string &sublist_name,
const bool mustAlreadyExist)
const
771 mustAlreadyExist, Exceptions::InvalidParameterName
772 ,
"The sublist "<<baselist_name<<
"->\""<<sublist_name<<
"\" does not exist!"
780bool Teuchos::operator==(
const ParameterList& list1,
const ParameterList& list2 )
788 if (!Teuchos::haveSameModifiers(list1, list2)){
791 ParameterList::ConstIterator itr1, itr2;
793 itr1 = list1.begin(), itr2 = list2.begin();
794 itr1 != list1.end() && itr2 != list2.end();
798 const std::string &entryName1 = list1.name(itr1);
799 const std::string &entryName2 = list2.name(itr2);
800 const ParameterEntry &entry1 = list1.entry(itr1);
801 const ParameterEntry &entry2 = list2.entry(itr2);
802 if( entryName1 != entryName2 ) {
805 else if( entry1 != entry2 ) {
814 if ((itr1 != list1.end()) || (itr2 != list2.end())) {
821bool Teuchos::haveSameModifiers(
const ParameterList &list1,
const ParameterList &list2) {
823 ParameterList::ConstIterator itr1, itr2;
825 itr1 = list1.begin(), itr2 = list2.begin();
826 itr1 != list1.end() && itr2 != list2.end();
832 if( modifier1 != modifier2 ) {
848bool Teuchos::haveSameValues(
const ParameterList& list1,
const ParameterList& list2,
bool verbose )
856 ParameterList::ConstIterator itr1, itr2;
858 itr1 = list1.begin(), itr2 = list2.begin();
859 itr1 != list1.end() && itr2 != list2.end();
863 const std::string &entryName1 = list1.name(itr1);
864 const std::string &entryName2 = list2.name(itr2);
865 const ParameterEntry &entry1 = list1.entry(itr1);
866 const ParameterEntry &entry2 = list2.entry(itr2);
867 if( entryName1 != entryName2 ) {
868 if (verbose) std::cerr <<
"entryName1 \"" << entryName1 <<
"\" != entryName2 \"" << entryName2 <<
"\"\n";
871 if( entry1.isList() && entry2.isList() ) {
874 getValue<ParameterList>(entry1),
875 getValue<ParameterList>(entry2),
883 if (verbose) std::cerr <<
"sublists \"" << entryName1 <<
"\" differ\n";
888 if( entry1.getAny() != entry2.getAny() ) {
889 if (verbose) std::cerr <<
"for key \"" << entryName1 <<
"\", value \"" << entry1.
getAny() <<
"\" != \"" << entry2.getAny() <<
"\"\n";
895 if ((itr1 != list1.end()) || (itr2 != list2.end())) {
896 if (verbose) std::cerr <<
"lists are not the same size\n";
903bool Teuchos::haveSameValuesSorted(
const ParameterList& list1,
const ParameterList& list2,
bool verbose )
911 ParameterList::ConstIterator itr1, itr2;
912 Array<std::string> arr1, arr2;
913 for(itr1 = list1.begin(); itr1 != list1.end(); ++itr1){
914 arr1.push_back(list1.name(itr1));
916 for(itr2 = list2.begin(); itr2 != list2.end(); ++itr2){
917 arr2.push_back(list2.name(itr2));
920 if (arr1.size() != arr2.size()) {
921 if (verbose) std::cerr <<
"lists are not the same size\n";
924 std::sort(arr1.begin(), arr1.end());
925 std::sort(arr2.begin(), arr2.end());
926 Array<std::string>::iterator iarr1, iarr2;
928 iarr1 = arr1.begin(), iarr2 = arr2.begin();
929 iarr1 != arr1.end() && iarr2 != arr2.end();
933 const std::string &entryName1 = *iarr1;
934 const std::string &entryName2 = *iarr2;
935 const ParameterEntry &entry1 = list1.getEntry(entryName1);
936 const ParameterEntry &entry2 = list2.getEntry(entryName2);
937 if( entryName1 != entryName2 ) {
938 if (verbose) std::cerr <<
"entryName1 \"" << entryName1 <<
"\" != entryName2 \"" << entryName2 <<
"\"\n";
941 if( entry1.isList() && entry2.isList() ) {
943 !haveSameValuesSorted(
944 getValue<ParameterList>(entry1),
945 getValue<ParameterList>(entry2),
953 if (verbose) std::cerr <<
"sublists \"" << entryName1 <<
"\" differ\n";
958 if( entry1.getAny() != entry2.getAny() ) {
959 if (verbose) std::cerr <<
"for key \"" << entryName1 <<
"\", value \"" << entry1.getAny() <<
"\" != \"" << entry2.getAny() <<
"\"\n";
Templated Parameter List class.
A std::string utilities class for Teuchos.
This object is held as the "value" in the Teuchos::ParameterList std::map.
any & getAny(bool activeQry=true)
Direct access to the Teuchos::any data value underlying this object. The bool argument activeQry (def...
bool isList() const
Return whether or not the value itself is a list.
Utility class for setting and passing in print options.
A list of parameters of arbitrary type.
void reconcileParameterList(ParameterList &validParamList, const bool left_to_right=true)
Reconcile a parameter list after validation.
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.
virtual ~ParameterList()
Destructor.
Ordinal numParams() const
Get the number of stored parameters.
ParameterList & setParametersNotAlreadySet(const ParameterList &source)
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...
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,...
void print() const
Print function to use in debugging in a debugger.
const std::string & name() const
The name of this ParameterList.
ParameterList()=default
Constructor.
void modifyParameterList(ParameterList &validParamList, int const depth=1000)
Modify the valid parameter list prior to validation.
bool isSublist(const std::string &name) const
Whether the given sublist exists in this list.
ParameterList & disableRecursiveValidation()
ParameterList & disableRecursiveReconciliation()
ParameterList & operator=(const ParameterList &source)
Replace the current parameter list with source.
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.
ConstIterator begin() const
An iterator pointing to the first entry.
ParameterList & disableRecursiveModification()
std::string currentParametersString() const
Create a single formated std::string of all of the zero-level parameters in this list.
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.
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.
Smart reference counting pointer class for automatic garbage collection.
T * get() const
Get the raw C++ pointer to the underlying object.
static std::ostream & printLines(std::ostream &os, const std::string &linePrefix, const std::string &lines)
Print lines with prefix first.
Base types for StringIndexedOrderedValueObjectContainer.
Ordinal getObjOrdinalIndex(const std::string &key) const
Get the ordinal index given the string key.
Ordinal numObjects() const
void removeObj(const Ordinal &idx)
Remove an object given its ordinal index.
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 RCP< FancyOStream > getDefaultOStream()
Get the default output stream object.
std::string typeName() const
Return the name of the type.
Tabbing class for helping to create formated, indented output for a basic_FancyOStream object.
#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_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.
basic_OSTab< char > OSTab
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.