Teuchos - Trilinos Tools Package Version of the Day
Loading...
Searching...
No Matches
Teuchos_ParameterListModifier.cpp
1// @HEADER
2// *****************************************************************************
3// Teuchos: Common Tools Package
4//
5// Copyright 2004 NTESS and the Teuchos contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
12#include "Teuchos_StrUtils.hpp"
13
14namespace Teuchos {
15
16
17// Constructors and/or destructors
21
24
25
26void ParameterListModifier::printDoc(std::string const& docString, std::ostream &out) const
27{
28 StrUtils::printLines(out,"# ",docString);
29 out << "# Modifier Used: " << name_ << std::endl;
30}
31
32
34 const std::string &base_name, const bool &find_parameters, const bool &find_sublists) const
35{
38 for (itr = pl.begin(); itr != pl.end(); ++itr) {
39 const std::string &name = pl.name(itr);
40 std::size_t found = name.find(base_name);
41 if (found == 0){
42 if (pl.isSublist(name)){
43 if (find_sublists){
44 matches.push_back(name);
45 }
46 } else{
47 if (find_parameters){
48 matches.push_back(name);
49 }
50 }
51 }
52 }
53 return matches;
54}
55
56
60{
61 int replacements = 0;
63 std::sort(ignore_names.begin(), ignore_names.end());
65 if (valid_pl.isParameter(param_template_name)){
67 for (itr = pl.begin(); itr != pl.end(); ++itr) {
68 const std::string &param_name = pl.name(itr);
69 if (!pl.isSublist(param_name)){
70 if (!std::binary_search(ignore_names.begin(), ignore_names.end(), param_name)){
72 replacements += 1;
73 }
74 }
75 }
77 }
78 return replacements;
79}
80
81
85{
86 int replacements = 0;
88 std::sort(ignore_names.begin(), ignore_names.end());
90 if (valid_pl.isSublist(sublist_template_name)){
92 for (itr = pl.begin(); itr != pl.end(); ++itr) {
93 const std::string &subname = pl.name(itr);
94 if (pl.isSublist(subname)){
95 if (!std::binary_search(ignore_names.begin(), ignore_names.end(), subname)){
97 replacements += 1;
98 }
99 }
100 }
102 }
103 return replacements;
104}
105
106
108 const std::string &base_name, ParameterList &pl, ParameterList &valid_pl,
109 const bool &allow_base_name) const
110{
111 int replacements = 0;
112 bool delete_base_name = true;
113 if (valid_pl.isSublist(base_name)){
114 if (pl.isSublist(base_name)){
116 "Sublist can't have the same name as the parameter template name "
117 "without `allow_base_name=true`.");
118 delete_base_name = false;
119 }
121 replacements = matches.length();
122 for (const std::string &match_name : matches){
124 }
125 if (delete_base_name){
126 valid_pl.remove(base_name);
127 }
128 }
129 return replacements;
130}
131
132
135 const bool remove_param) const
136{
137 int num_defaults = 0;
138 if (pl.isParameter(param_name)){
139 for (const std::string &sublist_name : sublist_names){
140 if (pl.isSublist(sublist_name)){
141 ParameterList &sublist = pl.sublist(sublist_name);
142 if (!sublist.isParameter(param_name)){
144 sublist.setEntry(param_name, pl_entry);
145 }
146 }
147 }
148 if (remove_param){
149 pl.remove(param_name);
150 }
151 }
152 return num_defaults;
153}
154
155
156} // namespace Teuchos
Parameter List Modifier class.
Templated Parameter List class.
A std::string utilities class for Teuchos.
This object is held as the "value" in the Teuchos::ParameterList std::map.
int expandSublistsUsingBaseName(const std::string &baseName, ParameterList &paramList, ParameterList &validParamList, const bool &allowBaseName=true) const
Create sublists in the valid parameter list using a base name and the corresponding sublists in the p...
int expandParameters(const std::string &paramTemplateName, ParameterList &paramList, ParameterList &validParamList, const Array< std::string > &excludeParameters=Array< std::string >()) const
Create parameters in the valid parameter list using a template parameter from the valid parameter lis...
ParameterListModifier()=default
Constructor.
void printDoc(std::string const &docString, std::ostream &out) const
Print documentation for this parameter list modifier.
int setDefaultsInSublists(const std::string &paramName, ParameterList &paramList, const Array< std::string > &sublistNames, const bool removeParam=true) const
Copy a parameter into desired sublists.
Array< std::string > findMatchingBaseNames(const ParameterList &paramList, const std::string &baseName, const bool &findParameters=true, const bool &findSublists=true) const
Find the parameters and/or sublists with matching base names.
int expandSublists(const std::string &sublistTemplateName, ParameterList &paramList, ParameterList &validParamList, const Array< std::string > &excludeSublists=Array< std::string >()) const
Create sublists in the valid parameter list using a template parameter from the valid parameter list ...
A list of parameters of arbitrary type.
ParameterList & setEntry(const std::string &name, U &&entry)
Set a parameter directly as a ParameterEntry.
params_t::ConstIterator ConstIterator
Parameter container const iterator typedef.
bool isParameter(const std::string &name) const
Whether the given parameter exists in this list.
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.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...