Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_DependencyXMLConverterDB.cpp
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 
44 
45 
46 
47 namespace Teuchos {
48 
49 
50 
52  RCP<const Dependency> dependency,
53  RCP<DependencyXMLConverter> converterToAdd)
54 {
55  getConverterMap().insert(
56  ConverterPair(dependency->getTypeAttributeValue(), converterToAdd));
57 }
58 
59 
62 {
63  ConverterMap::const_iterator it =
64  getConverterMap().find(dependency.getTypeAttributeValue());
67  "Could not find a DependencyXMLConverter for a dependency with "
68  "attribute tag " << dependency.getTypeAttributeValue() <<
69  "!" << std::endl <<
70  "Try adding an appropriate converter to the DependencyXMLConverterDB " <<
71  "in order to solve this problem." << std::endl << std::endl);
72  return it->second;
73 }
74 
75 
78 {
79  std::string dependencyType = xmlObject.getRequired(
81  ConverterMap::const_iterator it = getConverterMap().find(dependencyType);
82  #ifdef HAVE_TEUCHOS_DEBUG
83  std::ostringstream sout;
85  #endif
86  std::string extraError =
87  #ifdef HAVE_TEUCHOS_DEBUG
88  sout.str();
89  #else
90  "";
91  #endif
92 
95  "Could not find a DependencyXMLConverter for a dependency of type " <<
96  dependencyType << "!" << std::endl <<
97  "Try adding an appropriate converter to the DependencyXMLConverterDB " <<
98  "in order to solve this problem." << std::endl << std::endl << extraError
99  );
100  return it->second;
101 }
102 
104  RCP<const Dependency> dependency,
105  const XMLParameterListWriter::EntryIDsMap& entryIDsMap,
106  ValidatortoIDMap& validatorIDsMap)
107 {
108  return getConverter(*dependency)->fromDependencytoXML(
109  dependency, entryIDsMap, validatorIDsMap);
110 }
111 
113  const XMLObject& xmlObject,
114  const XMLParameterListReader::EntryIDsMap& entryIDsMap,
115  const IDtoValidatorMap& validatorIDsMap)
116 {
117  return DependencyXMLConverterDB::getConverter(xmlObject)->
118  fromXMLtoDependency(xmlObject, entryIDsMap, validatorIDsMap);
119 }
120 
123 {
124  static ConverterMap masterMap;
125  return masterMap;
126 }
127 
128 
129 } // namespace Teuchos
130 
131 
132 namespace {
133 
134 
136 {
142 
143  TEUCHOS_ADD_TEMPLATED_NUMBER_DEPS(long long int)
144 
146  Teuchos::StringValidatorDependency,
147  Teuchos::StringValidatorDependencyXMLConverter)
149  Teuchos::StringVisualDependency,
150  Teuchos::StringVisualDependencyXMLConverter)
152  Teuchos::BoolValidatorDependency,
153  Teuchos::BoolValidatorDependencyXMLConverter)
155  Teuchos::BoolVisualDependency,
156  Teuchos::BoolVisualDependencyXMLConverter)
158  Teuchos::ConditionVisualDependency,
159  Teuchos::ConditionVisualDependencyXMLConverter)
160 }
161 
162 
163 } //namespace
164 
Maps Validators to integers.
A database for DependencyXMLConverters.
static const std::string & getTypeAttributeName()
Returns the string to be used for the type attribute.
#define TEUCHOS_ADD_RANGE_VALIDATOR_DEP(T)
Adds a RangeValidatorDependencyXMLConverter temeplated on type T to the list of available converters...
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
static ConverterMap & getConverterMap()
Gets the default converter to be used to convert Dependencies.
This class represents a depndency between elements in a Parameter List.
#define TEUCHOS_ADD_DEP_CONVERTER(DEP_TYPE, CONVERTER)
Adds converter to the list of DependencyXMLConverters so that all dependencies of DEP_TYPE will be co...
static void printKnownConverters(std::ostream &out)
prints the xml tags associated with all known converters
#define TEUCHOS_ADD_TEMPLATED_NUMBER_DEPS(T)
Adds converters for NumberVisualDepednency, RangeValidatorDepencny, and NumberArrayLengthDependency w...
#define TEUCHOS_ADD_NUMBER_VISUAL_DEP(T)
Adds a NumberVisualDependencyXMLConverter temeplated on type T to the list of available converters...
std::pair< std::string, RCP< DependencyXMLConverter > > ConverterPair
convience typedef.
Representation of an XML data tree. XMLObject is a ref-counted handle to a XMLObjectImplem object...
std::map< RCP< const ParameterEntry >, ParameterEntry::ParameterEntryID, RCPConstComp > EntryIDsMap
virtual std::string getTypeAttributeValue() const =0
Returns the string to be used for the value of the type attribute when converting the dependency to X...
A class for mapping validators to integers.
static void addConverter(RCP< const Dependency > dependency, RCP< DependencyXMLConverter > converterToAdd)
Add a converter to the database.
std::map< std::string, RCP< DependencyXMLConverter > > ConverterMap
convience class.
std::map< ParameterEntry::ParameterEntryID, RCP< ParameterEntry > > EntryIDsMap
Convenience typedef.
Smart reference counting pointer class for automatic garbage collection.
static RCP< const DependencyXMLConverter > getConverter(const Dependency &dependency)
Get an appropriate DependencyXMLConverter given a ParameterEntry.
static XMLObject convertDependency(RCP< const Dependency > dependency, const XMLParameterListWriter::EntryIDsMap &entryIDsMap, ValidatortoIDMap &validatorIDsMap)
Given a dependency converts the dependency to XML.
static RCP< Dependency > convertXML(const XMLObject &xmlObject, const XMLParameterListReader::EntryIDsMap &entryIDsMap, const IDtoValidatorMap &validatorIDsMap)
Given an XMLObject converts the XMLObject to a Dependency.
const std::string & getRequired(const std::string &name) const
Get an attribute, throwing an std::exception if it is not found.
TEUCHOS_STATIC_SETUP()
Thrown when an appropriate Dependency Converter can&#39;t be found.