Teuchos - Trilinos Tools Package
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
parameterlist
src
Teuchos_FunctionObjectXMLConverterDB.cpp
1
// @HEADER
2
// *****************************************************************************
3
// Teuchos: Common Tools Package
4
//
5
// Copyright 2004 NTESS and the Teuchos contributors.
6
// SPDX-License-Identifier: BSD-3-Clause
7
// *****************************************************************************
8
// @HEADER
9
10
#include "
Teuchos_FunctionObjectXMLConverterDB.hpp
"
11
#include "Teuchos_StaticSetupMacro.hpp"
12
#include "
Teuchos_XMLFunctionObjectExceptions.hpp
"
13
14
15
16
namespace
Teuchos
{
17
18
19
void
FunctionObjectXMLConverterDB::addConverter
(
20
RCP<const FunctionObject>
function,
21
RCP<FunctionObjectXMLConverter>
converterToAdd){
22
getConverterMap().insert(
23
ConverterPair(function->getTypeAttributeValue(), converterToAdd));
24
}
25
26
27
RCP<const FunctionObjectXMLConverter>
28
FunctionObjectXMLConverterDB::getConverter
(
const
FunctionObject
& function){
29
ConverterMap::const_iterator it =
30
getConverterMap().find(function.
getTypeAttributeValue
());
31
TEUCHOS_TEST_FOR_EXCEPTION
(it == getConverterMap().end(),
32
CantFindFunctionObjectConverterException
,
33
"Could not find a FunctionObjectXMLConverter for a FuncitonObject of type "
<<
34
function.
getTypeAttributeValue
() <<
" when writing out a condition to "
<<
35
"xml."
<< std::endl << std::endl
36
)
37
return
it->second;
38
}
39
40
41
RCP<const FunctionObjectXMLConverter>
42
FunctionObjectXMLConverterDB::getConverter
(
const
XMLObject
& xmlObject)
43
{
44
std::string functionType = xmlObject.
getRequired
(
45
FunctionObjectXMLConverter::getTypeAttributeName
());
46
ConverterMap::const_iterator it = getConverterMap().find(functionType);
47
TEUCHOS_TEST_FOR_EXCEPTION
(it == getConverterMap().end(),
48
CantFindFunctionObjectConverterException
,
49
"Could not find a FunctionObjectXMLConverter for a condition of type "
<<
50
functionType <<
" when reading in a condition from "
<<
51
"xml."
<< std::endl << std::endl
52
)
53
return
it->second;
54
}
55
56
XMLObject
FunctionObjectXMLConverterDB::convertFunctionObject
(
57
RCP<const FunctionObject>
function)
58
{
59
return
getConverter
(*function)->fromFunctionObjecttoXML(function);
60
}
61
62
RCP<FunctionObject>
FunctionObjectXMLConverterDB::convertXML
(
63
const
XMLObject
& xmlObject)
64
{
65
return
FunctionObjectXMLConverterDB::getConverter
(xmlObject)->
66
fromXMLtoFunctionObject(xmlObject);
67
}
68
69
FunctionObjectXMLConverterDB::ConverterMap&
70
FunctionObjectXMLConverterDB::getConverterMap()
71
{
72
static
ConverterMap masterMap;
73
return
masterMap;
74
}
75
76
77
}
// namespace Teuchos
78
79
80
namespace
{
81
82
83
TEUCHOS_STATIC_SETUP()
84
{
85
86
TEUCHOS_ADD_SIMPLEFUNCTIONCONVERTERS
(
int
);
87
TEUCHOS_ADD_SIMPLEFUNCTIONCONVERTERS
(
unsigned
int
);
88
TEUCHOS_ADD_SIMPLEFUNCTIONCONVERTERS
(
short
int
);
89
TEUCHOS_ADD_SIMPLEFUNCTIONCONVERTERS
(
unsigned
short
int
);
90
TEUCHOS_ADD_SIMPLEFUNCTIONCONVERTERS
(
long
int
);
91
TEUCHOS_ADD_SIMPLEFUNCTIONCONVERTERS
(
unsigned
long
int
);
92
TEUCHOS_ADD_SIMPLEFUNCTIONCONVERTERS
(
double
);
93
TEUCHOS_ADD_SIMPLEFUNCTIONCONVERTERS
(
float
);
94
95
TEUCHOS_ADD_SIMPLEFUNCTIONCONVERTERS
(
long
long
int
);
96
TEUCHOS_ADD_SIMPLEFUNCTIONCONVERTERS
(
unsigned
long
long
int
);
97
98
}
99
100
101
}
// namespace
Teuchos_FunctionObjectXMLConverterDB.hpp
A database for FunctionObjectXMLConverters.
TEUCHOS_ADD_SIMPLEFUNCTIONCONVERTERS
#define TEUCHOS_ADD_SIMPLEFUNCTIONCONVERTERS(T)
Adds a SubtractionFunction, AdditionFunction, MultiplicationFunction, and DivisionFunction of type T ...
Definition
Teuchos_FunctionObjectXMLConverterDB.hpp:141
Teuchos_XMLFunctionObjectExceptions.hpp
A collection of Exceptions thrown when converting FunctionObjects to and from XML.
Teuchos::CantFindFunctionObjectConverterException
Thrown when an appropriate FunctionObject Converter can't be found.
Definition
Teuchos_XMLFunctionObjectExceptions.hpp:23
Teuchos::FunctionObject
A function object represents an arbitrary function.
Definition
Teuchos_FunctionObject.hpp:27
Teuchos::FunctionObject::getTypeAttributeValue
virtual std::string getTypeAttributeValue() const =0
Returns the string to be used for the value of the type attribute when converting the function to XML...
Teuchos::FunctionObjectXMLConverterDB::getConverter
static RCP< const FunctionObjectXMLConverter > getConverter(const FunctionObject &function)
Get an appropriate FunctionObjectXMLConverter given a FunctionObject.
Definition
Teuchos_FunctionObjectXMLConverterDB.cpp:28
Teuchos::FunctionObjectXMLConverterDB::addConverter
static void addConverter(RCP< const FunctionObject > function, RCP< FunctionObjectXMLConverter > converterToAdd)
Add a converter to the database.
Definition
Teuchos_FunctionObjectXMLConverterDB.cpp:19
Teuchos::FunctionObjectXMLConverterDB::convertFunctionObject
static XMLObject convertFunctionObject(RCP< const FunctionObject > function)
Given a FunctionObject, converts the FunctionObject to XML.
Definition
Teuchos_FunctionObjectXMLConverterDB.cpp:56
Teuchos::FunctionObjectXMLConverterDB::convertXML
static RCP< FunctionObject > convertXML(const XMLObject &xmlObject)
Given an XMLObject, converts the XMLObject to a FunctionObject.
Definition
Teuchos_FunctionObjectXMLConverterDB.cpp:62
Teuchos::FunctionObjectXMLConverter::getTypeAttributeName
static const std::string & getTypeAttributeName()
Definition
Teuchos_FunctionObjectXMLConverter.hpp:79
Teuchos::RCP
Smart reference counting pointer class for automatic garbage collection.
Definition
Teuchos_RCPDecl.hpp:397
Teuchos::XMLObject
Representation of an XML data tree. XMLObject is a ref-counted handle to a XMLObjectImplem object,...
Definition
Teuchos_XMLObject.hpp:30
Teuchos::XMLObject::getRequired
const std::string & getRequired(const std::string &name) const
Get an attribute, throwing an std::exception if it is not found.
Definition
Teuchos_XMLObject.cpp:61
TEUCHOS_TEST_FOR_EXCEPTION
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
Definition
Teuchos_TestForException.hpp:146
Teuchos
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...
Generated by
1.17.0