Teuchos - Trilinos Tools Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_StandardFunctionObjectXMLConverters.hpp
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 #ifndef TEUCHOS_STANDARDFUNCTIONOBJECTXMLCONVERTERS_HPP
43 #define TEUCHOS_STANDARDFUNCTIONOBJECTXMLCONVERTERS_HPP
44 
51 #include "Teuchos_StandardFunctionObjects.hpp"
52 
53 
54 namespace Teuchos {
55 
56 
58 template<class OperandType>
60 
61 public:
62 
65 
73  getSpecificSimpleFunction(OperandType operand) const = 0;
74 
83  const RCP<const SimpleFunctionObject<OperandType> > /* functionObject */,
84  XMLObject& /* xmlObj */) const{}
85 
87 
90 
93  convertXML(const XMLObject& xmlObj) const;
94 
97  const RCP<const FunctionObject> functionObject,
98  XMLObject& xmlObj) const;
99 
101 
103 
104 
105  static std::string getOperandAttributeName(){
106  static const std::string operandAttributeName = "operand";
107  return operandAttributeName;
108  }
109 
111 
112 };
113 
114 template<class OperandType>
115 RCP<FunctionObject>
117  const XMLObject& xmlObj) const
118 {
119  OperandType operand =
120  xmlObj.getRequired<OperandType>(getOperandAttributeName());
121  return getSpecificSimpleFunction(operand);
122 }
123 
124 template<class OperandType>
126  const RCP<const FunctionObject> functionObject,
127  XMLObject& xmlObj) const
128 {
130  rcp_dynamic_cast<const SimpleFunctionObject<OperandType> >(
131  functionObject, true);
132  OperandType operand = castedFunction->getModifiyingOperand();
133  xmlObj.addAttribute(getOperandAttributeName(),operand);
134  getSpecialSimpleFunctionXMLTraits(castedFunction, xmlObj);
135 }
136 
145 template<class OperandType>
147  public SimpleFunctionXMLConverter<OperandType>
148 {
149 public:
150 
153 
156  getSpecificSimpleFunction(OperandType operand) const;
157 
159 };
160 
161 template<class OperandType>
164  OperandType operand) const
165 {
166  return rcp(new SubtractionFunction<OperandType>(operand));
167 }
168 
177 template<class OperandType>
179  public SimpleFunctionXMLConverter<OperandType>
180 {
181 public:
182 
185 
188  getSpecificSimpleFunction(OperandType operand) const;
189 
191 };
192 
193 template<class OperandType>
196  OperandType operand) const
197 {
198  return rcp(new AdditionFunction<OperandType>(operand));
199 }
200 
209 template<class OperandType>
211  public SimpleFunctionXMLConverter<OperandType>
212 {
213 public:
214 
217 
220  getSpecificSimpleFunction(OperandType operand) const;
221 
223 };
224 
225 template<class OperandType>
228  OperandType operand) const
229 {
230  return rcp(new MultiplicationFunction<OperandType>(operand));
231 }
232 
241 template<class OperandType>
243  public SimpleFunctionXMLConverter<OperandType>
244 {
245 public:
246 
249 
252  getSpecificSimpleFunction(OperandType operand) const;
253 
255 };
256 
257 template<class OperandType>
260  OperandType operand) const
261 {
262  return rcp(new DivisionFunction<OperandType>(operand));
263 }
264 
265 
266 } // namespace Teuchos
267 
268 
269 #endif // TEUCHOS_STANDARDFUNCTIONOBJECTXMLCONVERTERS_HPP
270 
RCP< SimpleFunctionObject< OperandType > > getSpecificSimpleFunction(OperandType operand) const
RCP< SimpleFunctionObject< OperandType > > getSpecificSimpleFunction(OperandType operand) const
RCP< FunctionObject > convertXML(const XMLObject &xmlObj) const
A simple function object that multiplys a specififed value from the given arguement in the runFunctio...
Converts back and forth between XML and FunctionObjects.
A simple function object that adds a specififed value from the given arguement in the runFunction fun...
virtual void getSpecialSimpleFunctionXMLTraits(const RCP< const SimpleFunctionObject< OperandType > >, XMLObject &) const
Add and extra XML traits that are specific to a certain FuncitonOjbect when converting that function ...
Class for converting MultiplicationFunction objects to and from XML.
Class for converting SubtractionFunction objects to and from XML.
A simple function object that subtracts a specififed value from the given arguement in the runFunctio...
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
RCP< SimpleFunctionObject< OperandType > > getSpecificSimpleFunction(OperandType operand) const
Representation of an XML data tree. XMLObject is a ref-counted handle to a XMLObjectImplem object...
Class for converting DivisionFunction objects to and from XML.
Class for converting AdditionFunction objects to and from XML.
void addAttribute(const std::string &name, T value)
Lookup whether or not Doubles are allowed.
virtual RCP< SimpleFunctionObject< OperandType > > getSpecificSimpleFunction(OperandType operand) const =0
Gets the specific SimpleFunction to be returned by this converter when converting from XML...
void convertFunctionObject(const RCP< const FunctionObject > functionObject, XMLObject &xmlObj) const
An abstract base class for converting FunctionObjects to and from XML.
RCP< SimpleFunctionObject< OperandType > > getSpecificSimpleFunction(OperandType operand) const
A simple function object that divides a specififed value from the given arguement in the runFunction ...
Smart reference counting pointer class for automatic garbage collection.
const std::string & getRequired(const std::string &name) const
Get an attribute, throwing an std::exception if it is not found.
A simple function object that applies a given operand to a spcified arguement using a specific operat...