Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_XMLParameterListWriter.cpp
Go to the documentation of this file.
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 
15 
16 
17 namespace Teuchos{
18 
19 
21 {;}
22 
23 
26  const ParameterList& p,
27  RCP<const DependencySheet> depSheet) const
28 {
29  EntryIDsMap entryIDsMap;
30  ValidatortoIDMap validatorIDsMap;
31  ParameterEntry::ParameterEntryID peIDCounter = 0;
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 
37  XMLObject toReturn =
38  convertParameterList(p, peIDCounter, entryIDsMap, validatorIDsMap);
39  toReturn.addAttribute(getNameAttributeName(), p.name());
40 
41  if(!depSheet.is_null()){
42  XMLObject deps =
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 
56  const ParameterList& p,
57  ValidatortoIDMap& validatorIDsMap) const
58 {
59  for (ParameterList::ConstIterator i=p.begin(); i!=p.end(); ++i) {
60  const ParameterEntry& entry = p.entry(i);
61  if(entry.isList()){
63  getValue<ParameterList>(entry),
64  validatorIDsMap);
65  }
66  else if(nonnull(entry.validator())){
67  validatorIDsMap.insert(entry.validator());
68  }
69  }
70 }
71 
72 
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 
90  const ParameterList& p,
92  EntryIDsMap& entryIDsMap,
93  const ValidatortoIDMap& validatorIDsMap) const
94 {
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()){
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 
123 XMLObject
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 
const std::string & name() const
The name of this ParameterList.
C++ Standard Library compatable filtered iterator.
XMLObject toXML(const ParameterList &p, RCP< const DependencySheet > depSheet=null) const
ConstIterator end() const
An iterator pointing beyond the last entry.
RCP< ParameterEntry > getEntryRCP(const std::string &name)
Retrieves the RCP for an entry with the name name if it exists.
A database for DependencyXMLConverters.
RCP< const ParameterEntryValidator > validator() const
Return the (optional) validator object.
bool nonnull(const std::shared_ptr< T > &p)
Returns true if p.get()!=NULL.
This object is held as the &quot;value&quot; in the Teuchos::ParameterList std::map.
void addChild(const XMLObject &child)
Add a child node to the node.
ValidatorMap::const_iterator const_iterator
static const std::string & getValidatorsTagName()
static XMLObject convertValidator(RCP< const ParameterEntryValidator > validator, const ValidatortoIDMap &validatorIDsMap, bool assignedID=true)
Given a validator converts the validator to XML.
void buildInitialValidatorMap(const ParameterList &p, ValidatortoIDMap &validatorIDsMap) const
Builds up the list of validators to be converted.
Representation of an XML data tree. XMLObject is a ref-counted handle to a XMLObjectImplem object...
static const std::string & getDependenciesTagName()
A database for ValidatorXMLConverters.
Writes a ParameterList to an XML object.
std::map< RCP< const ParameterEntry >, ParameterEntry::ParameterEntryID, RCPConstComp > EntryIDsMap
const_iterator end() const
Returns a const_reference to the end of the map.
A class for mapping validators to integers.
void insert(RCP< const ParameterEntryValidator > toInsert)
inserts an IDValidatorPair into the map.
ConstIterator begin() const
An iterator pointing to the first entry.
void addAttribute(const std::string &name, T value)
Lookup whether or not Doubles are allowed.
bool isList() const
Return whether or not the value itself is a list.
A list of parameters of arbitrary type.
XMLObject convertParameterList(const ParameterList &p, ParameterEntry::ParameterEntryID &idCounter, EntryIDsMap &entryIDsMap, const ValidatortoIDMap &validatorIDsMap) const
Write the given list to an XML object.
const ParameterEntry & entry(ConstIterator i) const
Access to ParameterEntry (i.e., returns i-&gt;second)
static XMLObject convertEntry(RCP< const ParameterEntry > entry, const std::string &name, const ParameterEntry::ParameterEntryID &id, const ValidatortoIDMap &validatorIDsMap)
Converts the given ParameterEntry to XML.
A collection of Exceptions that can be potentially thrown when converting a ParameterList to and from...
const_iterator begin() const
Returns a const_reference to the beginning of the map.
XMLObject convertDependencies(RCP< const DependencySheet > depSheet, const EntryIDsMap &entryIDsMap, ValidatortoIDMap &validatorIDsMap) const
Convert all the dependencies.
XMLObject convertValidators(const ParameterList &p, ValidatortoIDMap &validatorIDsMap) const
Convert all the validators.
Smart reference counting pointer class for automatic garbage collection.
static const std::string & getParameterListTagName()
static XMLObject convertDependency(RCP< const Dependency > dependency, const XMLParameterListWriter::EntryIDsMap &entryIDsMap, ValidatortoIDMap &validatorIDsMap)
Given a dependency converts the dependency to XML.
static const std::string & getNameAttributeName()
static const std::string & getNameAttributeName()
When serializing to XML, this string should be used as the name of the name attribute.
bool is_null() const
Returns true if the underlying pointer is null.