|
Teuchos Package Browser (Single Doxygen Collection)
Version of the Day
|
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_STANDARDFUNCTIONOBJECTXMLCONVERTERS_HPP 00043 #define TEUCHOS_STANDARDFUNCTIONOBJECTXMLCONVERTERS_HPP 00044 00050 #include "Teuchos_FunctionObjectXMLConverter.hpp" 00051 #include "Teuchos_StandardFunctionObjects.hpp" 00052 00053 00054 namespace Teuchos { 00055 00056 00058 template<class OperandType> 00059 class SimpleFunctionXMLConverter : public FunctionObjectXMLConverter{ 00060 00061 public: 00062 00065 00072 virtual RCP<SimpleFunctionObject<OperandType> > 00073 getSpecificSimpleFunction(OperandType operand) const = 0; 00074 00082 virtual void getSpecialSimpleFunctionXMLTraits( 00083 const RCP<const SimpleFunctionObject<OperandType> > functionObject, 00084 XMLObject& xmlObj) const{} 00085 00087 00090 00092 RCP<FunctionObject> 00093 convertXML(const XMLObject& xmlObj) const; 00094 00096 void convertFunctionObject( 00097 const RCP<const FunctionObject> functionObject, 00098 XMLObject& xmlObj) const; 00099 00101 00103 00104 00105 static std::string getOperandAttributeName(){ 00106 static const std::string operandAttributeName = "operand"; 00107 return operandAttributeName; 00108 } 00109 00111 00112 }; 00113 00114 template<class OperandType> 00115 RCP<FunctionObject> 00116 SimpleFunctionXMLConverter<OperandType>::convertXML( 00117 const XMLObject& xmlObj) const 00118 { 00119 OperandType operand = 00120 xmlObj.getRequired<OperandType>(getOperandAttributeName()); 00121 return getSpecificSimpleFunction(operand); 00122 } 00123 00124 template<class OperandType> 00125 void SimpleFunctionXMLConverter<OperandType>::convertFunctionObject( 00126 const RCP<const FunctionObject> functionObject, 00127 XMLObject& xmlObj) const 00128 { 00129 RCP<const SimpleFunctionObject<OperandType> > castedFunction = 00130 rcp_dynamic_cast<const SimpleFunctionObject<OperandType> >( 00131 functionObject, true); 00132 OperandType operand = castedFunction->getModifiyingOperand(); 00133 xmlObj.addAttribute(getOperandAttributeName(),operand); 00134 getSpecialSimpleFunctionXMLTraits(castedFunction, xmlObj); 00135 } 00136 00145 template<class OperandType> 00146 class SubtractionFunctionXMLConverter : 00147 public SimpleFunctionXMLConverter<OperandType> 00148 { 00149 public: 00150 00153 00155 RCP<SimpleFunctionObject<OperandType> > 00156 getSpecificSimpleFunction(OperandType operand) const; 00157 00159 }; 00160 00161 template<class OperandType> 00162 RCP<SimpleFunctionObject<OperandType> > 00163 SubtractionFunctionXMLConverter<OperandType>::getSpecificSimpleFunction( 00164 OperandType operand) const 00165 { 00166 return rcp(new SubtractionFunction<OperandType>(operand)); 00167 } 00168 00177 template<class OperandType> 00178 class AdditionFunctionXMLConverter : 00179 public SimpleFunctionXMLConverter<OperandType> 00180 { 00181 public: 00182 00185 00187 RCP<SimpleFunctionObject<OperandType> > 00188 getSpecificSimpleFunction(OperandType operand) const; 00189 00191 }; 00192 00193 template<class OperandType> 00194 RCP<SimpleFunctionObject<OperandType> > 00195 AdditionFunctionXMLConverter<OperandType>::getSpecificSimpleFunction( 00196 OperandType operand) const 00197 { 00198 return rcp(new AdditionFunction<OperandType>(operand)); 00199 } 00200 00209 template<class OperandType> 00210 class MultiplicationFunctionXMLConverter : 00211 public SimpleFunctionXMLConverter<OperandType> 00212 { 00213 public: 00214 00217 00219 RCP<SimpleFunctionObject<OperandType> > 00220 getSpecificSimpleFunction(OperandType operand) const; 00221 00223 }; 00224 00225 template<class OperandType> 00226 RCP<SimpleFunctionObject<OperandType> > 00227 MultiplicationFunctionXMLConverter<OperandType>::getSpecificSimpleFunction( 00228 OperandType operand) const 00229 { 00230 return rcp(new MultiplicationFunction<OperandType>(operand)); 00231 } 00232 00241 template<class OperandType> 00242 class DivisionFunctionXMLConverter : 00243 public SimpleFunctionXMLConverter<OperandType> 00244 { 00245 public: 00246 00249 00251 RCP<SimpleFunctionObject<OperandType> > 00252 getSpecificSimpleFunction(OperandType operand) const; 00253 00255 }; 00256 00257 template<class OperandType> 00258 RCP<SimpleFunctionObject<OperandType> > 00259 DivisionFunctionXMLConverter<OperandType>::getSpecificSimpleFunction( 00260 OperandType operand) const 00261 { 00262 return rcp(new DivisionFunction<OperandType>(operand)); 00263 } 00264 00265 00266 } // namespace Teuchos 00267 00268 00269 #endif // TEUCHOS_STANDARDFUNCTIONOBJECTXMLCONVERTERS_HPP 00270
1.7.6.1