56 return ( entry.
isList() ? std::string(
"...") :
toString(entry.getAny()) );
60 struct 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 std::string linePrefix(indent,
' ');
354 out = getFancyOStream(
rcp(&os,
false));
355 OSTab tab(out,indent);
357 *out <<
"[empty list]" << std::endl;
363 const std::string &name_i = this->
name(i);
370 const std::string &docString = entry_i.
docString();
373 *out <<
" = "; entry_i.
leftshift(os,showFlags); *out << std::endl;
376 validator->printDoc(docString,
OSTab(os).o());
378 else if (docString.length()) {
389 const std::string &docString = entry_i.
docString();
390 const std::string &name_i = this->
name(i);
391 *out << name_i <<
" -> " << std::endl;
392 if( docString.length() && showDoc ) {
404 return this->
print(os,
PrintOptions().indent(indent).showTypes(showTypes).showFlags(showFlags));
415 typedef std::deque<ListPlusValidList> sublist_list_t;
416 #ifdef TEUCHOS_PARAMETER_LIST_SHOW_TRACE
419 *out <<
"\n*** Entering ParameterList::validateParameters(...) for "
420 "this->name()=\""<<this->
name()<<
"\"...\n";
427 sublist_list_t sublist_list;
429 for (itr = this->
begin(); itr != this->
end(); ++itr) {
430 const std::string &entryName = this->
name(itr);
432 #ifdef TEUCHOS_PARAMETER_LIST_SHOW_TRACE
434 *out <<
"\nentryName=\""<<entryName<<
"\"\n";
447 ,
"Error, the parameter {name=\""<<entryName<<
"\","
449 ",value=\""<<filterValueToString(theEntry)<<
"\"}"
450 "\nin the parameter (sub)list \""<<this->
name()<<
"\""
451 "\nwas not found in the list of valid parameters!"
452 "\n\nThe valid parameters and types are:\n"
457 validator->validate(theEntry, entryName, this->
name());
460 const bool validType =
467 ,
"Error, the parameter {name=\""<<entryName<<
"\","
469 ",value=\""<<filterValueToString(theEntry)<<
"\"}"
470 "\nin the parameter (sub)list \""<<this->
name()<<
"\""
471 "\nexists in the list of valid parameters but has the wrong type."
472 "\n\nThe correct type is \""
476 if( theEntry.
isList() && depth > 0 ) {
477 sublist_list.push_back(
479 &getValue<ParameterList>(theEntry),&getValue<ParameterList>(*validEntry)
488 sublist_list_t::const_iterator sl_itr = sublist_list.begin();
489 sl_itr != sublist_list.end();
493 if (!sl_itr->validList->disableRecursiveValidation_) {
494 sl_itr->list->validateParameters(
502 #ifdef TEUCHOS_PARAMETER_LIST_SHOW_TRACE
503 *out <<
"\n*** Existing ParameterList::validateParameters(...) for "
504 "this->name()=\""<<this->
name()<<
"\"...\n";
514 modifier->modify(*
this, valid_pl);
517 for (itr = valid_pl.
begin(); itr != valid_pl.
end(); ++itr){
518 const std::string &entry_name = itr->first;
520 if (cur_entry.
isList() && depth > 0){
526 ,
"Error, the parameter {name=\""<<entry_name<<
"\","
528 ",value=\""<<filterValueToString(cur_entry)<<
"\"}"
529 "\nin the parameter (sub)list \""<<this->
name()<<
"\""
530 "\nwas not found in the list of parameters during modification."
531 "\n\nThe parameters and types are:\n"
535 pl_sublist.modifyParameterList(valid_pl_sublist, depth-1);
543 const bool left_to_right)
547 std::deque<std::reference_wrapper<ParameterList>> refs, valid_refs, tmp, valid_tmp;
548 tmp.push_back(*
this);
549 valid_tmp.push_back(valid_pl);
550 while (!valid_tmp.empty()){
554 valid_tmp.pop_front();
555 refs.push_back(cur_node);
556 valid_refs.push_back(valid_cur_node);
558 for (
auto itr = valid_cur_node.
begin(); itr != valid_cur_node.
end(); ++itr){
559 const std::string &entry_name = itr->first;
560 if (valid_cur_node.
isSublist(entry_name)){
566 ,
"Error, the parameter {name=\"" << entry_name <<
"\","
568 ",value=\"" << filterValueToString(cur_entry) <<
"\"}"
569 "\nin the parameter (sub)list \"" <<cur_node.
name() <<
"\""
570 "\nwas not found in the list of parameters during reconciliation."
571 "\n\nThe parameters and types are:\n"
575 valid_tmp.push_back(valid_cur_node_sublist);
576 tmp.push_back(cur_node.
sublist(entry_name));
578 valid_tmp.push_front(valid_cur_node_sublist);
579 tmp.push_front(cur_node.
sublist(entry_name));
588 std::deque<std::reference_wrapper<ParameterList>>::reverse_iterator ref, valid_ref;
589 for(ref = refs.rbegin(), valid_ref = valid_refs.rbegin();
590 ref != refs.rend() && valid_ref != valid_refs.rend();
592 if (
nonnull(modifier = valid_ref->
get().getModifier())) {
593 modifier->reconcile(ref->get());
604 typedef std::deque<ListPlusValidList> sublist_list_t;
605 #ifdef TEUCHOS_PARAMETER_LIST_SHOW_TRACE
608 *out <<
"\n*** Entering ParameterList::validateParametersAndSetDefaults(...) "
609 "for this->name()=\""<<this->
name()<<
"\"...\n";
616 sublist_list_t sublist_list;
620 const std::string &entryName = this->
name(itr);
622 #ifdef TEUCHOS_PARAMETER_LIST_SHOW_TRACE
624 *out <<
"\nentryName=\""<<entryName<<
"\"\n";
629 ,
"Error, the parameter {name=\""<<entryName<<
"\","
631 ",value=\""<<filterValueToString(theEntry)<<
"\"}"
632 "\nin the parameter (sub)list \""<<this->
name()<<
"\""
633 "\nwas not found in the list of valid parameters!"
634 "\n\nThe valid parameters and types are:\n"
639 validator->validateAndModify(entryName, this->
name(), &theEntry);
643 const bool validType =
650 ,
"Error, the parameter {name=\""<<entryName<<
"\","
652 ",value=\""<<filterValueToString(theEntry)<<
"\"}"
653 "\nin the parameter (sub)list \""<<this->
name()<<
"\""
654 "\nexists in the list of valid parameters but has the wrong type."
655 "\n\nThe correct type is \""
661 if( theEntry.
isList() && depth > 0 ) {
662 sublist_list.push_back(
664 &getValue<ParameterList>(theEntry),
665 &getValue<ParameterList>(*validEntry)
677 for (itr = validParamList.
begin(); itr != validParamList.
end(); ++itr) {
678 const std::string &validEntryName = validParamList.
name(itr);
693 this->
setEntry(validEntryName,newEntry);
702 sublist_list_t::iterator sl_itr = sublist_list.begin();
703 sl_itr != sublist_list.end();
707 if (!sl_itr->validList->disableRecursiveValidation_) {
708 sl_itr->list->validateParametersAndSetDefaults(*sl_itr->validList,depth-1);
711 #ifdef TEUCHOS_PARAMETER_LIST_SHOW_TRACE
712 *out <<
"\n*** Existing ParameterList::validateParametersAndSetDefaults(...) "
713 "for this->name()=\""<<this->
name()<<
"\"...\n";
723 const std::string this_name = this->
name();
726 const std::string &entryName = this->
name(itr);
729 ParameterList &sublistEntry = getValue<ParameterList>(theEntry);
730 sublistEntry.
setName(this_name+std::string(
"->")+entryName);
739 const std::string & ,
const std::string &name_in,
745 ,
"Error! The parameter \""<<name_in<<
"\" does not exist"\
746 "\nin the parameter (sub)list \""<<this->
name()<<
"\"."
747 "\n\nThe current parameters set in (sub)list \""<<this->
name()<<
"\" are:\n\n"
759 ,
"Error, the parameter \"" << name_in <<
"\" is not a list, it is of type \""
765 const std::string &sublist_name,
const bool mustAlreadyExist)
const
769 ,
"The sublist "<<baselist_name<<
"->\""<<sublist_name<<
"\" does not exist!"
785 if (!Teuchos::haveSameModifiers(list1, list2)){
788 ParameterList::ConstIterator itr1, itr2;
790 itr1 = list1.begin(), itr2 = list2.begin();
791 itr1 != list1.end() && itr2 != list2.end();
795 const std::string &entryName1 = list1.name(itr1);
796 const std::string &entryName2 = list2.name(itr2);
797 const ParameterEntry &entry1 = list1.entry(itr1);
798 const ParameterEntry &entry2 = list2.entry(itr2);
799 if( entryName1 != entryName2 ) {
802 else if( entry1 != entry2 ) {
811 if ((itr1 != list1.end()) || (itr2 != list2.end())) {
818 bool Teuchos::haveSameModifiers(
const ParameterList &list1,
const ParameterList &list2) {
820 ParameterList::ConstIterator itr1, itr2;
822 itr1 = list1.begin(), itr2 = list2.begin();
823 itr1 != list1.end() && itr2 != list2.end();
829 if( modifier1 != modifier2 ) {
836 Teuchos::getValue<ParameterList>(entry2) ) ){
845 bool Teuchos::haveSameValues(
const ParameterList& list1,
const ParameterList& list2,
bool verbose )
853 ParameterList::ConstIterator itr1, itr2;
855 itr1 = list1.begin(), itr2 = list2.begin();
856 itr1 != list1.end() && itr2 != list2.end();
860 const std::string &entryName1 = list1.name(itr1);
861 const std::string &entryName2 = list2.name(itr2);
862 const ParameterEntry &entry1 = list1.entry(itr1);
863 const ParameterEntry &entry2 = list2.entry(itr2);
864 if( entryName1 != entryName2 ) {
865 if (verbose) std::cerr <<
"entryName1 \"" << entryName1 <<
"\" != entryName2 \"" << entryName2 <<
"\"\n";
868 if( entry1.isList() && entry2.isList() ) {
871 getValue<ParameterList>(entry1),
872 getValue<ParameterList>(entry2),
880 if (verbose) std::cerr <<
"sublists \"" << entryName1 <<
"\" differ\n";
885 if( entry1.getAny() != entry2.getAny() ) {
886 if (verbose) std::cerr <<
"for key \"" << entryName1 <<
"\", value \"" << entry1.
getAny() <<
"\" != \"" << entry2.getAny() <<
"\"\n";
892 if ((itr1 != list1.end()) || (itr2 != list2.end())) {
893 if (verbose) std::cerr <<
"lists are not the same size\n";
900 bool Teuchos::haveSameValuesSorted(
const ParameterList& list1,
const ParameterList& list2,
bool verbose )
908 ParameterList::ConstIterator itr1, itr2;
909 Array<std::string> arr1, arr2;
910 for(itr1 = list1.begin(); itr1 != list1.end(); ++itr1){
911 arr1.push_back(list1.name(itr1));
913 for(itr2 = list2.begin(); itr2 != list2.end(); ++itr2){
914 arr2.push_back(list2.name(itr2));
917 if (arr1.size() != arr2.size()) {
918 if (verbose) std::cerr <<
"lists are not the same size\n";
921 std::sort(arr1.begin(), arr1.end());
922 std::sort(arr2.begin(), arr2.end());
925 iarr1 = arr1.begin(), iarr2 = arr2.begin();
926 iarr1 != arr1.end() && iarr2 != arr2.end();
930 const std::string &entryName1 = *iarr1;
931 const std::string &entryName2 = *iarr2;
932 const ParameterEntry &entry1 = list1.getEntry(entryName1);
933 const ParameterEntry &entry2 = list2.getEntry(entryName2);
934 if( entryName1 != entryName2 ) {
935 if (verbose) std::cerr <<
"entryName1 \"" << entryName1 <<
"\" != entryName2 \"" << entryName2 <<
"\"\n";
938 if( entry1.isList() && entry2.isList() ) {
941 getValue<ParameterList>(entry1),
942 getValue<ParameterList>(entry2),
950 if (verbose) std::cerr <<
"sublists \"" << entryName1 <<
"\" differ\n";
955 if( entry1.getAny() != entry2.getAny() ) {
956 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.
bool disableRecursiveModification_
Modify into list or not.
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.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
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.
T * get() const
Get the raw C++ pointer to the underlying object.
bool disableRecursiveReconciliation_
Reconcile into list or not.
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
ParameterList & disableRecursiveAll()
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)
ParameterList & disableRecursiveReconciliation()
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.
RCP< const ParameterListModifier > modifier_
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.
void modifyParameterList(ParameterList &validParamList, int const depth=1000)
Modify the valid parameter list prior to validation.
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...
RCP< const ParameterListModifier > getModifier() const
Return the optional modifier object.
ParameterList()=default
Constructor.
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)
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.
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT bool haveSameModifiers(const ParameterList &list1, const ParameterList &list2)
Returns true if two parameter lists have the same modifiers.
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
ParameterList & disableRecursiveModification()
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)
void reconcileParameterList(ParameterList &validParamList, const bool left_to_right=true)
Reconcile a parameter list after validation.
void setModifier(RCP< const ParameterListModifier > const &modifier)
#define TEUCHOS_TEST_FOR_EXCEPTION_PURE_MSG(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.