12#include "Teuchos_Assert.hpp"
13#include "Teuchos_ParameterEntryXMLConverterDB.hpp"
22: _allowDuplicateSublists(
true)
26{
return _allowDuplicateSublists; }
29{ _allowDuplicateSublists =
policy; }
39 "XMLParameterListReader expected tag " <<
41 <<
", found " <<
xml.getTag());
73 "XMLParameterListReader expected tag " <<
75 <<
", found " <<
xml.getTag());
90void XMLParameterListReader::convertValidators(
94 for (
int i=0;
i<
xml.numChildren(); ++
i){
95 if (
xml.getChild(
i).hasAttribute(
101 RCP<ParameterEntryValidator> insertedValidator =
107 testForDuplicateValidatorIDs(xmlID, validatorIDsMap);
115 std::set<const XMLObject*>::const_iterator it =
116 validatorsWithPrototypes.begin();
117 it!=validatorsWithPrototypes.end();
120 RCP<ParameterEntryValidator> insertedValidator =
125 testForDuplicateValidatorIDs(xmlID, validatorIDsMap);
127 xmlID, insertedValidator));
133XMLParameterListReader::convertParameterList(
const XMLObject& xml,
134 RCP<ParameterList> parentList,
135 EntryIDsMap& entryIDsMap,
const IDtoValidatorMap& validatorIDsMap)
const
139 BadParameterListElementException,
140 "XMLParameterListReader expected tag " <<
150 for (
int i=0; i<xml.numChildren(); i++) {
152 XMLObject child = xml.getChild(i);
162 BadParameterListElementException,
163 "XMLParameterListReader expected tag "
166 << child.getTag() <<
" tag.");
183 std::ostringstream ss;
188 _allowDuplicateSublists ==
false
190 parentList->isSublist(name) ==
true,
191 DuplicateParameterSublist,
192 "XMLParameterListReader encountered duplicate sublist \"" << name <<
"\", in violation"
193 <<
" of the policy specified by XMLParameterListReader::setAllowsDuplicateSublists()." );
194 RCP<ParameterList> newList = sublist(parentList, name);
195 convertParameterList(child, newList, entryIDsMap, validatorIDsMap);
200 NoNameAttributeExecption,
201 "All child nodes of a ParameterList must have a name attribute!" <<
202 std::endl << std::endl);
204 parentList->setEntry(
211 MissingValidatorDefinitionException,
212 "Could not find validator with id: "
213 << child.getRequired(
216 "Bad Parameter: " << name << std::endl << std::endl);
217 parentList->getEntryRCP(name)->setValidator(result->second);
221 insertEntryIntoMap(child, parentList->getEntryRCP(name), entryIDsMap);
227void XMLParameterListReader::testForDuplicateValidatorIDs(
229 const IDtoValidatorMap& currentMap)
const
232 DuplicateValidatorIDsException,
233 "Validators with duplicate ids found!" << std::endl <<
234 "Bad ID: " << potentialNewID);
237void XMLParameterListReader::convertDependencies(
238 RCP<DependencySheet> depSheet,
239 const XMLObject& xml,
240 const EntryIDsMap& entryIDsMap,
241 const IDtoValidatorMap& validatorIDsMap)
const
247 for(
int i = 0; i < xml.numChildren(); ++i){
252 depSheet->addDependency(currentDep);
256void XMLParameterListReader::insertEntryIntoMap(
257 const XMLObject& xmlObj,
258 RCP<ParameterEntry> entryToInsert,
259 EntryIDsMap& entryIDsMap)
const
267 DuplicateParameterIDsException,
268 "Parameters/ParameterList with duplicate ids found!" << std::endl <<
269 "Bad ID: " << xmlID << std::endl << std::endl);
270 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 XMLObject & getChild(int i) const
Return the i-th child 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.