14#include "Teuchos_FancyOStream.hpp"
16#include "Teuchos_VerboseObject.hpp"
24 return ( entry.
isList() ? std::string(
"...") : toString(entry.getAny()) );
28struct ListPlusValidList {
35 :list(_list),validList(_validList)
58 params_ = source.params_;
59 disableRecursiveValidation_ = source.disableRecursiveValidation_;
60 disableRecursiveModification_= source.disableRecursiveModification_;
61 disableRecursiveReconciliation_ = source.disableRecursiveReconciliation_;
62 modifier_ = source.modifier_;
81 params_ = source.params_;
82 disableRecursiveValidation_ = source.disableRecursiveValidation_;
83 disableRecursiveModification_= source.disableRecursiveModification_;
84 disableRecursiveReconciliation_ = source.disableRecursiveReconciliation_;
85 modifier_ = source.modifier_;
90void ParameterList::setModifier(
111 this->updateSubListNames();
139 this->updateSubListNames();
146 disableRecursiveValidation_ =
true;
153 disableRecursiveModification_ =
true;
160 disableRecursiveReconciliation_ =
true;
177 if (!(
entry(
i).isUsed())) {
178 os <<
"WARNING: Parameter \"" <<
name(
i) <<
"\" " <<
entry(
i)
179 <<
" is unused" << std::endl;
187 std::ostringstream
oss;
207 if (
param_idx != SIOVOCB::getInvalidOrdinal()) {
218 if (
param_idx != SIOVOCB::getInvalidOrdinal()) {
231 if (
param_idx != SIOVOCB::getInvalidOrdinal()) {
238 validateEntryExists(
"get",
name_in, 0);
246 const std::string& docString
255 if (
param_idx != SIOVOCB::getInvalidOrdinal()) {
282 const std::string& docString
288 ,
"The parameter "<<this->
name()<<
"->\""<<name_in<<
"\" already exists."
301 if (
param_idx == SIOVOCB::getInvalidOrdinal()) {
302 validateMissingSublistMustExist(this->
name(), name_in,
true);
327 out = getFancyOStream(
rcp(&os,
false));
328 OSTab tab(out,indent);
330 *out <<
"[empty list]" << std::endl;
339 validator =
entry_i.validator();
342 if(!showDefault &&
entry_i.isDefault())
345 const std::string &docString =
entry_i.docString();
347 *out <<
" : " <<
entry_i.getAny(
false).typeName();
348 *out <<
" = ";
entry_i.leftshift(os,showFlags); *out << std::endl;
351 validator->printDoc(docString,
OSTab(os).o());
353 else if (docString.length()) {
364 const std::string &docString =
entry_i.docString();
366 *out <<
name_i <<
" -> " << std::endl;
367 if( docString.length() && showDoc ) {
377std::ostream&
ParameterList::print(std::ostream& os,
int indent,
bool showTypes,
bool showFlags,
bool showDefault)
const
379 return this->
print(os,
PrintOptions().indent(indent).showTypes(showTypes).showFlags(showFlags).showDefault(showDefault));
391#ifdef TEUCHOS_PARAMETER_LIST_SHOW_TRACE
394 *out <<
"\n*** Entering ParameterList::validateParameters(...) for "
395 "this->name()=\""<<this->
name()<<
"\"...\n";
404 for (
itr = this->
begin(); itr != this->
end(); ++itr) {
407#ifdef TEUCHOS_PARAMETER_LIST_SHOW_TRACE
409 *out <<
"\nentryName=\""<<
entryName<<
"\"\n";
422 ,
"Error, the parameter {name=\""<<
entryName<<
"\","
423 "type=\""<<
theEntry.getAny(
false).typeName()<<
"\""
425 "\nin the parameter (sub)list \""<<this->
name()<<
"\""
426 "\nwas not found in the list of valid parameters!"
427 "\n\nThe valid parameters and types are:\n"
442 ,
"Error, the parameter {name=\""<<
entryName<<
"\","
443 "type=\""<<
theEntry.getAny(
false).typeName()<<
"\""
445 "\nin the parameter (sub)list \""<<this->
name()<<
"\""
446 "\nexists in the list of valid parameters but has the wrong type."
447 "\n\nThe correct type is \""
468 if (!
sl_itr->validList->disableRecursiveValidation_) {
469 sl_itr->list->validateParameters(
477#ifdef TEUCHOS_PARAMETER_LIST_SHOW_TRACE
478 *out <<
"\n*** Existing ParameterList::validateParameters(...) for "
479 "this->name()=\""<<this->
name()<<
"\"...\n";
502 ,
"Error, the parameter {name=\""<<
entry_name<<
"\","
503 "type=\""<<
cur_entry.getAny(
false).typeName()<<
"\""
505 "\nin the parameter (sub)list \""<<this->
name()<<
"\""
506 "\nwas not found in the list of parameters during modification."
507 "\n\nThe parameters and types are:\n"
524 tmp.push_back(*
this);
542 ,
"Error, the parameter {name=\"" <<
entry_name <<
"\","
543 "type=\"" <<
cur_entry.getAny(
false).typeName() <<
"\""
545 "\nin the parameter (sub)list \"" <<
cur_node.name() <<
"\""
546 "\nwas not found in the list of parameters during reconciliation."
547 "\n\nThe parameters and types are:\n"
548 <<
cur_node.currentParametersString()
564 std::deque<std::reference_wrapper<ParameterList>>::reverse_iterator
ref,
valid_ref;
581#ifdef TEUCHOS_PARAMETER_LIST_SHOW_TRACE
584 *out <<
"\n*** Entering ParameterList::validateParametersAndSetDefaults(...) "
585 "for this->name()=\""<<this->
name()<<
"\"...\n";
595 for (
itr = this->nonconstBegin();
itr != this->nonconstEnd(); ++
itr) {
598#ifdef TEUCHOS_PARAMETER_LIST_SHOW_TRACE
600 *out <<
"\nentryName=\""<<
entryName<<
"\"\n";
605 ,
"Error, the parameter {name=\""<<
entryName<<
"\","
606 "type=\""<<
theEntry.getAny(
false).typeName()<<
"\""
608 "\nin the parameter (sub)list \""<<this->
name()<<
"\""
609 "\nwas not found in the list of valid parameters!"
610 "\n\nThe valid parameters and types are:\n"
615 validator->validateAndModify(
entryName, this->
name(), &theEntry);
626 ,
"Error, the parameter {name=\""<<
entryName<<
"\","
627 "type=\""<<
theEntry.getAny(
false).typeName()<<
"\""
629 "\nin the parameter (sub)list \""<<this->
name()<<
"\""
630 "\nexists in the list of valid parameters but has the wrong type."
631 "\n\nThe correct type is \""
670#if defined(HAVE_TEUCHOS_MODIFY_DEFAULTS_DURING_VALIDATION)
691 if (!
sl_itr->validList->disableRecursiveValidation_) {
695#ifdef TEUCHOS_PARAMETER_LIST_SHOW_TRACE
696 *out <<
"\n*** Existing ParameterList::validateParametersAndSetDefaults(...) "
697 "for this->name()=\""<<this->
name()<<
"\"...\n";
705void ParameterList::updateSubListNames(
int depth)
709 for(
itr = this->nonconstBegin();
itr != this->nonconstEnd(); ++
itr ) {
722void ParameterList::validateEntryExists(
723 const std::string & ,
const std::string &name_in,
724 const ParameterEntry *entry_in
728 entry_in==NULL, Exceptions::InvalidParameterName
729 ,
"Error! The parameter \""<<name_in<<
"\" does not exist"\
730 "\nin the parameter (sub)list \""<<this->
name()<<
"\"."
731 "\n\nThe current parameters set in (sub)list \""<<this->
name()<<
"\" are:\n\n"
737void ParameterList::validateEntryIsList(
738 const std::string &name_in,
const ParameterEntry &entry_in
742 !entry_in.isList(), Exceptions::InvalidParameterType
743 ,
"Error, the parameter \"" << name_in <<
"\" is not a list, it is of type \""
744 <<entry_in.getAny(
false).typeName()<<
"\"!" );
748void ParameterList::validateMissingSublistMustExist(
const std::string &baselist_name,
749 const std::string &sublist_name,
const bool mustAlreadyExist)
const
752 mustAlreadyExist, Exceptions::InvalidParameterName
753 ,
"The sublist "<<baselist_name<<
"->\""<<sublist_name<<
"\" does not exist!"
761bool Teuchos::operator==(
const ParameterList& list1,
const ParameterList& list2 )
769 if (!Teuchos::haveSameModifiers(list1, list2)){
772 ParameterList::ConstIterator itr1, itr2;
774 itr1 = list1.begin(), itr2 = list2.begin();
775 itr1 != list1.end() && itr2 != list2.end();
779 const std::string &entryName1 = list1.name(itr1);
780 const std::string &entryName2 = list2.name(itr2);
781 const ParameterEntry &entry1 = list1.entry(itr1);
782 const ParameterEntry &entry2 = list2.entry(itr2);
783 if( entryName1 != entryName2 ) {
786 else if( entry1 != entry2 ) {
795 if ((itr1 != list1.end()) || (itr2 != list2.end())) {
802bool Teuchos::haveSameModifiers(
const ParameterList &list1,
const ParameterList &list2) {
804 const RCP<const ParameterListModifier> &modifier1 = list1.getModifier();
805 const RCP<const ParameterListModifier> &modifier2 = list2.getModifier();
807 const bool modifier1_is_null = is_null(modifier1);
808 const bool modifier2_is_null = is_null(modifier2);
809 if( modifier1_is_null || modifier2_is_null ){
810 if ( modifier1_is_null != modifier2_is_null ){
813 }
else if ( *modifier1 != *modifier2 ){
817 ParameterList::ConstIterator itr1, itr2;
819 itr1 = list1.begin(), itr2 = list2.begin();
820 itr1 != list1.end() && itr2 != list2.end();
825 const ParameterEntry &entry1 = itr1->second;
826 const ParameterEntry &entry2 = itr2->second;
827 if (entry1.isList() && entry2.isList()){
838bool Teuchos::haveSameValues(
const ParameterList& list1,
const ParameterList& list2,
bool verbose )
846 ParameterList::ConstIterator itr1, itr2;
848 itr1 = list1.begin(), itr2 = list2.begin();
849 itr1 != list1.end() && itr2 != list2.end();
853 const std::string &entryName1 = list1.name(itr1);
854 const std::string &entryName2 = list2.name(itr2);
855 const ParameterEntry &entry1 = list1.entry(itr1);
856 const ParameterEntry &entry2 = list2.entry(itr2);
857 if( entryName1 != entryName2 ) {
858 if (verbose) std::cerr <<
"entryName1 \"" << entryName1 <<
"\" != entryName2 \"" << entryName2 <<
"\"\n";
861 if( entry1.isList() && entry2.isList() ) {
864 getValue<ParameterList>(entry1),
865 getValue<ParameterList>(entry2),
873 if (verbose) std::cerr <<
"sublists \"" << entryName1 <<
"\" differ\n";
878 if( entry1.getAny() != entry2.getAny() ) {
879 if (verbose) std::cerr <<
"for key \"" << entryName1 <<
"\", value \"" << entry1.getAny() <<
"\" != \"" << entry2.getAny() <<
"\"\n";
885 if ((itr1 != list1.end()) || (itr2 != list2.end())) {
886 if (verbose) std::cerr <<
"lists are not the same size\n";
893bool Teuchos::haveSameValuesSorted(
const ParameterList& list1,
const ParameterList& list2,
bool verbose )
901 ParameterList::ConstIterator itr1, itr2;
902 Array<std::string> arr1, arr2;
903 for(itr1 = list1.begin(); itr1 != list1.end(); ++itr1){
904 arr1.push_back(list1.name(itr1));
906 for(itr2 = list2.begin(); itr2 != list2.end(); ++itr2){
907 arr2.push_back(list2.name(itr2));
910 if (arr1.size() != arr2.size()) {
911 if (verbose) std::cerr <<
"lists are not the same size\n";
914 std::sort(arr1.begin(), arr1.end());
915 std::sort(arr2.begin(), arr2.end());
916 Array<std::string>::iterator iarr1, iarr2;
918 iarr1 = arr1.begin(), iarr2 = arr2.begin();
919 iarr1 != arr1.end() && iarr2 != arr2.end();
923 const std::string &entryName1 = *iarr1;
924 const std::string &entryName2 = *iarr2;
925 const ParameterEntry &entry1 = list1.getEntry(entryName1);
926 const ParameterEntry &entry2 = list2.getEntry(entryName2);
927 if( entryName1 != entryName2 ) {
928 if (verbose) std::cerr <<
"entryName1 \"" << entryName1 <<
"\" != entryName2 \"" << entryName2 <<
"\"\n";
931 if( entry1.isList() && entry2.isList() ) {
933 !haveSameValuesSorted(
934 getValue<ParameterList>(entry1),
935 getValue<ParameterList>(entry2),
943 if (verbose) std::cerr <<
"sublists \"" << entryName1 <<
"\" differ\n";
948 if( entry1.getAny() != entry2.getAny() ) {
949 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 & setEntry(const std::string &name, U &&entry)
Set a parameter directly as a ParameterEntry.
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.
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 setObj(const std::string &key, U &&obj)
Set (or reset) object by value and return its ordinal index.
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.
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.