Teuchos Package Browser (Single Doxygen Collection)
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
parameterlist
src
Teuchos_ParameterEntryXMLConverterDB.cpp
Go to the documentation of this file.
1
2
// @HEADER
3
// ***********************************************************************
4
//
5
// Teuchos: Common Tools Package
6
// Copyright (2004) Sandia Corporation
7
//
8
// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
9
// license for use of this work by or on behalf of the U.S. Government.
10
//
11
// Redistribution and use in source and binary forms, with or without
12
// modification, are permitted provided that the following conditions are
13
// met:
14
//
15
// 1. Redistributions of source code must retain the above copyright
16
// notice, this list of conditions and the following disclaimer.
17
//
18
// 2. Redistributions in binary form must reproduce the above copyright
19
// notice, this list of conditions and the following disclaimer in the
20
// documentation and/or other materials provided with the distribution.
21
//
22
// 3. Neither the name of the Corporation nor the names of the
23
// contributors may be used to endorse or promote products derived from
24
// this software without specific prior written permission.
25
//
26
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37
//
38
// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
39
//
40
// ***********************************************************************
41
// @HEADER
42
43
#include "
Teuchos_ParameterEntryXMLConverterDB.hpp
"
44
#include "
Teuchos_XMLParameterListWriter.hpp
"
45
#include "
Teuchos_StaticSetupMacro.hpp
"
46
#include "
Teuchos_TwoDArray.hpp
"
47
48
namespace
Teuchos
{
49
50
51
RCP<const ParameterEntryXMLConverter>
52
ParameterEntryXMLConverterDB::getConverter
(
RCP<const ParameterEntry>
entry)
53
{
54
ConverterMap::const_iterator it =
55
getConverterMap
().find(entry->getAny().typeName());
56
if
(it ==
getConverterMap
().end()){
57
return
getDefaultConverter
();
58
}
59
else
{
60
return
it->second;
61
}
62
}
63
64
RCP<const ParameterEntryXMLConverter>
65
ParameterEntryXMLConverterDB::getConverter
(
const
XMLObject
& xmlObject)
66
{
67
TEUCHOS_TEST_FOR_EXCEPTION
(
68
!xmlObject.
hasAttribute
(
ParameterEntryXMLConverter::getTypeAttributeName
()),
69
NoTypeAttributeExecption
,
70
ParameterEntry::getTagName
() <<
" tags must "
71
"have a "
<<
ParameterEntryXMLConverter::getTypeAttributeName
() <<
72
" attribute."
<< std::endl <<
73
"Bad Parameter: "
<<
74
xmlObject.
getAttribute
(
XMLParameterListWriter::getNameAttributeName
()) <<
75
std::endl << std::endl);
76
77
std::string parameterType = xmlObject.
getRequired
(
78
ParameterEntryXMLConverter::getTypeAttributeName
());
79
ConverterMap::const_iterator it =
getConverterMap
().find(parameterType);
80
81
TEUCHOS_TEST_FOR_EXCEPTION
(it ==
getConverterMap
().end(),
82
CantFindParameterEntryConverterException
,
83
"Can't find converter for parameter entry of type: "
<<
84
xmlObject.
getRequired
(
ParameterEntryXMLConverter::getTypeAttributeName
()) <<
85
std::endl << std::endl);
86
87
return
it->second;
88
}
89
90
void
ParameterEntryXMLConverterDB::printKnownConverters
(std::ostream& out){
91
out <<
"Known ParameterEntryXMLConverters: "
<< std::endl;
92
for
(
93
ConverterMap::const_iterator it =
getConverterMap
().begin();
94
it !=
getConverterMap
().end();
95
++it)
96
{
97
out <<
"\t"
<< it->first <<std::endl;
98
}
99
}
100
101
RCP<const ParameterEntryXMLConverter>
102
ParameterEntryXMLConverterDB::getDefaultConverter
()
103
{
104
static
RCP<const AnyParameterEntryConverter>
defaultConverter;
105
if
(defaultConverter.
is_null
()){
106
defaultConverter =
rcp
(
new
AnyParameterEntryConverter
);
107
}
108
return
defaultConverter;
109
}
110
111
ParameterEntryXMLConverterDB::ConverterMap
&
112
ParameterEntryXMLConverterDB::getConverterMap
()
113
{
114
static
ConverterMap
masterMap;
115
return
masterMap;
116
117
}
118
119
120
}
//namespace Teuchos
121
122
123
namespace
{
124
125
TEUCHOS_STATIC_SETUP
()
126
{
127
typedef
unsigned
int
uint;
128
typedef
unsigned
short
int
ushort;
129
typedef
unsigned
long
ulong;
130
TEUCHOS_ADD_TYPE_AND_ARRAYTYPE_CONVERTER
(
int
);
131
TEUCHOS_ADD_TYPE_AND_ARRAYTYPE_CONVERTER
(uint);
132
TEUCHOS_ADD_TYPE_AND_ARRAYTYPE_CONVERTER
(
short
);
133
TEUCHOS_ADD_TYPE_AND_ARRAYTYPE_CONVERTER
(ushort);
134
TEUCHOS_ADD_TYPE_AND_ARRAYTYPE_CONVERTER
(
long
);
135
TEUCHOS_ADD_TYPE_AND_ARRAYTYPE_CONVERTER
(ulong);
136
typedef
long
long
int
llint;
137
typedef
unsigned
long
long
int
ullint;
138
TEUCHOS_ADD_TYPE_AND_ARRAYTYPE_CONVERTER
(llint);
139
TEUCHOS_ADD_TYPE_AND_ARRAYTYPE_CONVERTER
(ullint);
140
TEUCHOS_ADD_TYPE_AND_ARRAYTYPE_CONVERTER
(
double
);
141
TEUCHOS_ADD_TYPE_AND_ARRAYTYPE_CONVERTER
(
float
);
142
143
typedef
std::string myString;
144
TEUCHOS_ADD_TYPE_AND_ARRAYTYPE_CONVERTER
(myString);
145
146
TEUCHOS_ADD_TYPE_CONVERTER
(
char
);
147
TEUCHOS_ADD_TYPE_CONVERTER
(
bool
);
148
149
Teuchos::ParameterEntryXMLConverterDB::addConverter
(
150
Teuchos::rcp
(
new
Teuchos::AnyParameterEntryConverter
));
151
}
152
153
154
}
// namespace
Teuchos_ParameterEntryXMLConverterDB.hpp
TEUCHOS_ADD_TYPE_CONVERTER
#define TEUCHOS_ADD_TYPE_CONVERTER(T)
Definition
Teuchos_ParameterEntryXMLConverterDB.hpp:172
TEUCHOS_ADD_TYPE_AND_ARRAYTYPE_CONVERTER
#define TEUCHOS_ADD_TYPE_AND_ARRAYTYPE_CONVERTER(T)
Definition
Teuchos_ParameterEntryXMLConverterDB.hpp:189
Teuchos_StaticSetupMacro.hpp
TEUCHOS_STATIC_SETUP
#define TEUCHOS_STATIC_SETUP()
Run setup code statically in a translation unit.
Definition
Teuchos_StaticSetupMacro.hpp:68
Teuchos_TwoDArray.hpp
A thin wrapper around the Teuchos Array class that allows for 2 dimensional arrays.
Teuchos_XMLParameterListWriter.hpp
Writes a ParameterList to an XML object.
Teuchos::AnyParameterEntryConverter
A last resort converter for when no others will do.
Definition
Teuchos_StandardParameterEntryXMLConverters.hpp:61
Teuchos::CantFindParameterEntryConverterException
Thrown when an appropriate ParameterEntryXMLConverter can't be found.
Definition
Teuchos_XMLParameterListExceptions.hpp:58
Teuchos::NoTypeAttributeExecption
Thrown when a parameter entry tag is missing it's type attribute.
Definition
Teuchos_XMLParameterListExceptions.hpp:174
Teuchos::ParameterEntryXMLConverterDB::ConverterMap
std::map< std::string, RCP< ParameterEntryXMLConverter > > ConverterMap
convience typedef
Definition
Teuchos_ParameterEntryXMLConverterDB.hpp:148
Teuchos::ParameterEntryXMLConverterDB::getDefaultConverter
static RCP< const ParameterEntryXMLConverter > getDefaultConverter()
Gets the default converter to be used on Parameter Entries.
Definition
Teuchos_ParameterEntryXMLConverterDB.cpp:102
Teuchos::ParameterEntryXMLConverterDB::getConverterMap
static ConverterMap & getConverterMap()
Gets the map containing all the ParameterEntry converters.
Definition
Teuchos_ParameterEntryXMLConverterDB.cpp:112
Teuchos::ParameterEntryXMLConverterDB::addConverter
static void addConverter(RCP< ParameterEntryXMLConverter > converterToAdd)
Add a converter to the database.
Definition
Teuchos_ParameterEntryXMLConverterDB.hpp:70
Teuchos::ParameterEntryXMLConverterDB::printKnownConverters
static void printKnownConverters(std::ostream &out)
prints the xml tags associated with all known converters
Definition
Teuchos_ParameterEntryXMLConverterDB.cpp:90
Teuchos::ParameterEntryXMLConverterDB::getConverter
static RCP< const ParameterEntryXMLConverter > getConverter(RCP< const ParameterEntry > entry)
Get an appropriate ParameterEntryXMLConverter given a ParameterEntry.
Definition
Teuchos_ParameterEntryXMLConverterDB.cpp:52
Teuchos::ParameterEntryXMLConverter::getTypeAttributeName
static const std::string & getTypeAttributeName()
Definition
Teuchos_ParameterEntryXMLConverter.hpp:114
Teuchos::ParameterEntry::getTagName
static const std::string & getTagName()
Get the string that should be used as the tag name for all parameters when they are serialized to xml...
Definition
Teuchos_ParameterEntry.hpp:226
Teuchos::RCP
Smart reference counting pointer class for automatic garbage collection.
Definition
Teuchos_RCPDecl.hpp:429
Teuchos::RCP::is_null
bool is_null() const
Returns true if the underlying pointer is null.
Definition
Teuchos_RCP.hpp:370
Teuchos::XMLObject
Representation of an XML data tree. XMLObject is a ref-counted handle to a XMLObjectImplem object,...
Definition
Teuchos_XMLObject.hpp:62
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:93
Teuchos::XMLObject::getAttribute
const std::string & getAttribute(const std::string &name) const
Return the value of the attribute with the specified name.
Definition
Teuchos_XMLObject.cpp:85
Teuchos::XMLObject::hasAttribute
bool hasAttribute(const std::string &name) const
Find out if the current node has an attribute of the specified name.
Definition
Teuchos_XMLObject.cpp:77
Teuchos::XMLParameterListWriter::getNameAttributeName
static const std::string & getNameAttributeName()
Definition
Teuchos_XMLParameterListWriter.hpp:95
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:178
Teuchos
Definition
Teuchos_AbstractFactory.hpp:47
Teuchos::rcp
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
Definition
Teuchos_RCPDecl.hpp:1266
Generated by
1.17.0