Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_ParameterEntryXMLConverter.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 
15 
16 namespace Teuchos{
17 
18 
19 ParameterEntry
21  const XMLObject &xmlObj) const
22 {
23  #ifdef HAVE_TEUCHOS_DEBUG
27  "Error: this Parameter Entry XML tag has a type different than "
28  "the XMLConverter being used to convert it." <<std::endl <<
29  "Parameter name: " << xmlObj.getRequired(
31  "XML Parameter Entry type: " <<
32  xmlObj.getRequired(getTypeAttributeName()) << std::endl <<
33  "XMLConverter type: " << getTypeAttributeValue() <<
34  std::endl <<std::endl);
35  #endif
36 
40  ParameterEntry::getTagName() <<" tags must "
41  "have a " << getValueAttributeName() << " attribute" << std::endl <<
42  "Bad Parameter: " <<
44  std::endl << std::endl);
45 
46  ParameterEntry toReturn;
47  bool isDefault = false;
48  bool isUsed = false;
49  std::string docString = "";
50 
51 
53  isDefault = xmlObj.getRequiredBool(getDefaultAttributeName());
54  }
55 
56  if(xmlObj.hasAttribute(getUsedAttributeName())){
57  isUsed = xmlObj.getRequiredBool(getUsedAttributeName());
58  }
59 
61  docString = xmlObj.getRequired(getDocStringAttributeName());
62  }
63 
64  toReturn.setAnyValue(getAny(xmlObj), isDefault);
65  toReturn.setDocString(docString);
66 
67  if(isUsed){
68  toReturn.getAny();
69  }
70 
71  return toReturn;
72 }
73 
74 
78  const std::string &name,
80  const ValidatortoIDMap& validatorIDsMap) const
81 {
82  #ifdef HAVE_TEUCHOS_DEBUG
84  (entry->getAny().typeName() != getTypeAttributeValue())
85  &&
86  (
88  ParameterEntryXMLConverterDB::getDefaultConverter()->getTypeAttributeValue()
89  ),
91  "Error: This converter can't convert the given ParameterEntry to XML "
92  "because their types don't match." << std::endl <<
93  "Parameter name: " << name << std::endl <<
94  "Parameter type: " << entry->getAny().typeName() << std::endl <<
95  "Converter type: " << getTypeAttributeValue() << std::endl << std::endl);
96  #endif
97 
99  toReturn.addAttribute(
101  toReturn.addAttribute(getTypeAttributeName(), getTypeAttributeValue());
102  toReturn.addAttribute(getDocStringAttributeName(), entry->docString());
103  toReturn.addAttribute(getIdAttributeName(), id);
104  toReturn.addAttribute(
106  toReturn.addBool(getDefaultAttributeName(), entry->isDefault());
107  toReturn.addBool(getUsedAttributeName(), entry->isUsed());
108  if(nonnull(entry->validator())){
110  validatorIDsMap.find(entry->validator()) == validatorIDsMap.end(),
112  "Could not find validator in given ValidatorIDsMap! " <<
113  std::endl << std::endl);
114  toReturn.addAttribute(
116  validatorIDsMap.find(entry->validator())->second);
117  }
118  return toReturn;
119 }
120 
121 
122 } // namespace Teuchos
123 
static const std::string & getIdAttributeName()
XMLObject fromParameterEntrytoXML(RCP< const ParameterEntry > entry, const std::string &name, const ParameterEntry::ParameterEntryID &id, const ValidatortoIDMap &validatorIDsMap) const
Converts the given parameter entry to xml.
Thrown when a parameter entry tag is missing it&#39;s value attribute.
bool nonnull(const std::shared_ptr< T > &p)
Returns true if p.get()!=NULL.
This object is held as the &quot;value&quot; in the Teuchos::ParameterList std::map.
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.
Thrown when a converter is being used to convert either and XML tag or ParameterEntry with an innappr...
virtual const std::string getTypeAttributeValue() const =0
Gets a string representing the value that should be assigned to the &quot;type&quot; attribute when converting ...
Representation of an XML data tree. XMLObject is a ref-counted handle to a XMLObjectImplem object...
Converts back and forth between XML and ParameterEntryValidators.
Writes a ParameterList to an XML object.
ParameterEntry fromXMLtoParameterEntry(const XMLObject &xmlObj) const
Converts the given xml into a parameter entry.
const_iterator end() const
Returns a const_reference to the end of the map.
A class for mapping validators to integers.
virtual any getAny(const XMLObject &xmlObj) const =0
bool getRequiredBool(const std::string &name) const
Get a required attribute, returning it as a bool.
const_iterator find(const RCP< const ParameterEntryValidator > validator) const
Returns an iterator to the validator and id specified by the validator.
virtual const std::string getValueAttributeValue(RCP< const ParameterEntry > entry) const =0
Gets the value to be assigned to the &quot;value&quot; attribute when converting the paramter entry to xml...
A collection of Exceptions that can be potentially thrown when converting a ParameterList to and from...
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.
Thrown when a referenced validator can&#39;t be found.