Teuchos - Trilinos Tools Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_StandardDependencies.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 
11 #include "Teuchos_StandardParameterEntryValidators.hpp"
12 
13 
14 namespace Teuchos{
15 
16 
19  RCP<ParameterEntry> dependent,
20  bool showIf):
21  Dependency(dependee, dependent),
22  dependentVisible_(false),
23  showIf_(showIf)
24  {}
25 
28  ParameterEntryList dependents,
29  bool showIf):
30  Dependency(dependee, dependents),
31  dependentVisible_(false),
32  showIf_(showIf)
33  {}
34 
36  ConstParameterEntryList dependees,
37  RCP<ParameterEntry> dependent,
38  bool showIf):
39  Dependency(dependees, dependent),
40  dependentVisible_(false),
41  showIf_(showIf)
42  {}
43 
45  ConstParameterEntryList dependees,
46  ParameterEntryList dependents,
47  bool showIf):
48  Dependency(dependees, dependents),
49  dependentVisible_(false),
50  showIf_(showIf)
51  {}
52 
54  return dependentVisible_;
55 }
56 
58  return showIf_;
59 }
60 
62  if((getDependeeState() && showIf_) || (!getDependeeState() && !showIf_)){
63  dependentVisible_ = true;
64  }
65  else{
66  dependentVisible_ = false;
67  }
68 }
69 
72  RCP<ParameterEntry> dependent):
73  Dependency(dependee, dependent){}
74 
77  ParameterEntryList dependents):
78  Dependency(dependee, dependents){}
79 
82  RCP<ParameterEntry> dependent,
83  std::string value,
84  bool showIf):
85  VisualDependency(dependee, dependent, showIf),
86  values_(ValueList(1,value))
87 {
88  validateDep();
89 }
90 
93  RCP<ParameterEntry> dependent,
94  const ValueList& values,
95  bool showIf):
96  VisualDependency(dependee, dependent, showIf),
97  values_(values)
98 {
99  validateDep();
100 }
101 
103  RCP<const ParameterEntry> dependee,
105  const std::string& value,
106  bool showIf):
107  VisualDependency(dependee, dependents, showIf),
108  values_(ValueList(1,value))
109 {
110  validateDep();
111 }
112 
114  RCP<const ParameterEntry> dependee,
116  const ValueList& values,
117  bool showIf):
118  VisualDependency(dependee, dependents, showIf),
119  values_(values)
120 {
121  validateDep();
122 }
123 
126 {
127  return values_;
128 }
129 
131  return find(values_.begin(), values_.end(),
132  getFirstDependeeValue<std::string>()) != values_.end();
133 }
134 
136  return "StringVisualDependency";
137 }
138 
140  TEUCHOS_TEST_FOR_EXCEPTION(!getFirstDependee()->isType<std::string>(),
142  "Ay no! The dependee of a "
143  "String Visual Dependency must be of type "
144  << TypeNameTraits<std::string>::name() << std::endl <<
145  "Type encountered: " << getFirstDependee()->getAny().typeName() <<
146  std::endl << std::endl);
147 }
148 
151 {
152  std::string blahString = "blah";
153  return rcp(new StringVisualDependency(
154  rcp(new ParameterEntry(blahString)),
156  "i'm a dummy"));
157 }
158 
160  RCP<const ParameterEntry> dependee,
161  RCP<ParameterEntry> dependent,
162  bool showIf):
163  VisualDependency(dependee, dependent, showIf)
164 {
165  validateDep();
166 }
167 
169  RCP<const ParameterEntry> dependee,
171  bool showIf):
172  VisualDependency(dependee, dependents, showIf)
173 {
174  validateDep();
175 }
176 
178  return getFirstDependeeValue<bool>();
179 }
180 
182  return "BoolVisualDependency";
183 }
184 
186  TEUCHOS_TEST_FOR_EXCEPTION(!getFirstDependee()->isType<bool>(),
188  "Ay no! The dependee of a "
189  "Bool Visual Dependency must be of type " <<
190  TypeNameTraits<bool>::name() << std::endl <<
191  "Encountered type: " << getFirstDependee()->getAny().typeName() <<
192  std::endl << std::endl);
193 }
194 
197 {
198  return rcp(new BoolVisualDependency(
199  rcp(new ParameterEntry(true)),
201 }
202 
204  RCP<const Condition> condition,
205  RCP<ParameterEntry> dependent,
206  bool showIf):
207  VisualDependency(condition->getAllParameters(), dependent, showIf),
208  condition_(condition)
209 {
210  validateDep();
211 }
212 
214  RCP<const Condition> condition,
216  bool showIf):
217  VisualDependency(condition->getAllParameters(), dependents, showIf),
218  condition_(condition)
219 {
220  validateDep();
221 }
222 
224  return condition_;
225 }
226 
228  return condition_->isConditionTrue();
229 }
230 
232  return "ConditionVisualDependency";
233 }
234 
237 {
238  return rcp(new ConditionVisualDependency(
241 }
242 
244  RCP<const ParameterEntry> dependee,
245  RCP<ParameterEntry> dependent,
246  ValueToValidatorMap valuesAndValidators,
247  RCP<ParameterEntryValidator> defaultValidator):
248  ValidatorDependency(dependee, dependent),
249  valuesAndValidators_(valuesAndValidators),
250  defaultValidator_(defaultValidator)
251 {
252  validateDep();
253 }
254 
256  RCP<const ParameterEntry> dependee,
258  ValueToValidatorMap valuesAndValidators,
259  RCP<ParameterEntryValidator> defaultValidator):
260  ValidatorDependency(dependee, dependents),
261  valuesAndValidators_(valuesAndValidators),
262  defaultValidator_(defaultValidator)
263 {
264  validateDep();
265 }
266 
269 {
270  return valuesAndValidators_;
271 }
272 
275 {
276  return defaultValidator_;
277 }
278 
280  std::string currentDependeeValue = getFirstDependeeValue<std::string>();
281  for(
282  ParameterEntryList::iterator it = getDependents().begin();
283  it != getDependents().end();
284  ++it)
285  {
286  if(
287  valuesAndValidators_.find(currentDependeeValue)
288  ==
289  valuesAndValidators_.end())
290  {
291  (*it)->setValidator(defaultValidator_);
292  }
293  else{
294  (*it)->setValidator(valuesAndValidators_[currentDependeeValue]);
295  }
296  }
297 }
298 
300  return "StringValidatorDependency";
301 }
302 
304  TEUCHOS_TEST_FOR_EXCEPTION(!getFirstDependee()->isType<std::string>(),
306  "Ay no! The dependee of a "
307  "String Validator Dependency must be of type " <<
308  TypeNameTraits<std::string>::name() << std::endl <<
309  "Type Encountered: " << getFirstDependee()->getAny().typeName() <<
310  std::endl << std::endl);
311 
313  valuesAndValidators_.size() < 1,
315  "The valuesAndValidatord map for a string validator dependency must "
316  "have at least one entry!" << std::endl << std::endl);
317  ValueToValidatorMap::const_iterator it = valuesAndValidators_.begin();
318  RCP<const ParameterEntryValidator> firstVali = (it->second);
319  //using the raw pointer avoids a Clang warning about side effects in typeid
320  const ParameterEntryValidator* rawFirstValidatorPtr = firstVali.get();
321  ++it;
322  for(; it != valuesAndValidators_.end(); ++it){
323  const ParameterEntryValidator* rawValidatorPtr = it->second.get();
324  TEUCHOS_TEST_FOR_EXCEPTION( typeid(*rawFirstValidatorPtr) != typeid(*rawValidatorPtr),
326  "Ay no! All of the validators in a StringValidatorDependency "
327  "must have the same type.");
328  }
329 }
330 
331 
334 {
335  std::string blahString = "blah";
339  return rcp(new StringValidatorDependency(
340  rcp(new ParameterEntry(blahString)),
342  dummyMap));
343 }
344 
346  RCP<const ParameterEntry> dependee,
347  RCP<ParameterEntry> dependent,
349  RCP<const ParameterEntryValidator> falseValidator):
350  ValidatorDependency(dependee, dependent),
351  trueValidator_(trueValidator),
352  falseValidator_(falseValidator)
353 {
354  validateDep();
355 }
356 
358  RCP<const ParameterEntry> dependee,
361  RCP<const ParameterEntryValidator> falseValidator):
362  ValidatorDependency(dependee, dependents),
363  trueValidator_(trueValidator),
364  falseValidator_(falseValidator)
365 {
366  validateDep();
367 }
368 
370  bool dependeeValue = getFirstDependeeValue<bool>();
371  for(
372  ParameterEntryList::iterator it = getDependents().begin();
373  it != getDependents().end();
374  ++it)
375  {
376  dependeeValue ?
377  (*it)->setValidator(trueValidator_)
378  :
379  (*it)->setValidator(falseValidator_);
380  }
381 }
382 
385 {
386  return trueValidator_;
387 }
388 
391 {
392  return falseValidator_;
393 }
394 
396  return "BoolValidatorDependency";
397 }
398 
399 
401 
402  TEUCHOS_TEST_FOR_EXCEPTION(!getFirstDependee()->isType<bool>(),
404  "Ay no! The dependee of a "
405  "Bool Validator Dependency must be of type " <<
406  TypeNameTraits<bool>::name() << std::endl <<
407  "Encountered type: " << getFirstDependee()->getAny().typeName() <<
408  std::endl << std::endl);
409 
410  if(!falseValidator_.is_null() && !trueValidator_.is_null()){
411  //avoid Clang warnings about side effects in typeid
412  const ParameterEntryValidator* rawFalseValidatorPtr = falseValidator_.get();
413  const ParameterEntryValidator* rawTrueValidatorPtr = trueValidator_.get();
414  TEUCHOS_TEST_FOR_EXCEPTION(typeid(*rawFalseValidatorPtr) != typeid(*rawTrueValidatorPtr),
416  "Ay no! The true and false validators of a Bool Validator Dependency "
417  "must be the same type! " <<std::endl << std::endl);
418  }
419 
420 }
421 
424 {
425  return rcp(new BoolValidatorDependency(
426  rcp(new ParameterEntry(true)),
428  null, null));
429 }
430 
431 }
432 
RCP< const ParameterEntryValidator > getDefaultValidator() const
static RCP< T > getDummyObject()
Retrieves a dummy object of type T.
A BoolValidatorDependency says the following about the relationship between two parameters: Dependeni...
std::pair< std::string, RCP< const ParameterEntryValidator > > ValueToValidatorPair
Conveniece typedef.
std::set< RCP< const ParameterEntry >, RCPConstComp > ConstParameterEntryList
A list of dependents.
An abstract parent class for all visual dependencies.
ParameterEntryList & getDependents()
Gets the dependents of the dependency.
BoolValidatorDependency(RCP< const ParameterEntry > dependee, RCP< ParameterEntry > dependent, RCP< const ParameterEntryValidator > trueValidator, RCP< const ParameterEntryValidator > falseValidator=null)
Constructs a BoolValidatorDependency.
A string visual dependency says the following about the relationship between two elements in a Parame...
A bool visual dependency says the following about the relationship between two elements in a Paramete...
void validateDep() const
Validates the dependency to make sure it&#39;s valid/has been setup properly. If subclassing, this fucntion should be called in the new subclasses constructor.
std::set< RCP< ParameterEntry >, RCPComp > ParameterEntryList
A list of Dependees.
This object is held as the &quot;value&quot; in the Teuchos::ParameterList std::map.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
bool getShowIf() const
Get&#39;s the value of the showIf variable.
const ValueToValidatorMap & getValuesAndValidators() const
retrieve a const reference to the ValueToValidator map being used by this StringValidatorDependency ...
T * get() const
Get the raw C++ pointer to the underlying object.
VisualDependency(RCP< const ParameterEntry > dependee, RCP< ParameterEntry > dependent, bool showIf=getShowIfDefaultValue())
Constructs a VisualDependency.
std::map< std::string, RCP< const ParameterEntryValidator > > ValueToValidatorMap
Conveniece typedef.
This class represents a depndency between elements in a Parameter List.
const ValueList & getValues() const
get the List of values the dependee will be checked against.
RCP< const ParameterEntryValidator > getFalseValidator() const
Gets the false validator.
BoolVisualDependency(RCP< const ParameterEntry > dependee, RCP< ParameterEntry > dependent, bool showIf=true)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
StringVisualDependency(RCP< const ParameterEntry > dependee, RCP< ParameterEntry > dependent, std::string value, bool showIf=true)
Constructs a StringVisualDependency.
RCP< const ParameterEntryValidator > getTrueValidator() const
Gets the true validator.
ValidatorDependency(RCP< const ParameterEntry > dependee, RCP< ParameterEntry > dependent)
Constructs a ValidatorDependency.
A collection of standard dependencies.
RCP< const ParameterEntry > getFirstDependee() const
Gets the first dependee in the dependees list. This is a convience function.
Abstract interface for an object that can validate a ParameterEntry&#39;s value.
RCP< const Condition > getCondition() const
Gets the condition being used in this dependency.
Default traits class that just returns typeid(T).name().
Class for retrieving a dummy object of type T.
A StringValidatorDependency says the following about the relationship between two parameters: Depende...
ConditionVisualDependency(RCP< const Condition > condition, RCP< ParameterEntry > dependent, bool showIf=true)
An abstract base class for all validator dependencies.
StringValidatorDependency(RCP< const ParameterEntry > dependee, RCP< ParameterEntry > dependent, ValueToValidatorMap valuesAndValidators, RCP< ParameterEntryValidator > defaultValidator=null)
Constructs a StringValidatorDependency.
Smart reference counting pointer class for automatic garbage collection.
A condition visual dependency says the following about the relationship between elements in a Paramet...
bool isDependentVisible() const
Determines whether or not the dependent is currently visible.
virtual bool getDependeeState() const =0
Get the state of the dependee in order to evaluate the dependency.
iterator begin()
std::string typeName(const T &t)
Template function for returning the concrete type name of a passed-in object.
void validateDep() const
Validates the dependency to make sure it&#39;s valid/has been setup properly. If subclassing, this fucntion should be called in the new subclasses constructor.