Teuchos - Trilinos Tools Package Version of the Day
Loading...
Searching...
No Matches
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
14namespace Teuchos{
15
16
20 bool showIf):
21 Dependency(dependee, dependent),
22 dependentVisible_(false),
23 showIf_(showIf)
24 {}
25
29 bool showIf):
30 Dependency(dependee, dependents),
31 dependentVisible_(false),
32 showIf_(showIf)
33 {}
34
43
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
74
79
83 std::string value,
84 bool showIf):
86 values_(ValueList(1,value))
87{
89}
90
94 const ValueList& values,
95 bool showIf):
97 values_(values)
98{
100}
101
105 const std::string& value,
106 bool showIf):
108 values_(ValueList(1,value))
109{
110 validateDep();
111}
112
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
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
158
167
176
180
182 return "BoolVisualDependency";
183}
184
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
202
212
222
226
228 return condition_->isConditionTrue();
229}
230
232 return "ConditionVisualDependency";
233}
234
242
254
266
269{
270 return valuesAndValidators_;
271}
272
275{
276 return defaultValidator_;
277}
278
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
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();
319 //using the raw pointer avoids a Clang warning about side effects in typeid
321 ++it;
322 for(; it != valuesAndValidators_.end(); ++it){
326 "Ay no! All of the validators in a StringValidatorDependency "
327 "must have the same type.");
328 }
329}
330
331
344
356
368
371 for(
372 ParameterEntryList::iterator it = getDependents().begin();
373 it != getDependents().end();
374 ++it)
375 {
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
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();
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
430
431}
432
A collection of standard dependencies.
A BoolValidatorDependency says the following about the relationship between two parameters: Dependeni...
BoolValidatorDependency(RCP< const ParameterEntry > dependee, RCP< ParameterEntry > dependent, RCP< const ParameterEntryValidator > trueValidator, RCP< const ParameterEntryValidator > falseValidator=null)
Constructs a BoolValidatorDependency.
RCP< const ParameterEntryValidator > getTrueValidator() const
Gets the true validator.
void validateDep() const
Validates the dependency to make sure it's valid/has been setup properly. If subclassing,...
RCP< const ParameterEntryValidator > getFalseValidator() const
Gets the false validator.
A bool visual dependency says the following about the relationship between two elements in a Paramete...
BoolVisualDependency(RCP< const ParameterEntry > dependee, RCP< ParameterEntry > dependent, bool showIf=true)
A condition visual dependency says the following about the relationship between elements in a Paramet...
ConditionVisualDependency(RCP< const Condition > condition, RCP< ParameterEntry > dependent, bool showIf=true)
RCP< const Condition > getCondition() const
Gets the condition being used in this dependency.
This class represents a depndency between elements in a Parameter List.
ParameterEntryList & getDependents()
Gets the dependents of the dependency.
std::set< RCP< ParameterEntry >, RCPComp > ParameterEntryList
A list of Dependees.
std::set< RCP< const ParameterEntry >, RCPConstComp > ConstParameterEntryList
A list of dependents.
RCP< const ParameterEntry > getFirstDependee() const
Gets the first dependee in the dependees list. This is a convience function.
Class for retrieving a dummy object of type T.
static RCP< T > getDummyObject()
Retrieves a dummy object of type T.
Abstract interface for an object that can validate a ParameterEntry's value.
This object is held as the "value" in the Teuchos::ParameterList std::map.
Smart reference counting pointer class for automatic garbage collection.
RCP< T > rcp(const boost::shared_ptr< T > &sptr)
Conversion function that takes in a boost::shared_ptr object and spits out a Teuchos::RCP object.
bool is_null() const
Returns true if the underlying pointer is null.
T * get() const
Get the raw C++ pointer to the underlying object.
A StringValidatorDependency says the following about the relationship between two parameters: Depende...
void validateDep() const
Validates the dependency to make sure it's valid/has been setup properly. If subclassing,...
const ValueToValidatorMap & getValuesAndValidators() const
retrieve a const reference to the ValueToValidator map being used by this StringValidatorDependency
RCP< const ParameterEntryValidator > getDefaultValidator() const
std::pair< std::string, RCP< const ParameterEntryValidator > > ValueToValidatorPair
Conveniece typedef.
StringValidatorDependency(RCP< const ParameterEntry > dependee, RCP< ParameterEntry > dependent, ValueToValidatorMap valuesAndValidators, RCP< ParameterEntryValidator > defaultValidator=null)
Constructs a StringValidatorDependency.
std::map< std::string, RCP< const ParameterEntryValidator > > ValueToValidatorMap
Conveniece typedef.
A string visual dependency says the following about the relationship between two elements in a Parame...
const ValueList & getValues() const
get the List of values the dependee will be checked against.
StringVisualDependency(RCP< const ParameterEntry > dependee, RCP< ParameterEntry > dependent, std::string value, bool showIf=true)
Constructs a StringVisualDependency.
Default traits class that just returns typeid(T).name().
An abstract base class for all validator dependencies.
ValidatorDependency(RCP< const ParameterEntry > dependee, RCP< ParameterEntry > dependent)
Constructs a ValidatorDependency.
An abstract parent class for all visual dependencies.
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.
bool getShowIf() const
Get's the value of the showIf variable.
VisualDependency(RCP< const ParameterEntry > dependee, RCP< ParameterEntry > dependent, bool showIf=getShowIfDefaultValue())
Constructs a VisualDependency.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
std::string typeName(const T &t)
Template function for returning the concrete type name of a passed-in object.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...