Teuchos Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
Teuchos_StandardConditions.cpp
Go to the documentation of this file.
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
46namespace Teuchos{
47
49 parameterEntry_(parameter)
50{
53 "Parameter conditions can't be given a null parameter" <<
54 std::endl << std::endl);
55}
56
59{
61 toReturn.insert(getParameter());
62 return toReturn;
63}
64
66 conditions_(conditions)
67{
70 "You must provide at least one condition "
71 "when you're constructing a BoolLogicCondition. "
72 << std::endl << std::endl <<
73 "Error: Empty condition list given to a BoolLogicCondition "
74 "constructor.");
75}
76
77
79 conditions_.append(toAdd);
80}
81
84 bool toReturn = (*it)->isConditionTrue();
85 ++it;
86 for(;it != conditions_.end(); ++it){
87 toReturn = applyOperator(toReturn,(*it)->isConditionTrue());
88 }
89 return toReturn;
90}
91
93 for(
95 it!=conditions_.end();
96 ++it)
97 {
98 if((*it)->containsAtLeasteOneParameter()){
99 return true;
100 }
101 }
102 return false;
103}
104
109 for(
111 it != conditions_.end();
112 ++it)
113 {
114 currentList = (*it)->getAllParameters();
115 toReturn.insert(currentList.begin(), currentList.end());
116 }
117 return toReturn;
118}
119
121 BoolLogicCondition(conditions){}
122
123bool OrCondition::applyOperator(bool op1, bool op2) const{
124 return op1 || op2;
125}
126
130 return rcp(new OrCondition(dummyList));
131}
132
134 BoolLogicCondition(conditions){}
135
136bool AndCondition::applyOperator(bool op1, bool op2) const{
137 return op1 && op2;
138}
139
143 return rcp(new AndCondition(dummyList));
144}
145
147 BoolLogicCondition(conditions){}
148
149bool EqualsCondition::applyOperator(bool op1, bool op2) const{
150 return op1 == op2;
151}
152
156 return rcp(new EqualsCondition(dummyList));
157}
158
160 childCondition_(childCondition)
161{
164 "OOOOOOOOPppppps! Looks like you tried "
165 "to give me "
166 "a null pointer when you were making a not conditon. "
167 "That's a no no. Go back and "
168 "checkout your not conditions and make sure you didn't "
169 "give any of them a null pointer "
170 "as an argument to the constructor." << std::endl << std::endl <<
171 "Error: Null pointer given to NotCondition constructor.");
172}
173
175 return (!childCondition_->isConditionTrue());
176}
177
179 return childCondition_->containsAtLeasteOneParameter();
180}
181
183 return childCondition_->getAllParameters();
184}
185
187 return rcp(new NotCondition(
189}
190
193 std::string value):
194 ParameterCondition(parameter),
195 values_(ValueList(1,value))
196{
198}
199
202 ValueList values):
203 ParameterCondition(parameter),
204 values_(values)
205{
207}
208
210 TEUCHOS_TEST_FOR_EXCEPTION(!getParameter()->isType<std::string>(),
212 "The parameter of a String Condition "
213 "must be of type string." << std::endl <<
214 "Expected type: " << TypeNameTraits<std::string>::name() << std::endl <<
215 "Actual type: " << getParameter()->getAny().typeName() <<
216 std::endl << std::endl);
217}
218
219
221 return find(
223 getValue<std::string>(*getParameter())) != values_.end();
224}
225
227 std::string empty = "";
228 return rcp(new StringCondition(rcp(new ParameterEntry(empty)), empty));
229}
230
232 ParameterCondition(parameter)
233{
234 TEUCHOS_TEST_FOR_EXCEPTION(!getParameter()->isType<bool>(),
236 "The parameter of a Bool Condition "
237 "must be of type " << TypeNameTraits<bool>::name() << std::endl <<
238 "Expected type: Bool" << std::endl <<
239 "Actual type: " << getParameter()->getAny().typeName() <<
240 std::endl << std::endl);
241}
242
244 return getValue<bool>(*getParameter());
245}
246
248 return rcp(new BoolCondition(rcp(new ParameterEntry(true))));
249}
250
251
252} //namespace Teuchos
253
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
Replacement for std::vector that is compatible with the Teuchos Memory Management classes.
iterator begin()
size_type size() const
std::vector< T >::const_iterator const_iterator
The type of a const forward 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.
An abstract parent class for all Bool Logic Conditions.
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.
Class for retrieving a dummy object of type T.
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.
RCP< const Condition > childCondition_
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
An Abstract Base class for all ParameterConditions.
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.
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.
void checkParameterType()
Ensures the parameter is the proper type. In this case a string.
Default traits class that just returns typeid(T).name().
#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.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.