Teuchos - Trilinos Tools Package Version of the Day
Loading...
Searching...
No Matches
Teuchos_StandardConditions.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
12namespace Teuchos{
13
15 parameterEntry_(parameter)
16{
19 "Parameter conditions can't be given a null parameter" <<
20 std::endl << std::endl);
21}
22
25{
27 toReturn.insert(getParameter());
28 return toReturn;
29}
30
31BoolLogicCondition::BoolLogicCondition(ConstConditionList& conditions):
32 conditions_(conditions)
33{
34 TEUCHOS_TEST_FOR_EXCEPTION(conditions_.size() ==0,
36 "You must provide at least one condition "
37 "when you're constructing a BoolLogicCondition. "
38 << std::endl << std::endl <<
39 "Error: Empty condition list given to a BoolLogicCondition "
40 "constructor.");
41}
42
43
45 conditions_.append(toAdd);
46}
47
49 ConstConditionList::const_iterator it = conditions_.begin();
50 bool toReturn = (*it)->isConditionTrue();
51 ++it;
52 for(;it != conditions_.end(); ++it){
53 toReturn = applyOperator(toReturn,(*it)->isConditionTrue());
54 }
55 return toReturn;
56}
57
59 for(
60 ConstConditionList::const_iterator it=conditions_.begin();
61 it!=conditions_.end();
62 ++it)
63 {
64 if((*it)->containsAtLeasteOneParameter()){
65 return true;
66 }
67 }
68 return false;
69}
70
75 for(
76 ConstConditionList::const_iterator it = conditions_.begin();
77 it != conditions_.end();
78 ++it)
79 {
80 currentList = (*it)->getAllParameters();
81 toReturn.insert(currentList.begin(), currentList.end());
82 }
83 return toReturn;
84}
85
86OrCondition::OrCondition(ConstConditionList& conditions):
87 BoolLogicCondition(conditions){}
88
89bool OrCondition::applyOperator(bool op1, bool op2) const{
90 return op1 || op2;
91}
92
94 Condition::ConstConditionList dummyList;
96 return rcp(new OrCondition(dummyList));
97}
98
99AndCondition::AndCondition(ConstConditionList& conditions):
100 BoolLogicCondition(conditions){}
101
102bool AndCondition::applyOperator(bool op1, bool op2) const{
103 return op1 && op2;
104}
105
107 Condition::ConstConditionList dummyList;
109 return rcp(new AndCondition(dummyList));
110}
111
112EqualsCondition::EqualsCondition(ConstConditionList& conditions):
113 BoolLogicCondition(conditions){}
114
115bool EqualsCondition::applyOperator(bool op1, bool op2) const{
116 return op1 == op2;
117}
118
120 Condition::ConstConditionList dummyList;
122 return rcp(new EqualsCondition(dummyList));
123}
124
126 childCondition_(childCondition)
127{
128 TEUCHOS_TEST_FOR_EXCEPTION(childCondition_.is_null(),
130 "OOOOOOOOPppppps! Looks like you tried "
131 "to give me "
132 "a null pointer when you were making a not conditon. "
133 "That's a no no. Go back and "
134 "checkout your not conditions and make sure you didn't "
135 "give any of them a null pointer "
136 "as an argument to the constructor." << std::endl << std::endl <<
137 "Error: Null pointer given to NotCondition constructor.");
138}
139
141 return (!childCondition_->isConditionTrue());
142}
143
145 return childCondition_->containsAtLeasteOneParameter();
146}
147
149 return childCondition_->getAllParameters();
150}
151
156
159 std::string value):
160 ParameterCondition(parameter),
161 values_(ValueList(1,value))
162{
163 checkParameterType();
164}
165
168 ValueList values):
169 ParameterCondition(parameter),
170 values_(values)
171{
172 checkParameterType();
173}
174
175void StringCondition::checkParameterType(){
176 TEUCHOS_TEST_FOR_EXCEPTION(!getParameter()->isType<std::string>(),
178 "The parameter of a String Condition "
179 "must be of type string." << std::endl <<
180 "Expected type: " << TypeNameTraits<std::string>::name() << std::endl <<
181 "Actual type: " << getParameter()->getAny().typeName() <<
182 std::endl << std::endl);
183}
184
185
187 return find(
188 values_.begin(), values_.end(),
189 getValue<std::string>(*getParameter())) != values_.end();
190}
191
193 std::string empty = "";
194 return rcp(new StringCondition(rcp(new ParameterEntry(empty)), empty));
195}
196
198 ParameterCondition(parameter)
199{
200 TEUCHOS_TEST_FOR_EXCEPTION(!getParameter()->isType<bool>(),
202 "The parameter of a Bool Condition "
203 "must be of type " << TypeNameTraits<bool>::name() << std::endl <<
204 "Expected type: Bool" << std::endl <<
205 "Actual type: " << getParameter()->getAny().typeName() <<
206 std::endl << std::endl);
207}
208
212
216
217
218} //namespace Teuchos
219
Standard Conditions to be used.
A Bool Logic Condition that returns the result or perfroming a logical AND on the conditions.
AndCondition(ConstConditionList &conditions)
Constructs an And Condition.
bool applyOperator(bool op1, bool op2) const
std::vector< Teuchos::RCP< const Condition > >::const_iterator const_iterator
Array< T > & append(const T &x)
Add a new entry at the end of the array.
A Bool Condition is a Parameter Condition that evaluates whether or not a Boolean parameter is ture.
BoolCondition(RCP< const ParameterEntry > parameter)
Constructs a Bool Condition.
Dependency::ConstParameterEntryList getAllParameters() const
BoolLogicCondition(ConstConditionList &conditions)
Constructs a BoolLogicCondition.
void addCondition(RCP< const Condition > toAdd)
Adds a Condition to the list of conditions that will be evaluated by this Bool Logic Condition.
virtual bool applyOperator(bool op1, bool op2) const =0
Applies a Bool Logic operator to two operands and returns the result.
std::set< RCP< const ParameterEntry >, RCPConstComp > ConstParameterEntryList
A list of dependents.
static RCP< T > getDummyObject()
Retrieves a dummy object of type T.
A Bool Logic Condition that returns the result or perfroming a logical EQUALS on the conditions.
bool applyOperator(bool op1, bool op2) const
EqualsCondition(ConstConditionList &conditions)
Constructs an Equals Condition.
A Not condition returns the result of performing a logical NOT on a given condition.
Dependency::ConstParameterEntryList getAllParameters() const
NotCondition(RCP< const Condition > condition)
Constructs a Not Condition.
A Bool Logic Condition that returns the result or perfroming a logical OR on the conditions.
OrCondition(ConstConditionList &conditions)
Constructs an Or Condition.
bool applyOperator(bool op1, bool op2) const
ParameterCondition(RCP< const ParameterEntry > parameter)
Constructs a Parameter Condition.
RCP< const ParameterEntry > getParameter() const
Gets a const pointer to the Parameter being evaluated by this ParameterCondition.
Dependency::ConstParameterEntryList getAllParameters() const
Gets all of the parameters that are evaluated in this condition.
This object is held as the "value" in the Teuchos::ParameterList std::map.
T & getValue(const ParameterEntry &entry)
A templated helper function for returning the value of type T held in the ParameterEntry object,...
Smart reference counting pointer class for automatic garbage collection.
A String Condition is a Parameter Condition that evaluates whether or not a string parameter has take...
StringCondition(RCP< const ParameterEntry > parameter, std::string value)
Constructs a String Condition.
Array< std::string > ValueList
Convience typedef representing an array of strings.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
bool is_null(const std::shared_ptr< T > &p)
Returns true if p.get()==NULL.
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,...
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.