Teuchos - Trilinos Tools Package Version of the Day
Loading...
Searching...
No Matches
Teuchos_ConditionXMLConverterDB.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
12#include "Teuchos_StaticSetupMacro.hpp"
13
14
15
16namespace Teuchos {
17
18
20 RCP<const Condition> condition,
21 RCP<ConditionXMLConverter> converterToAdd){
22 getConverterMap().insert(
23 ConverterPair(condition->getTypeAttributeValue(), converterToAdd));
24}
25
26
29 ConverterMap::const_iterator it =
30 getConverterMap().find(condition.getTypeAttributeValue());
31 TEUCHOS_TEST_FOR_EXCEPTION(it == getConverterMap().end(),
33 "Could not find a ConditionXMLConverter for a condition of type " <<
34 condition.getTypeAttributeValue() << " when writing out a condition to " <<
35 "xml." << std::endl << std::endl
36 )
37 return it->second;
38}
39
40
43{
44 std::string conditionType = xmlObject.getRequired(
46 ConverterMap::const_iterator it = getConverterMap().find(conditionType);
47 TEUCHOS_TEST_FOR_EXCEPTION(it == getConverterMap().end(),
49 "Could not find a ConditionXMLConverter for a condition of type " <<
50 conditionType << " when reading in a condition from " <<
51 "xml." << std::endl << std::endl
52 )
53 return it->second;
54}
55
57 RCP<const Condition> condition,
58 const XMLParameterListWriter::EntryIDsMap& entryIDsMap)
59{
60 return getConverter(*condition)->fromConditiontoXML(condition, entryIDsMap);
61}
62
64 const XMLObject& xmlObject,
65 const XMLParameterListReader::EntryIDsMap& entryIDsMap)
66{
68 fromXMLtoCondition(xmlObject, entryIDsMap);
69}
70
71ConditionXMLConverterDB::ConverterMap&
72ConditionXMLConverterDB::getConverterMap()
73{
74 static ConverterMap masterMap;
75 return masterMap;
76}
77
78
79} // namespace Teuchos
80
81
82namespace {
83
84
85TEUCHOS_STATIC_SETUP()
86{
90 TEUCHOS_ADD_NUMBERCONDITION_CONVERTER(unsigned short int);
95
97 TEUCHOS_ADD_NUMBERCONDITION_CONVERTER(unsigned long long int);
98
101 getDummyObject(),
103
106 getDummyObject(),
108
111 getDummyObject(),
113
116 getDummyObject(),
118
121 getDummyObject(),
123
126 getDummyObject(),
128}
129
130
131} // namespace
A database for ConditionXMLConverters.
#define TEUCHOS_ADD_NUMBERCONDITION_CONVERTER(T)
Adds a NumberCondition of type T.
A collection of Exceptions thrown when converting Conditions to and from XML.
Thrown when an appropriate Condition Converter can't be found.
static RCP< const ConditionXMLConverter > getConverter(const Condition &condition)
Get an appropriate ConditionXMLConverter given a Condition.
static RCP< Condition > convertXML(const XMLObject &xmlObject, const XMLParameterListReader::EntryIDsMap &entryIDsMap)
Given an XMLObject and IDtoConditionMap, converts the XMLObject to a Condition.
static void addConverter(RCP< const Condition > condition, RCP< ConditionXMLConverter > converterToAdd)
Add a converter to the database.
static XMLObject convertCondition(RCP< const Condition > condition, const XMLParameterListWriter::EntryIDsMap &entryIDsMap)
Given a condition and ConditiontoIDMap, converts the condition to XML.
static const std::string & getTypeAttributeName()
Returns the string to be used for the type attribute.
A Condition determines whether or not a particular set of conditions are currently occuring.
virtual std::string getTypeAttributeValue() const =0
Get the value that should be used for the condition type attribute when converting a condition to XML...
Class for retrieving a dummy object of type T.
Smart reference counting pointer class for automatic garbage collection.
An xml converter for StringConditions The valid XML represntation for a StringCondition is:
Representation of an XML data tree. XMLObject is a ref-counted handle to a XMLObjectImplem object,...
const std::string & getRequired(const std::string &name) const
Get an attribute, throwing an std::exception if it is not found.
std::map< ParameterEntry::ParameterEntryID, RCP< ParameterEntry > > EntryIDsMap
Convenience typedef.
std::map< RCP< const ParameterEntry >, ParameterEntry::ParameterEntryID, RCPConstComp > EntryIDsMap
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.