Teuchos - Trilinos Tools Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_DependencyXMLConverter.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 
12 
13 
14 namespace Teuchos{
15 
16 
17 RCP<Dependency>
19  const XMLObject& xmlObj,
20  const XMLParameterListReader::EntryIDsMap& entryIDsMap,
21  const IDtoValidatorMap& validatorIDsMap) const
22 {
25 
28  "Could not find any dependees for a dependency!"
29  <<std::endl <<std::endl);
30 
33  "Could not find any dependents for a dependency!"
34  <<std::endl <<std::endl);
35 
36  for(int i=0; i<xmlObj.numChildren(); ++i){
37  XMLObject child = xmlObj.getChild(i);
38  if(child.getTag() == getDependeeTagName()){
42 
43  TEUCHOS_TEST_FOR_EXCEPTION(entryIDsMap.find(dependeeID) == entryIDsMap.end(),
45  "Can't find a Dependee ParameterEntry associated with the ID: " <<
46  dependeeID << std::endl << std::endl);
47  dependees.insert(entryIDsMap.find(dependeeID)->second);
48  }
49  else if(child.getTag() == getDependentTagName()){
53 
54  TEUCHOS_TEST_FOR_EXCEPTION(entryIDsMap.find(dependentID) == entryIDsMap.end(),
56  "Can't find a Dependent ParameterEntry associated with the ID: " <<
57  dependentID << std::endl << std::endl);
58  dependents.insert(entryIDsMap.find(dependentID)->second);
59  }
60  }
61 
62  return convertXML(
63  xmlObj, dependees, dependents, entryIDsMap, validatorIDsMap);
64 }
65 
68  const RCP<const Dependency> dependency,
69  const XMLParameterListWriter::EntryIDsMap& entryIDsMap,
70  ValidatortoIDMap& validatorIDsMap) const
71 {
73 
75  dependency->getTypeAttributeValue());
76 
77  Dependency::ConstParameterEntryList::const_iterator it =
78  dependency->getDependees().begin();
79 
80  for(;it != dependency->getDependees().end(); ++it){
81  XMLObject currentDependee(getDependeeTagName());
82  TEUCHOS_TEST_FOR_EXCEPTION(entryIDsMap.find(*it) == entryIDsMap.end(),
84  "Can't find the Dependee of a dependency in the given " <<
85  "EntryIDsMap. Occurred when converting " <<
86  "to XML" << std::endl << std::endl);
88  getParameterIdAttributeName(), entryIDsMap.find(*it)->second);
89  toReturn.addChild(currentDependee);
90  }
91 
92  it = dependency->getDependents().begin();
93  for(; it != dependency->getDependents().end(); ++it){
94  XMLObject currentDependent(getDependentTagName());
95  TEUCHOS_TEST_FOR_EXCEPTION(entryIDsMap.find(*it) == entryIDsMap.end(),
97  "Can't find the Dependent of a dependency in the given " <<
98  "ValidatordIDsMap. Occurred when converting " <<
99  "to XML" << std::endl << std::endl);
101  getParameterIdAttributeName(), entryIDsMap.find(*it)->second);
102  toReturn.addChild(currentDependent);
103  }
104 
105  convertDependency(dependency, toReturn, entryIDsMap, validatorIDsMap);
106 
107  return toReturn;
108 }
109 
110 
111 } // namespace Teuchos
112 
virtual RCP< Dependency > convertXML(const XMLObject &xmlObj, const Dependency::ConstParameterEntryList dependees, const Dependency::ParameterEntryList dependets, const XMLParameterListReader::EntryIDsMap &entryIDsMap, const IDtoValidatorMap &validatorIDsMap) const =0
Preforms any and all special xml conversion that is specific to a particular Dependency.
RCP< Dependency > fromXMLtoDependency(const XMLObject &xmlObj, const XMLParameterListReader::EntryIDsMap &entryIDsMap, const IDtoValidatorMap &validatorIDsMap) const
Converts a given XMLObject to a Dependency.
Thrown when no dependes of a dependency can&#39;t be found when converting the dependency to or from XML...
const std::string & getTag() const
Return the tag of the current node.
Maps Validators to integers.
std::set< RCP< const ParameterEntry >, RCPConstComp > ConstParameterEntryList
A list of dependents.
static const std::string & getTypeAttributeName()
Returns the string to be used for the type attribute.
std::set< RCP< ParameterEntry >, RCPComp > ParameterEntryList
A list of Dependees.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
static const std::string & getDependeeTagName()
Returns the string to be used for the dependee tag.
void addChild(const XMLObject &child)
Add a child node to the node.
Thrown when a dependent of a dependency cant be found when converting the dependency to or from XML...
Thrown when no dependents of a dependency are specified when converting the dependency from XML...
Representation of an XML data tree. XMLObject is a ref-counted handle to a XMLObjectImplem object...
A collection of Exceptions thrown when converting Dependencys to and from XML.
std::map< RCP< const ParameterEntry >, ParameterEntry::ParameterEntryID, RCPConstComp > EntryIDsMap
static const std::string & getXMLTagName()
Returns the XML tag to use when serializing Dependencies.
static const std::string & getParameterIdAttributeName()
Returns the string to be used for the ParameterID attribute.
static const std::string & getDependentTagName()
Returns the string to be used for the dependent tag.
A class for mapping validators to integers.
void addAttribute(const std::string &name, T value)
Lookup whether or not Doubles are allowed.
virtual void convertDependency(const RCP< const Dependency > dependency, XMLObject &xmlObj, const XMLParameterListWriter::EntryIDsMap &entryIDsMap, ValidatortoIDMap &validatorIDsMap) const =0
Preforms any and all special dependency conversion that is specific to a particlar Dependency...
Converts back and forth between XML and Dependencies.
std::map< ParameterEntry::ParameterEntryID, RCP< ParameterEntry > > EntryIDsMap
Convenience typedef.
XMLObject fromDependencytoXML(const RCP< const Dependency > dependency, const XMLParameterListWriter::EntryIDsMap &entryIDsMap, ValidatortoIDMap &validatorIDsMap) const
Converters a given ParameterEntryValidator to XML.
int numChildren() const
Return the number of child nodes owned by this node.
Smart reference counting pointer class for automatic garbage collection.
int findFirstChild(std::string tagName) const
Returns the index of the first child found with the given tag name. Returns -1 if no child is found...
const XMLObject & getChild(int i) const
Return the i-th child node.
const std::string & getRequired(const std::string &name) const
Get an attribute, throwing an std::exception if it is not found.
Thrown when no dependess of a dependency are specified when converting the dependency from XML...