44#include "Teuchos_Assert.hpp"
45#include "Teuchos_ParameterEntryXMLConverterDB.hpp"
54: _allowDuplicateSublists(true)
58{
return _allowDuplicateSublists; }
61{ _allowDuplicateSublists = policy; }
71 "XMLParameterListReader expected tag " <<
73 <<
", found " << xml.
getTag());
78 if(validatorsIndex != -1){
79 convertValidators(xml.
getChild(validatorsIndex), validatorIDsMap);
82 convertParameterList(xml, rtn, entryIDsMap, validatorIDsMap);
86 if(dependencyIndex != -1){
105 "XMLParameterListReader expected tag " <<
107 <<
", found " << xml.
getTag());
110 int validatorsIndex =
112 if(validatorsIndex != -1){
113 convertValidators(xml.
getChild(validatorsIndex), validatorIDsMap);
116 convertParameterList(xml, rtn, entryIDsMap, validatorIDsMap);
122void XMLParameterListReader::convertValidators(
125 std::set<const XMLObject*> validatorsWithPrototypes;
130 validatorsWithPrototypes.insert(&xml.
getChild(i));
133 RCP<ParameterEntryValidator> insertedValidator =
139 testForDuplicateValidatorIDs(xmlID, validatorIDsMap);
147 std::set<const XMLObject*>::const_iterator it =
148 validatorsWithPrototypes.begin();
149 it!=validatorsWithPrototypes.end();
152 RCP<ParameterEntryValidator> insertedValidator =
157 testForDuplicateValidatorIDs(xmlID, validatorIDsMap);
159 xmlID, insertedValidator));
165XMLParameterListReader::convertParameterList(
const XMLObject& xml,
166 RCP<ParameterList> parentList,
167 EntryIDsMap& entryIDsMap,
const IDtoValidatorMap& validatorIDsMap)
const
171 BadParameterListElementException,
172 "XMLParameterListReader expected tag " <<
182 for (
int i=0; i<xml.numChildren(); i++) {
184 XMLObject child = xml.getChild(i);
194 BadParameterListElementException,
195 "XMLParameterListReader expected tag "
198 << child.getTag() <<
" tag.");
215 std::ostringstream ss;
220 _allowDuplicateSublists ==
false
222 parentList->isSublist(name) ==
true,
223 DuplicateParameterSublist,
224 "XMLParameterListReader encountered duplicate sublist \"" << name <<
"\", in violation"
225 <<
" of the policy specified by XMLParameterListReader::setAllowsDuplicateSublists()." );
226 RCP<ParameterList> newList = sublist(parentList, name);
227 convertParameterList(child, newList, entryIDsMap, validatorIDsMap);
232 NoNameAttributeExecption,
233 "All child nodes of a ParameterList must have a name attribute!" <<
234 std::endl << std::endl);
236 parentList->setEntry(
243 MissingValidatorDefinitionException,
244 "Could not find validator with id: "
245 << child.getRequired(
248 "Bad Parameter: " << name << std::endl << std::endl);
249 parentList->getEntryRCP(name)->setValidator(result->second);
253 insertEntryIntoMap(child, parentList->getEntryRCP(name), entryIDsMap);
259void XMLParameterListReader::testForDuplicateValidatorIDs(
261 const IDtoValidatorMap& currentMap)
const
264 DuplicateValidatorIDsException,
265 "Validators with duplicate ids found!" << std::endl <<
266 "Bad ID: " << potentialNewID);
269void XMLParameterListReader::convertDependencies(
270 RCP<DependencySheet> depSheet,
271 const XMLObject& xml,
272 const EntryIDsMap& entryIDsMap,
273 const IDtoValidatorMap& validatorIDsMap)
const
279 for(
int i = 0; i < xml.numChildren(); ++i){
284 depSheet->addDependency(currentDep);
288void XMLParameterListReader::insertEntryIntoMap(
289 const XMLObject& xmlObj,
290 RCP<ParameterEntry> entryToInsert,
291 EntryIDsMap& entryIDsMap)
const
299 DuplicateParameterIDsException,
300 "Parameters/ParameterList with duplicate ids found!" << std::endl <<
301 "Bad ID: " << xmlID << std::endl << std::endl);
302 entryIDsMap.insert(EntryIDsMap::value_type(xmlID, entryToInsert));
A database for DependencyXMLConverters.
A database for ValidatorXMLConverters.
Writes an XML object to a parameter list.
Writes a ParameterList to an XML object.
Thrown when the root xml tag for a parameter list is incorrect.
static const std::string & getNameAttributeName()
When serializing to XML, this string should be used as the name of the name attribute.
static RCP< Dependency > convertXML(const XMLObject &xmlObject, const XMLParameterListReader::EntryIDsMap &entryIDsMap, const IDtoValidatorMap &validatorIDsMap)
Given an XMLObject converts the XMLObject to a Dependency.
Maps Validators to integers.
ValidatorMap::const_iterator const_iterator
std::pair< ParameterEntryValidator::ValidatorID, RCP< ParameterEntryValidator > > IDValidatorPair
void insert(IDValidatorPair toInsert)
inserts an IDValidatorPair into the map.
static ParameterEntry convertXML(const XMLObject &xmlObj)
Converts XML to a ParameterEntry.
static const std::string & getIdAttributeName()
unsigned int ParameterEntryID
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...
A list of parameters of arbitrary type.
Smart reference counting pointer class for automatic garbage collection.
static RCP< ParameterEntryValidator > convertXML(const XMLObject &xmlObject, const IDtoValidatorMap &validatorIDsMap)
Given an XMLObject converts the XMLObject to a ParameterEntryValidator and inserts the validator into...
static const std::string & getIdAttributeName()
static const std::string & getPrototypeIdAttributeName()
Representation of an XML data tree. XMLObject is a ref-counted handle to a XMLObjectImplem object,...
const std::string & getRequired(const std::string &name) const
Get an attribute, throwing an std::exception if it is not found.
const std::string & getTag() const
Return the tag of the current node.
const XMLObject & getChild(int i) const
Return the i-th child node.
bool hasAttribute(const std::string &name) const
Find out if the current node has an attribute of the specified name.
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.
int numChildren() const
Return the number of child nodes owned by this node.
bool getAllowsDuplicateSublists() const
Specifies the current policy regarding duplicated sublists. See setAllowsDuplicateSublists() for more...
void setAllowsDuplicateSublists(bool policy)
Set policy regarding duplicated sublists.
RCP< ParameterList > toParameterList(const XMLObject &xml, RCP< DependencySheet > depSheet) const
std::map< ParameterEntry::ParameterEntryID, RCP< ParameterEntry > > EntryIDsMap
Convenience typedef.
static const std::string & getDependenciesTagName()
static const std::string & getValidatorsTagName()
static const std::string & getParameterListTagName()
static const std::string & getNameAttributeName()
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.