Teuchos - Trilinos Tools Package Version of the Day
Teuchos_StandardFunctionObjects.hpp
00001 // @HEADER
00002 // ***********************************************************************
00003 //
00004 //                    Teuchos: Common Tools Package
00005 //                 Copyright (2004) Sandia Corporation
00006 //
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00038 //
00039 // ***********************************************************************
00040 // @HEADER
00041 
00042 #ifndef Teuchos_STANDARD_FUNCTION_OBJECTS_H
00043 #define Teuchos_STANDARD_FUNCTION_OBJECTS_H
00044 
00049 #include "Teuchos_FunctionObject.hpp"
00050 
00051 
00052 namespace Teuchos{
00053 
00058 template<class OperandType>
00059 class SimpleFunctionObject : public FunctionObject
00060 {
00061 public:
00062 
00064 
00065 
00070   SimpleFunctionObject():
00071     FunctionObject(){}
00072   
00079   SimpleFunctionObject(OperandType modifyingOperand):
00080     FunctionObject(),
00081     _modifyingOperand(modifyingOperand){}
00082 
00084 
00092   virtual OperandType runFunction(OperandType arguement) const=0;
00093 
00095 
00096 
00100   inline OperandType getModifiyingOperand() const{
00101     return _modifyingOperand;
00102   }
00103 
00110   inline OperandType setModifyingOperand(OperandType newOperand){
00111     _modifyingOperand = newOperand;
00112   }
00113 
00115 
00116 private:
00118 
00119 
00123   OperandType _modifyingOperand;
00124   
00126 };
00127 
00136 template<class OperandType>
00137 class SubtractionFunction :
00138   public SimpleFunctionObject<OperandType>
00139 {
00140 public:
00142 
00143   
00147   SubtractionFunction():SimpleFunctionObject<OperandType>(){}
00148 
00155   SubtractionFunction(OperandType amountToSubtract):
00156     SimpleFunctionObject<OperandType>(amountToSubtract){}
00157   
00159 
00161 
00162 
00164   OperandType runFunction(OperandType arguement) const{
00165     return 
00166       arguement
00167       -
00168       SimpleFunctionObject<OperandType>::getModifiyingOperand();
00169   }
00170 
00172   
00174 
00175 
00177   std::string getTypeAttributeValue() const{
00178     return 
00179       "SubtractionFunction(" 
00180       + TypeNameTraits<OperandType>::name()
00181       +")";
00182   }
00183 
00185 };
00186 
00195 template<class OperandType>
00196 class AdditionFunction :
00197   public SimpleFunctionObject<OperandType>
00198 {
00199 public:
00201 
00202 
00206   AdditionFunction():SimpleFunctionObject<OperandType>(){}
00207 
00214   AdditionFunction(OperandType amountToAdd):
00215     SimpleFunctionObject<OperandType>(amountToAdd){}
00216 
00218 
00220 
00221 
00223   OperandType runFunction(OperandType arguement) const{
00224     return 
00225       arguement
00226       +
00227       SimpleFunctionObject<OperandType>::getModifiyingOperand();
00228   }
00229 
00231   
00233 
00234 
00236   std::string getTypeAttributeValue() const{
00237     return 
00238       "AdditionFunction("
00239       + TypeNameTraits<OperandType>::name()
00240       +")";
00241   }
00242   
00244 };
00245 
00254 template<class OperandType>
00255 class MultiplicationFunction :
00256   public SimpleFunctionObject<OperandType>
00257 {
00258 public:
00260 
00261 
00266   MultiplicationFunction():SimpleFunctionObject<OperandType>(){}
00267 
00275   MultiplicationFunction(OperandType amountToMultiplyBy):
00276     SimpleFunctionObject<OperandType>(amountToMultiplyBy){}
00277 
00279   
00281 
00282 
00284   OperandType runFunction(OperandType arguement) const{
00285     return 
00286       arguement
00287       *
00288       SimpleFunctionObject<OperandType>::getModifiyingOperand();
00289   }
00290 
00292   
00294 
00295 
00297   std::string getTypeAttributeValue() const{
00298     return "MultiplicationFunction(" + 
00299       TypeNameTraits<OperandType>::name()
00300       +")";
00301   }
00302 
00304 };
00305 
00314 template<class OperandType>
00315 class DivisionFunction :
00316   public SimpleFunctionObject<OperandType>
00317 {
00318 public:
00319 
00321 
00322  
00327   DivisionFunction():SimpleFunctionObject<OperandType>(){}
00328 
00336   DivisionFunction(OperandType amountToDivideBy):
00337     SimpleFunctionObject<OperandType>(amountToDivideBy){}
00338 
00340   
00342 
00343 
00345   OperandType runFunction(OperandType arguement) const{
00346     return 
00347       arguement
00348       /
00349       SimpleFunctionObject<OperandType>::getModifiyingOperand();
00350   }
00351 
00353   
00355 
00356 
00358   std::string getTypeAttributeValue() const{
00359     return 
00360       "DivisionFunction(" 
00361       + TypeNameTraits<OperandType>::name()
00362       +")";
00363   }
00364 
00366   
00367 };
00368 
00369 } // namespace Teuchos
00370 
00371 
00372 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines