Teuchos - Trilinos Tools Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_ParameterEntryXMLConverterDB.cpp
1 
2 // @HEADER
3 // *****************************************************************************
4 // Teuchos: Common Tools Package
5 //
6 // Copyright 2004 NTESS and the Teuchos contributors.
7 // SPDX-License-Identifier: BSD-3-Clause
8 // *****************************************************************************
9 // @HEADER
10 
11 #include "Teuchos_ParameterEntryXMLConverterDB.hpp"
13 #include "Teuchos_StaticSetupMacro.hpp"
14 #include "Teuchos_TwoDArray.hpp"
15 
16 namespace Teuchos{
17 
18 
19 RCP<const ParameterEntryXMLConverter>
21 {
22  ConverterMap::const_iterator it =
23  getConverterMap().find(entry->getAny().typeName());
24  if(it == getConverterMap().end()){
25  return getDefaultConverter();
26  }
27  else{
28  return it->second;
29  }
30 }
31 
34 {
38  ParameterEntry::getTagName() <<" tags must "
40  " attribute." << std::endl <<
41  "Bad Parameter: " <<
43  std::endl << std::endl);
44 
45  std::string parameterType = xmlObject.getRequired(
47  ConverterMap::const_iterator it = getConverterMap().find(parameterType);
48 
49  TEUCHOS_TEST_FOR_EXCEPTION(it == getConverterMap().end(),
51  "Can't find converter for parameter entry of type: " <<
53  std::endl << std::endl);
54 
55  return it->second;
56 }
57 
59  out << "Known ParameterEntryXMLConverters: " << std::endl;
60  for(
61  ConverterMap::const_iterator it = getConverterMap().begin();
62  it != getConverterMap().end();
63  ++it)
64  {
65  out << "\t" << it->first <<std::endl;
66  }
67 }
68 
71 {
72  static RCP<const AnyParameterEntryConverter> defaultConverter;
73  if(defaultConverter.is_null()){
74  defaultConverter = rcp(new AnyParameterEntryConverter);
75  }
76  return defaultConverter;
77 }
78 
79 ParameterEntryXMLConverterDB::ConverterMap&
80 ParameterEntryXMLConverterDB::getConverterMap()
81 {
82  static ConverterMap masterMap;
83  return masterMap;
84 
85 }
86 
87 
88 } //namespace Teuchos
89 
90 
91 namespace {
92 
93 TEUCHOS_STATIC_SETUP()
94 {
95  typedef unsigned int uint;
96  typedef unsigned short int ushort;
97  typedef unsigned long ulong;
98  TEUCHOS_ADD_TYPE_AND_ARRAYTYPE_CONVERTER(int);
99  TEUCHOS_ADD_TYPE_AND_ARRAYTYPE_CONVERTER(uint);
100  TEUCHOS_ADD_TYPE_AND_ARRAYTYPE_CONVERTER(short);
101  TEUCHOS_ADD_TYPE_AND_ARRAYTYPE_CONVERTER(ushort);
102  TEUCHOS_ADD_TYPE_AND_ARRAYTYPE_CONVERTER(long);
103  TEUCHOS_ADD_TYPE_AND_ARRAYTYPE_CONVERTER(ulong);
104  typedef long long int llint;
105  typedef unsigned long long int ullint;
106  TEUCHOS_ADD_TYPE_AND_ARRAYTYPE_CONVERTER(llint);
107  TEUCHOS_ADD_TYPE_AND_ARRAYTYPE_CONVERTER(ullint);
108  TEUCHOS_ADD_TYPE_AND_ARRAYTYPE_CONVERTER(double);
109  TEUCHOS_ADD_TYPE_AND_ARRAYTYPE_CONVERTER(float);
110 
111  typedef std::string myString;
112  TEUCHOS_ADD_TYPE_AND_ARRAYTYPE_CONVERTER(myString);
113 
114  TEUCHOS_ADD_TYPE_CONVERTER(char);
115  TEUCHOS_ADD_TYPE_CONVERTER(bool);
116 
119 }
120 
121 
122 } // namespace
A thin wrapper around the Teuchos Array class that allows for 2 dimensional arrays.
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...
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
static RCP< const ParameterEntryXMLConverter > getConverter(RCP< const ParameterEntry > entry)
Get an appropriate ParameterEntryXMLConverter given a ParameterEntry.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
Thrown when an appropriate ParameterEntryXMLConverter can&#39;t be found.
Representation of an XML data tree. XMLObject is a ref-counted handle to a XMLObjectImplem object...
Writes a ParameterList to an XML object.
Thrown when a parameter entry tag is missing it&#39;s type attribute.
static void printKnownConverters(std::ostream &out)
prints the xml tags associated with all known converters
static void addConverter(RCP< ParameterEntryXMLConverter > converterToAdd)
Add a converter to the database.
A last resort converter for when no others will do.
const std::string & getAttribute(const std::string &name) const
Return the value of the attribute with the specified name.
static RCP< const ParameterEntryXMLConverter > getDefaultConverter()
Gets the default converter to be used on Parameter Entries.
Smart reference counting pointer class for automatic garbage collection.
bool hasAttribute(const std::string &name) const
Find out if the current node has an attribute of the specified name.
static const std::string & getNameAttributeName()
const std::string & getRequired(const std::string &name) const
Get an attribute, throwing an std::exception if it is not found.
bool is_null() const
Returns true if the underlying pointer is null.