Teuchos - Trilinos Tools Package Version of the Day
Loading...
Searching...
No Matches
Teuchos_XMLParameterListWriter.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#include "Teuchos_ParameterEntryXMLConverterDB.hpp"
15
16
17namespace Teuchos{
18
19
22
23
26 const ParameterList& p,
28{
32
33 //We build an initial map full of validators that are located in the
34 //parameter list. That way we can convert the parameter entries.
35 buildInitialValidatorMap(p, validatorIDsMap);
36
38 convertParameterList(p, peIDCounter, entryIDsMap, validatorIDsMap);
39 toReturn.addAttribute(getNameAttributeName(), p.name());
40
41 if(!depSheet.is_null()){
43 convertDependencies(depSheet, entryIDsMap, validatorIDsMap);
44 toReturn.addChild(deps);
45 }
46
47 //Validators must be done after depencneies because dependencies might add
48 //entries to the validator map. KLN 09/20/2010
49 XMLObject validators = convertValidators(p, validatorIDsMap);
50 toReturn.addChild(validators);
51
52 return toReturn;
53}
54
55void XMLParameterListWriter::buildInitialValidatorMap(
56 const ParameterList& p,
58{
59 for (ParameterList::ConstIterator i=p.begin(); i!=p.end(); ++i) {
60 const ParameterEntry& entry = p.entry(i);
61 if(entry.isList()){
62 buildInitialValidatorMap(
65 }
66 else if(nonnull(entry.validator())){
67 validatorIDsMap.insert(entry.validator());
68 }
69 }
70}
71
72
73XMLObject XMLParameterListWriter::convertValidators(
74 const ParameterList& /* p */, ValidatortoIDMap& validatorIDsMap) const
75{
76 XMLObject validators(getValidatorsTagName());
77 for(
78 ValidatortoIDMap::const_iterator it = validatorIDsMap.begin();
79 it != validatorIDsMap.end();
80 ++it)
81 {
82 validators.addChild(
83 ValidatorXMLConverterDB::convertValidator(it->first, validatorIDsMap));
84 }
85 return validators;
86}
87
88
89XMLObject XMLParameterListWriter::convertParameterList(
90 const ParameterList& p,
92 EntryIDsMap& entryIDsMap,
93 const ValidatortoIDMap& validatorIDsMap) const
94{
95 XMLObject rtn(getParameterListTagName());
96
97 for (ParameterList::ConstIterator i=p.begin(); i!=p.end(); ++i){
98 RCP<const ParameterEntry> entry = p.getEntryRCP(i->first);
99 if(entry->isList()){
100 XMLObject newPL = convertParameterList(
101 getValue<ParameterList>(entry),
102 idCounter,
103 entryIDsMap,
104 validatorIDsMap);
105 newPL.addAttribute(
106 getNameAttributeName(), p.name(i));
107 newPL.addAttribute(
109 entryIDsMap.insert(EntryIDsMap::value_type(entry, idCounter));
110 rtn.addChild(newPL);
111 ++idCounter;
112 }
113 else{
115 entry, p.name(i), idCounter, validatorIDsMap));
116 entryIDsMap.insert(EntryIDsMap::value_type(entry, idCounter));
117 ++idCounter;
118 }
119 }
120 return rtn;
121}
122
123XMLObject
124XMLParameterListWriter::convertDependencies(
125 RCP<const DependencySheet> depSheet,
126 const EntryIDsMap& entryIDsMap,
127 ValidatortoIDMap& validatorIDsMap) const
128{
129 XMLObject toReturn(getDependenciesTagName());
130 toReturn.addAttribute(
132 depSheet->getName()
133 );
134
135 for(
136 DependencySheet::DepSet::const_iterator it = depSheet->depBegin();
137 it != depSheet->depEnd();
138 ++it)
139 {
141 *it, entryIDsMap, validatorIDsMap));
142 }
143 return toReturn;
144}
145
146
147} // namespace Teuchos
148
A database for DependencyXMLConverters.
A database for ValidatorXMLConverters.
A collection of Exceptions that can be potentially thrown when converting a ParameterList to and from...
Writes a ParameterList to an XML object.
static const std::string & getNameAttributeName()
When serializing to XML, this string should be used as the name of the name attribute.
static XMLObject convertDependency(RCP< const Dependency > dependency, const XMLParameterListWriter::EntryIDsMap &entryIDsMap, ValidatortoIDMap &validatorIDsMap)
Given a dependency converts the dependency to XML.
static XMLObject convertEntry(RCP< const ParameterEntry > entry, const std::string &name, const ParameterEntry::ParameterEntryID &id, const ValidatortoIDMap &validatorIDsMap)
Converts the given ParameterEntry to XML.
This object is held as the "value" in the Teuchos::ParameterList std::map.
RCP< const ParameterEntryValidator > validator() const
Return the (optional) validator object.
bool isList() const
Return whether or not the value itself is a list.
A list of parameters of arbitrary type.
params_t::ConstIterator ConstIterator
Parameter container const iterator typedef.
Smart reference counting pointer class for automatic garbage collection.
bool is_null() const
Returns true if the underlying pointer is null.
static XMLObject convertValidator(RCP< const ParameterEntryValidator > validator, const ValidatortoIDMap &validatorIDsMap, bool assignedID=true)
Given a validator converts the validator to XML.
A class for mapping validators to integers.
void insert(RCP< const ParameterEntryValidator > toInsert)
inserts an IDValidatorPair into the map.
ValidatorMap::const_iterator const_iterator
Representation of an XML data tree. XMLObject is a ref-counted handle to a XMLObjectImplem object,...
std::map< RCP< const ParameterEntry >, ParameterEntry::ParameterEntryID, RCPConstComp > EntryIDsMap
static const std::string & getDependenciesTagName()
static const std::string & getValidatorsTagName()
static const std::string & getParameterListTagName()
static const std::string & getNameAttributeName()
XMLObject toXML(const ParameterList &p, RCP< const DependencySheet > depSheet=null) const
bool nonnull(const std::shared_ptr< T > &p)
Returns true if p.get()!=NULL.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...