60struct ListPlusValidList {
67 :list(_list),validList(_validList)
83 :name_(name_in), modifier_(modifier_in)
132 const std::string &name_i = this->
name(i);
136 getValue<ParameterList>(entry_i) );
152 const std::string &name_i = this->
name(i);
156 getValue<ParameterList>(entry_i) );
205 if (!(
entry(i).isUsed())) {
206 os <<
"WARNING: Parameter \"" <<
name(i) <<
"\" " <<
entry(i)
207 <<
" is unused" << std::endl;
215 std::ostringstream oss;
219 for( itr = this->
begin(), i = 0; itr != this->
end(); ++itr, ++i ) {
220 const std::string &entryName = this->
name(itr);
224 <<
" = "<<filterValueToString(theEntry) <<
"\n";
235 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
246 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
254 std::string
const& name_in,
bool throwIfNotExists
259 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
265 if (throwIfNotExists) {
273 const std::string& name_in,
bool mustAlreadyExist,
274 const std::string& docString
283 if (param_idx != SIOVOCB::getInvalidOrdinal()) {
291 const Ordinal new_param_idx =
304 return any_cast<ParameterList>(sublist_entry_ptr->getAny(
false));
310 const std::string& docString
316 ,
"The parameter "<<this->
name()<<
"->\""<<name_in<<
"\" already exists."
329 if (param_idx == SIOVOCB::getInvalidOrdinal()) {
336 return any_cast<ParameterList>(sublist_entry_ptr->getAny(
false));
348 const int indent = printOptions.
indent();
349 const bool showTypes = printOptions.
showTypes();
350 const bool showFlags = printOptions.
showFlags();
351 const bool showDoc = printOptions.
showDoc();
352 const bool showDefault = printOptions.
showDefault();
353 const std::string linePrefix(indent,
' ');
355 out = getFancyOStream(
rcp(&os,
false));
356 OSTab tab(out,indent);
358 *out <<
"[empty list]" << std::endl;
364 const std::string &name_i = this->
name(i);
373 const std::string &docString = entry_i.
docString();
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();
393 const std::string &name_i = this->
name(i);
394 *out << name_i <<
" -> " << std::endl;
395 if( docString.length() && showDoc ) {
398 getValue<ParameterList>(entry_i).print(
OSTab(out).o(), printOptions.
copy().
indent(0));
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));
418 typedef std::deque<ListPlusValidList> sublist_list_t;
419#ifdef TEUCHOS_PARAMETER_LIST_SHOW_TRACE
422 *out <<
"\n*** Entering ParameterList::validateParameters(...) for "
423 "this->name()=\""<<this->
name()<<
"\"...\n";
430 sublist_list_t sublist_list;
432 for (itr = this->
begin(); itr != this->
end(); ++itr) {
433 const std::string &entryName = this->
name(itr);
435#ifdef TEUCHOS_PARAMETER_LIST_SHOW_TRACE
437 *out <<
"\nentryName=\""<<entryName<<
"\"\n";
450 ,
"Error, the parameter {name=\""<<entryName<<
"\","
452 ",value=\""<<filterValueToString(theEntry)<<
"\"}"
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"
460 validator->validate(theEntry, entryName, this->
name());
463 const bool validType =
470 ,
"Error, the parameter {name=\""<<entryName<<
"\","
472 ",value=\""<<filterValueToString(theEntry)<<
"\"}"
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 \""
479 if( theEntry.
isList() && depth > 0 ) {
480 sublist_list.push_back(
482 &getValue<ParameterList>(theEntry),&getValue<ParameterList>(*validEntry)
491 sublist_list_t::const_iterator sl_itr = sublist_list.begin();
492 sl_itr != sublist_list.end();
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";
517 modifier->modify(*
this, valid_pl);
520 for (itr = valid_pl.
begin(); itr != valid_pl.
end(); ++itr){
521 const std::string &entry_name = itr->first;
523 if (cur_entry.
isList() && depth > 0){
529 ,
"Error, the parameter {name=\""<<entry_name<<
"\","
531 ",value=\""<<filterValueToString(cur_entry)<<
"\"}"
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"
546 const bool left_to_right)
550 std::deque<std::reference_wrapper<ParameterList>> refs, valid_refs, tmp, valid_tmp;
551 tmp.push_back(*
this);
552 valid_tmp.push_back(valid_pl);
553 while (!valid_tmp.empty()){
557 valid_tmp.pop_front();
558 refs.push_back(cur_node);
559 valid_refs.push_back(valid_cur_node);
561 for (
auto itr = valid_cur_node.
begin(); itr != valid_cur_node.
end(); ++itr){
562 const std::string &entry_name = itr->first;
563 if (valid_cur_node.
isSublist(entry_name)){
569 ,
"Error, the parameter {name=\"" << entry_name <<
"\","
571 ",value=\"" << filterValueToString(cur_entry) <<
"\"}"
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"
578 valid_tmp.push_back(valid_cur_node_sublist);
579 tmp.push_back(cur_node.
sublist(entry_name));
581 valid_tmp.push_front(valid_cur_node_sublist);
582 tmp.push_front(cur_node.
sublist(entry_name));
591 std::deque<std::reference_wrapper<ParameterList>>::reverse_iterator ref, valid_ref;
592 for(ref = refs.rbegin(), valid_ref = valid_refs.rbegin();
593 ref != refs.rend() && valid_ref != valid_refs.rend();
595 if (
nonnull(modifier = valid_ref->
get().getModifier())) {
596 modifier->reconcile(ref->get());
607 typedef std::deque<ListPlusValidList> sublist_list_t;
608#ifdef TEUCHOS_PARAMETER_LIST_SHOW_TRACE
611 *out <<
"\n*** Entering ParameterList::validateParametersAndSetDefaults(...) "
612 "for this->name()=\""<<this->
name()<<
"\"...\n";
619 sublist_list_t sublist_list;
623 const std::string &entryName = this->
name(itr);
625#ifdef TEUCHOS_PARAMETER_LIST_SHOW_TRACE
627 *out <<
"\nentryName=\""<<entryName<<
"\"\n";
632 ,
"Error, the parameter {name=\""<<entryName<<
"\","
634 ",value=\""<<filterValueToString(theEntry)<<
"\"}"
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);
646 const bool validType =
653 ,
"Error, the parameter {name=\""<<entryName<<
"\","
655 ",value=\""<<filterValueToString(theEntry)<<
"\"}"
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 \""
664 if( theEntry.
isList() && depth > 0 ) {
665 sublist_list.push_back(
667 &getValue<ParameterList>(theEntry),
668 &getValue<ParameterList>(*validEntry)
680 for (itr = validParamList.
begin(); itr != validParamList.
end(); ++itr) {
681 const std::string &validEntryName = validParamList.
name(itr);
696 this->
setEntry(validEntryName,newEntry);
705 sublist_list_t::iterator sl_itr = sublist_list.begin();
706 sl_itr != sublist_list.end();
710 if (!sl_itr->validList->disableRecursiveValidation_) {
711 sl_itr->list->validateParametersAndSetDefaults(*sl_itr->validList,depth-1);
714#ifdef TEUCHOS_PARAMETER_LIST_SHOW_TRACE
715 *out <<
"\n*** Existing ParameterList::validateParametersAndSetDefaults(...) "
716 "for this->name()=\""<<this->
name()<<
"\"...\n";
726 const std::string this_name = this->
name();
729 const std::string &entryName = this->
name(itr);
732 ParameterList &sublistEntry = getValue<ParameterList>(theEntry);
733 sublistEntry.
setName(this_name+std::string(
"->")+entryName);
742 const std::string & ,
const std::string &name_in,
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"
762 ,
"Error, the parameter \"" << name_in <<
"\" is not a list, it is of type \""
768 const std::string &sublist_name,
const bool mustAlreadyExist)
const
772 ,
"The sublist "<<baselist_name<<
"->\""<<sublist_name<<
"\" does not exist!"
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 ) {
838 if ( !haveSameModifiers( Teuchos::getValue<ParameterList>(entry1),
839 Teuchos::getValue<ParameterList>(entry2) ) ){
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.
C++ Standard Library compatable filtered iterator.
This object is held as the "value" in the Teuchos::ParameterList std::map.
void setValidator(RCP< const ParameterEntryValidator > const &validator)
Set the validator.
bool isUsed() const
Return whether or not the value has been used; i.e., whether or not the value has been retrieved via ...
any & getAny(bool activeQry=true)
Direct access to the Teuchos::any data value underlying this object. The bool argument activeQry (def...
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 docString() const
Return the (optional) documentation std::string.
bool isList() const
Return whether or not the value itself is a list.
void setAnyValue(const any &value, bool isDefault=false)
Set the value as an any object.
bool isDefault() const
Indicate whether this entry takes on the default value.
Utility class for setting and passing in print options.
PrintOptions & showFlags(bool _showFlags)
PrintOptions & indent(int _indent)
PrintOptions copy() const
PrintOptions & showTypes(bool _showTypes)
PrintOptions & showDefault(bool _showDefault)
PrintOptions & showDoc(bool _showDoc)
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)
RCP< const ParameterListModifier > modifier_
ConstIterator end() const
An iterator pointing beyond the last entry.
virtual ~ParameterList()
Destructor.
Ordinal numParams() const
Get the number of stored parameters.
ParameterEntry & nonconstEntry(Iterator i)
Access to ParameterEntry (i.e., returns i->second)
void validateEntryIsList(const std::string &name, const ParameterEntry &entry) const
Validate a sublist param is indeed a sublist.
ParameterList & setParametersNotAlreadySet(const ParameterList &source)
params_t params_
Parameter list.
RCP< const ParameterListModifier > getModifier() const
Return the optional modifier object.
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,...
bool disableRecursiveModification_
Modify into list or not.
Iterator nonconstEnd()
An iterator pointing beyond the last entry.
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.
params_t::Iterator Iterator
Parameter container iterator typedef.
ParameterList & disableRecursiveValidation()
ParameterList & disableRecursiveReconciliation()
bool disableRecursiveValidation_
Validate into list or not.
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.
std::string name_
Name of the (sub)list.
ConstIterator begin() const
An iterator pointing to the first entry.
ParameterList & disableRecursiveModification()
void validateEntryExists(const std::string &funcName, const std::string &name, const ParameterEntry *entry) const
Validate that a parameter exists.
void validateMissingSublistMustExist(const std::string &baselist_name, const std::string &sublist_name, const bool mustAlreadyExist) const
Throw a sublist does not exist exception.
bool disableRecursiveReconciliation_
Reconcile into list or not.
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 & setName(const std::string &name)
Set the name of *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).
void updateSubListNames(int depth=0)
Update sublist names recursively.
Iterator nonconstBegin()
An iterator pointing to the first entry.
void setModifier(RCP< const ParameterListModifier > const &modifier)
EValidateDefaults
Validation defaults enum.
EValidateUsed
Validation used enum.
Simple wrapper class for raw pointers to single objects where no persisting relationship exists.
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.
const std::type_info & type() const
Return the type of value being stored.
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.
@ VALIDATE_DEFAULTS_ENABLED
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
basic_OSTab< char > OSTab
std::string toString(const HashSet< Key > &h)
bool operator==(BigUInt< n > const &a, BigUInt< n > const &b)