Teuchos - Trilinos Tools Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_ValidatorXMLConverter.cpp
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 
11 
12 namespace Teuchos{
13 
14 RCP<ParameterEntryValidator>
16  const XMLObject& xmlObj,
17  const IDtoValidatorMap& validatorIDsMap) const
18 {
19  #ifdef HAVE_TEUCHOS_DEBUG
20  RCP<const ParameterEntryValidator> dummyValidator = getDummyValidator();
23  !=
24  dummyValidator->getXMLTypeName(),
26  "Cannot convert xmlObject " <<
27  ". Expected a " << dummyValidator->getXMLTypeName() <<
28  " tag but got a " << xmlObj.getRequired(getTypeAttributeName()) << "type");
29  #endif
31  convertXML(xmlObj, validatorIDsMap);
32  return toReturn;
33 }
34 
37  const RCP<const ParameterEntryValidator> validator,
38  const ValidatortoIDMap& validatorIDsMap,
39  bool assignedID) const
40 {
41  #ifdef HAVE_TEUCHOS_DEBUG
42  RCP<const ParameterEntryValidator> dummyValidator = getDummyValidator();
44  validator->getXMLTypeName()
45  !=
46  dummyValidator->getXMLTypeName(),
48  "Cannot convert Validator " <<
49  ". Expected a " << dummyValidator->getXMLTypeName() <<
50  " validator but got a " << validator->getXMLTypeName() << "type");
51  #endif
52  XMLObject toReturn(getValidatorTagName());
53  toReturn.addAttribute(getTypeAttributeName(), validator->getXMLTypeName());
54  if(assignedID){
55  TEUCHOS_TEST_FOR_EXCEPTION(validatorIDsMap.find(validator) == validatorIDsMap.end(),
57  "Could not find an id associated with the validator in the "
58  "given validatorIDsMap to use when " <<
59  "writing it to XML!" << std::endl << std::endl);
60  toReturn.addAttribute(getIdAttributeName(),
61  validatorIDsMap.find(validator)->second);
62  }
63  convertValidator(validator, toReturn, validatorIDsMap);
64  return toReturn;
65 }
66 
67 
68 }
69 
static const std::string & getIdAttributeName()
Maps Validators to integers.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
XMLObject fromValidatortoXML(const RCP< const ParameterEntryValidator > validator, const ValidatortoIDMap &validatorIDsMap, bool assignedID=true) const
Converters a given ParameterEntryValidator to XML.
static const std::string & getTypeAttributeName()
Representation of an XML data tree. XMLObject is a ref-counted handle to a XMLObjectImplem object...
Converts back and forth between XML and ParameterEntryValidators.
virtual void convertValidator(const RCP< const ParameterEntryValidator > validator, XMLObject &xmlObj, const ValidatortoIDMap &validatorIDsMap) const =0
Preforms any and all special validator conversion that is specific to a particlar ParameterEntryValid...
const_iterator end() const
Returns a const_reference to the end of the map.
static const std::string & getValidatorTagName()
A class for mapping validators to integers.
const_iterator find(const RCP< const ParameterEntryValidator > validator) const
Returns an iterator to the validator and id specified by the validator.
Smart reference counting pointer class for automatic garbage collection.
RCP< ParameterEntryValidator > fromXMLtoValidator(const XMLObject &xmlObj, const IDtoValidatorMap &validatorIDsMap) const
Converts a given XMLObject to a ParameterEntryValidator.
virtual RCP< ParameterEntryValidator > convertXML(const XMLObject &xmlObj, const IDtoValidatorMap &validatorIDsMap) const =0
Preforms any and all special xml conversion that is specific to a particular ParameterEntryValidator...
const std::string & getRequired(const std::string &name) const
Get an attribute, throwing an std::exception if it is not found.
Thrown when a bad validator xml converter is used.
Thrown when a referenced validator can&#39;t be found.