Teuchos - Trilinos Tools Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_ConditionXMLConverterDB.cpp
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 
44 #include "Teuchos_StaticSetupMacro.hpp"
45 
46 
47 
48 namespace Teuchos {
49 
50 
52  RCP<const Condition> condition,
53  RCP<ConditionXMLConverter> converterToAdd){
54  getConverterMap().insert(
55  ConverterPair(condition->getTypeAttributeValue(), converterToAdd));
56 }
57 
58 
61  ConverterMap::const_iterator it =
62  getConverterMap().find(condition.getTypeAttributeValue());
63  TEUCHOS_TEST_FOR_EXCEPTION(it == getConverterMap().end(),
65  "Could not find a ConditionXMLConverter for a condition of type " <<
66  condition.getTypeAttributeValue() << " when writing out a condition to " <<
67  "xml." << std::endl << std::endl
68  )
69  return it->second;
70 }
71 
72 
75 {
76  std::string conditionType = xmlObject.getRequired(
78  ConverterMap::const_iterator it = getConverterMap().find(conditionType);
79  TEUCHOS_TEST_FOR_EXCEPTION(it == getConverterMap().end(),
81  "Could not find a ConditionXMLConverter for a condition of type " <<
82  conditionType << " when reading in a condition from " <<
83  "xml." << std::endl << std::endl
84  )
85  return it->second;
86 }
87 
89  RCP<const Condition> condition,
90  const XMLParameterListWriter::EntryIDsMap& entryIDsMap)
91 {
92  return getConverter(*condition)->fromConditiontoXML(condition, entryIDsMap);
93 }
94 
96  const XMLObject& xmlObject,
97  const XMLParameterListReader::EntryIDsMap& entryIDsMap)
98 {
99  return ConditionXMLConverterDB::getConverter(xmlObject)->
100  fromXMLtoCondition(xmlObject, entryIDsMap);
101 }
102 
103 ConditionXMLConverterDB::ConverterMap&
104 ConditionXMLConverterDB::getConverterMap()
105 {
106  static ConverterMap masterMap;
107  return masterMap;
108 }
109 
110 
111 } // namespace Teuchos
112 
113 
114 namespace {
115 
116 
117 TEUCHOS_STATIC_SETUP()
118 {
122  TEUCHOS_ADD_NUMBERCONDITION_CONVERTER(unsigned short int);
124  TEUCHOS_ADD_NUMBERCONDITION_CONVERTER(unsigned long int);
127 
129  TEUCHOS_ADD_NUMBERCONDITION_CONVERTER(unsigned long long int);
130 
133  getDummyObject(),
135 
138  getDummyObject(),
140 
143  getDummyObject(),
145 
148  getDummyObject(),
150 
153  getDummyObject(),
155 
158  getDummyObject(),
160 }
161 
162 
163 } // namespace
An xml converter for StringConditions The valid XML represntation for a StringCondition is: ...
virtual std::string getTypeAttributeValue() const =0
Get the value that should be used for the condition type attribute when converting a condition to XML...
A collection of Exceptions thrown when converting Conditions to and from XML.
static RCP< Condition > convertXML(const XMLObject &xmlObject, const XMLParameterListReader::EntryIDsMap &entryIDsMap)
Given an XMLObject and IDtoConditionMap, converts the XMLObject to a Condition.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
Thrown when an appropriate Condition Converter can&#39;t be found.
static RCP< const ConditionXMLConverter > getConverter(const Condition &condition)
Get an appropriate ConditionXMLConverter given a Condition.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
Representation of an XML data tree. XMLObject is a ref-counted handle to a XMLObjectImplem object...
A database for ConditionXMLConverters.
std::map< RCP< const ParameterEntry >, ParameterEntry::ParameterEntryID, RCPConstComp > EntryIDsMap
std::map< ParameterEntry::ParameterEntryID, RCP< ParameterEntry > > EntryIDsMap
Convenience typedef.
static XMLObject convertCondition(RCP< const Condition > condition, const XMLParameterListWriter::EntryIDsMap &entryIDsMap)
Given a condition and ConditiontoIDMap, converts the condition to XML.
Class for retrieving a dummy object of type T.
A Condition determines whether or not a particular set of conditions are currently occuring...
#define TEUCHOS_ADD_NUMBERCONDITION_CONVERTER(T)
Adds a NumberCondition of type T.
static void addConverter(RCP< const Condition > condition, RCP< ConditionXMLConverter > converterToAdd)
Add a converter to the database.
Smart reference counting pointer class for automatic garbage collection.
static const std::string & getTypeAttributeName()
Returns the string to be used for the type attribute.
const std::string & getRequired(const std::string &name) const
Get an attribute, throwing an std::exception if it is not found.