Teuchos - Trilinos Tools Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_StandardFunctionObjects.hpp
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 #ifndef Teuchos_STANDARD_FUNCTION_OBJECTS_H
43 #define Teuchos_STANDARD_FUNCTION_OBJECTS_H
44 
50 
51 
52 namespace Teuchos{
53 
58 template<class OperandType>
60 {
61 public:
62 
64 
65 
71  FunctionObject(){}
72 
79  SimpleFunctionObject(OperandType modifyingOperand):
81  _modifyingOperand(modifyingOperand){}
82 
84 
92  virtual OperandType runFunction(OperandType arguement) const=0;
93 
95 
96 
100  inline OperandType getModifiyingOperand() const{
101  return _modifyingOperand;
102  }
103 
110  inline OperandType setModifyingOperand(OperandType newOperand){
111  _modifyingOperand = newOperand;
112  }
113 
115 
116 private:
118 
119 
123  OperandType _modifyingOperand;
124 
126 };
127 
136 template<class OperandType>
138  public SimpleFunctionObject<OperandType>
139 {
140 public:
142 
143 
148 
155  SubtractionFunction(OperandType amountToSubtract):
156  SimpleFunctionObject<OperandType>(amountToSubtract){}
157 
159 
161 
162 
164  OperandType runFunction(OperandType arguement) const{
165  return
166  arguement
167  -
169  }
170 
172 
174 
175 
177  std::string getTypeAttributeValue() const{
178  return
179  "SubtractionFunction("
181  +")";
182  }
183 
185 };
186 
195 template<class OperandType>
197  public SimpleFunctionObject<OperandType>
198 {
199 public:
201 
202 
207 
214  AdditionFunction(OperandType amountToAdd):
215  SimpleFunctionObject<OperandType>(amountToAdd){}
216 
218 
220 
221 
223  OperandType runFunction(OperandType arguement) const{
224  return
225  arguement
226  +
228  }
229 
231 
233 
234 
236  std::string getTypeAttributeValue() const{
237  return
238  "AdditionFunction("
240  +")";
241  }
242 
244 };
245 
254 template<class OperandType>
256  public SimpleFunctionObject<OperandType>
257 {
258 public:
260 
261 
267 
275  MultiplicationFunction(OperandType amountToMultiplyBy):
276  SimpleFunctionObject<OperandType>(amountToMultiplyBy){}
277 
279 
281 
282 
284  OperandType runFunction(OperandType arguement) const{
285  return
286  arguement
287  *
289  }
290 
292 
294 
295 
297  std::string getTypeAttributeValue() const{
298  return "MultiplicationFunction(" +
300  +")";
301  }
302 
304 };
305 
314 template<class OperandType>
316  public SimpleFunctionObject<OperandType>
317 {
318 public:
319 
321 
322 
328 
336  DivisionFunction(OperandType amountToDivideBy):
337  SimpleFunctionObject<OperandType>(amountToDivideBy){}
338 
340 
342 
343 
345  OperandType runFunction(OperandType arguement) const{
346  return
347  arguement
348  /
350  }
351 
353 
355 
356 
358  std::string getTypeAttributeValue() const{
359  return
360  "DivisionFunction("
362  +")";
363  }
364 
366 
367 };
368 
369 } // namespace Teuchos
370 
371 
372 #endif
A simple function object that multiplys a specififed value from the given arguement in the runFunctio...
SimpleFunctionObject()
Constructs a SimpleFunctionObject.
A simple function object that adds a specififed value from the given arguement in the runFunction fun...
OperandType setModifyingOperand(OperandType newOperand)
Sets the modifyingOperand.
SubtractionFunction(OperandType amountToSubtract)
Constructs a SubtractionFunction.
virtual OperandType runFunction(OperandType arguement) const =0
MultiplicationFunction(OperandType amountToMultiplyBy)
Constructs a MultiplicationFunction.
OperandType runFunction(OperandType arguement) const
An object representation of a function.
A simple function object that subtracts a specififed value from the given arguement in the runFunctio...
OperandType runFunction(OperandType arguement) const
SubtractionFunction()
Constructs a SubtractionFunction.
AdditionFunction()
Constructs a AdditionFunction.
OperandType runFunction(OperandType arguement) const
OperandType getModifiyingOperand() const
Returns the modifying operand.
A simple function object that divides a specififed value from the given arguement in the runFunction ...
DivisionFunction()
Constructs a DivisionFunction.
AdditionFunction(OperandType amountToAdd)
Constructs a AdditionFunction.
A function object represents an arbitrary function.
MultiplicationFunction()
Constructs a MultiplicationFunction.
OperandType runFunction(OperandType arguement) const
SimpleFunctionObject(OperandType modifyingOperand)
Constructs a SimpleFunctionObject.
DivisionFunction(OperandType amountToDivideBy)
Constructs a DivisionFunction.
A simple function object that applies a given operand to a spcified arguement using a specific operat...