Teuchos - Trilinos Tools Package Version of the Day
Loading...
Searching...
No Matches
Teuchos_StandardDependencies.cpp
1// @HEADER
2// ***********************************************************************
3//
4// Teuchos: Common Tools Package
5// Copyright (2004) Sandia Corporation
6//
7// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8// license for use of this work by or on behalf of the U.S. Government.
9//
10// Redistribution and use in source and binary forms, with or without
11// modification, are permitted provided that the following conditions are
12// met:
13//
14// 1. Redistributions of source code must retain the above copyright
15// notice, this list of conditions and the following disclaimer.
16//
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// 3. Neither the name of the Corporation nor the names of the
22// contributors may be used to endorse or promote products derived from
23// this software without specific prior written permission.
24//
25// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36//
37// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38//
39// ***********************************************************************
40// @HEADER
41
42
43
45#include "Teuchos_StandardParameterEntryValidators.hpp"
46
47
48namespace Teuchos{
49
50
54 bool showIf):
55 Dependency(dependee, dependent),
56 dependentVisible_(false),
57 showIf_(showIf)
58 {}
59
63 bool showIf):
64 Dependency(dependee, dependents),
65 dependentVisible_(false),
66 showIf_(showIf)
67 {}
68
77
86
88 return dependentVisible_;
89}
90
92 return showIf_;
93}
94
96 if((getDependeeState() && showIf_) || (!getDependeeState() && !showIf_)){
97 dependentVisible_ = true;
98 }
99 else{
100 dependentVisible_ = false;
101 }
102}
103
108
113
117 std::string value,
118 bool showIf):
120 values_(ValueList(1,value))
121{
122 validateDep();
123}
124
128 const ValueList& values,
129 bool showIf):
131 values_(values)
132{
133 validateDep();
134}
135
139 const std::string& value,
140 bool showIf):
142 values_(ValueList(1,value))
143{
144 validateDep();
145}
146
157
160{
161 return values_;
162}
163
165 return find(values_.begin(), values_.end(),
166 getFirstDependeeValue<std::string>()) != values_.end();
167}
168
170 return "StringVisualDependency";
171}
172
176 "Ay no! The dependee of a "
177 "String Visual Dependency must be of type "
178 << TypeNameTraits<std::string>::name() << std::endl <<
179 "Type encountered: " << getFirstDependee()->getAny().typeName() <<
180 std::endl << std::endl);
181}
182
192
201
210
214
216 return "BoolVisualDependency";
217}
218
222 "Ay no! The dependee of a "
223 "Bool Visual Dependency must be of type " <<
224 TypeNameTraits<bool>::name() << std::endl <<
225 "Encountered type: " << getFirstDependee()->getAny().typeName() <<
226 std::endl << std::endl);
227}
228
236
246
256
260
262 return condition_->isConditionTrue();
263}
264
266 return "ConditionVisualDependency";
267}
268
276
288
300
303{
304 return valuesAndValidators_;
305}
306
309{
310 return defaultValidator_;
311}
312
315 for(
316 ParameterEntryList::iterator it = getDependents().begin();
317 it != getDependents().end();
318 ++it)
319 {
320 if(
321 valuesAndValidators_.find(currentDependeeValue)
322 ==
323 valuesAndValidators_.end())
324 {
325 (*it)->setValidator(defaultValidator_);
326 }
327 else{
328 (*it)->setValidator(valuesAndValidators_[currentDependeeValue]);
329 }
330 }
331}
332
334 return "StringValidatorDependency";
335}
336
340 "Ay no! The dependee of a "
341 "String Validator Dependency must be of type " <<
342 TypeNameTraits<std::string>::name() << std::endl <<
343 "Type Encountered: " << getFirstDependee()->getAny().typeName() <<
344 std::endl << std::endl);
345
347 valuesAndValidators_.size() < 1,
349 "The valuesAndValidatord map for a string validator dependency must "
350 "have at least one entry!" << std::endl << std::endl);
351 ValueToValidatorMap::const_iterator it = valuesAndValidators_.begin();
353 //using the raw pointer avoids a Clang warning about side effects in typeid
355 ++it;
356 for(; it != valuesAndValidators_.end(); ++it){
360 "Ay no! All of the validators in a StringValidatorDependency "
361 "must have the same type.");
362 }
363}
364
365
378
390
402
405 for(
406 ParameterEntryList::iterator it = getDependents().begin();
407 it != getDependents().end();
408 ++it)
409 {
411 (*it)->setValidator(trueValidator_)
412 :
413 (*it)->setValidator(falseValidator_);
414 }
415}
416
419{
420 return trueValidator_;
421}
422
425{
426 return falseValidator_;
427}
428
430 return "BoolValidatorDependency";
431}
432
433
435
438 "Ay no! The dependee of a "
439 "Bool Validator Dependency must be of type " <<
440 TypeNameTraits<bool>::name() << std::endl <<
441 "Encountered type: " << getFirstDependee()->getAny().typeName() <<
442 std::endl << std::endl);
443
444 if(!falseValidator_.is_null() && !trueValidator_.is_null()){
445 //avoid Clang warnings about side effects in typeid
446 const ParameterEntryValidator* rawFalseValidatorPtr = falseValidator_.get();
447 const ParameterEntryValidator* rawTrueValidatorPtr = trueValidator_.get();
450 "Ay no! The true and false validators of a Bool Validator Dependency "
451 "must be the same type! " <<std::endl << std::endl);
452 }
453
454}
455
464
465}
466
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(ENull null_arg=null)
Initialize RCP<T> to NULL.
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 depdencies 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,...