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 // 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 
13 
14 
15 namespace Teuchos {
16 
17 
18 
20  RCP<const Dependency> dependency,
21  RCP<DependencyXMLConverter> converterToAdd)
22 {
23  getConverterMap().insert(
24  ConverterPair(dependency->getTypeAttributeValue(), converterToAdd));
25 }
26 
27 
30 {
31  ConverterMap::const_iterator it =
32  getConverterMap().find(dependency.getTypeAttributeValue());
35  "Could not find a DependencyXMLConverter for a dependency with "
36  "attribute tag " << dependency.getTypeAttributeValue() <<
37  "!" << std::endl <<
38  "Try adding an appropriate converter to the DependencyXMLConverterDB " <<
39  "in order to solve this problem." << std::endl << std::endl);
40  return it->second;
41 }
42 
43 
46 {
47  std::string dependencyType = xmlObject.getRequired(
49  ConverterMap::const_iterator it = getConverterMap().find(dependencyType);
50  #ifdef HAVE_TEUCHOS_DEBUG
51  std::ostringstream sout;
53  #endif
54  std::string extraError =
55  #ifdef HAVE_TEUCHOS_DEBUG
56  sout.str();
57  #else
58  "";
59  #endif
60 
63  "Could not find a DependencyXMLConverter for a dependency of type " <<
64  dependencyType << "!" << std::endl <<
65  "Try adding an appropriate converter to the DependencyXMLConverterDB " <<
66  "in order to solve this problem." << std::endl << std::endl << extraError
67  );
68  return it->second;
69 }
70 
72  RCP<const Dependency> dependency,
73  const XMLParameterListWriter::EntryIDsMap& entryIDsMap,
74  ValidatortoIDMap& validatorIDsMap)
75 {
76  return getConverter(*dependency)->fromDependencytoXML(
77  dependency, entryIDsMap, validatorIDsMap);
78 }
79 
81  const XMLObject& xmlObject,
82  const XMLParameterListReader::EntryIDsMap& entryIDsMap,
83  const IDtoValidatorMap& validatorIDsMap)
84 {
85  return DependencyXMLConverterDB::getConverter(xmlObject)->
86  fromXMLtoDependency(xmlObject, entryIDsMap, validatorIDsMap);
87 }
88 
91 {
92  static ConverterMap masterMap;
93  return masterMap;
94 }
95 
96 
97 } // namespace Teuchos
98 
99 
100 namespace {
101 
102 
104 {
110 
111  TEUCHOS_ADD_TEMPLATED_NUMBER_DEPS(long long int)
112 
114  Teuchos::StringValidatorDependency,
115  Teuchos::StringValidatorDependencyXMLConverter)
117  Teuchos::StringVisualDependency,
118  Teuchos::StringVisualDependencyXMLConverter)
120  Teuchos::BoolValidatorDependency,
121  Teuchos::BoolValidatorDependencyXMLConverter)
123  Teuchos::BoolVisualDependency,
124  Teuchos::BoolVisualDependencyXMLConverter)
126  Teuchos::ConditionVisualDependency,
127  Teuchos::ConditionVisualDependencyXMLConverter)
128 }
129 
130 
131 } //namespace
132 
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.