Teuchos Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
Teuchos_XMLParameterListReader.cpp
Go to the documentation of this file.
1// @HEADER
2// ***********************************************************************
3//
4// Teuchos: Common Tools Package
5// Copyright (2004) Sandia Corporation
6//
7// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8// license for use of this work by or on behalf of the U.S. Government.
9//
10// Redistribution and use in source and binary forms, with or without
11// modification, are permitted provided that the following conditions are
12// met:
13//
14// 1. Redistributions of source code must retain the above copyright
15// notice, this list of conditions and the following disclaimer.
16//
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// 3. Neither the name of the Corporation nor the names of the
22// contributors may be used to endorse or promote products derived from
23// this software without specific prior written permission.
24//
25// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36//
37// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38//
39// ***********************************************************************
40// @HEADER
41
44#include "Teuchos_Assert.hpp"
48
49
50namespace Teuchos {
51
52
54: _allowDuplicateSublists(true)
55{;}
56
59
62
95
96
120
121
162
163
164void
168{
172 "XMLParameterListReader expected tag " <<
174 <<", found the tag "
175 << xml.getTag());
176
178 parentList->setName(
180 }
181
182 for (int i=0; i<xml.numChildren(); i++) {
183
184 XMLObject child = xml.getChild(i);
185
188 &&
190 &&
192 &&
195 "XMLParameterListReader expected tag "
197 << ParameterEntry::getTagName() << ", but found "
198 << child.getTag() << " tag.");
199
200
201 if(
203 ||
205 )
206 {
207
208 std::string name;
212 }
213 else {
214 // the name needs to be unique: generate one
215 std::ostringstream ss;
216 ss << "child" << i;
217 name = ss.str();
218 }
221 &&
222 parentList->isSublist(name) == true,
224 "XMLParameterListReader encountered duplicate sublist \"" << name << "\", in violation"
225 << " of the policy specified by XMLParameterListReader::setAllowsDuplicateSublists()." );
226 RCP<ParameterList> newList = sublist(parentList, name);
228 }
229 else if (child.getTag() == ParameterEntry::getTagName()) {
233 "All child nodes of a ParameterList must have a name attribute!" <<
234 std::endl << std::endl);
236 parentList->setEntry(
244 "Could not find validator with id: "
245 << child.getRequired(
247 << std::endl <<
248 "Bad Parameter: " << name << std::endl << std::endl);
249 parentList->getEntryRCP(name)->setValidator(result->second);
250 }
251 }
253 insertEntryIntoMap(child, parentList->getEntryRCP(name), entryIDsMap);
254 }
255 }
256 }
257}
258
268
271 const XMLObject& xml,
274{
275 if(xml.hasAttribute(DependencySheet::getNameAttributeName())){
276 depSheet->setName(
278 }
279 for(int i = 0; i < xml.numChildren(); ++i){
281 xml.getChild(i),
284 depSheet->addDependency(currentDep);
285 }
286}
287
289 const XMLObject& xmlObj,
292{
294 {
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));
303 }
304}
305
306
307} // namespace Teuchos
308
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 an element inside a parameter list is bad.
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.
Thrown when two parameters in an XML file have the same ID.
Optionally thrown when a sublist is set twice by either updateParametersFromXmlFile(),...
Constructs a CantFindParameterEntryConverterException.
Maps Validators to integers.
ValidatorMap::const_iterator const_iterator
std::pair< ParameterEntryValidator::ValidatorID, RCP< ParameterEntryValidator > > IDValidatorPair
Thrown when a referenced validator can't be found.
Thrown when a parameter entry tag is missing it's name attribute.
static ParameterEntry convertXML(const XMLObject &xmlObj)
Converts XML to a ParameterEntry.
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.
Concrete serial communicator subclass.
int getTag() const
The current tag.
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,...
bool getAllowsDuplicateSublists() const
Specifies the current policy regarding duplicated sublists. See setAllowsDuplicateSublists() for more...
void setAllowsDuplicateSublists(bool policy)
Set policy regarding duplicated sublists.
void insertEntryIntoMap(const XMLObject &xmlObj, RCP< ParameterEntry > entryToInsert, EntryIDsMap &entryIDsMap) const
void convertParameterList(const XMLObject &xml, RCP< ParameterList > parentList, EntryIDsMap &entryIDsMap, const IDtoValidatorMap &validatorIDsMap) const
Write the given XML object to a parameter list along with the validators located in the given map.
void testForDuplicateValidatorIDs(ParameterEntryValidator::ValidatorID potentialNewID, const IDtoValidatorMap &currentMap) const
Tests to see if there are duplicate validator IDs.
RCP< ParameterList > toParameterList(const XMLObject &xml, RCP< DependencySheet > depSheet) const
void convertValidators(const XMLObject &xml, IDtoValidatorMap &validatorIDsMap) const
Write the given XML object to appropriate validators.
void convertDependencies(RCP< DependencySheet > depSheet, const XMLObject &xml, const EntryIDsMap &entryIDsMap, const IDtoValidatorMap &validatorIDsMap) const
Write the given XML object to appropriate dependencies.
std::map< ParameterEntry::ParameterEntryID, RCP< ParameterEntry > > EntryIDsMap
Convenience typedef.
static const std::string & getDependenciesTagName()
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.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.