Teuchos - Trilinos Tools Package Version of the Day
Loading...
Searching...
No Matches
Teuchos_StandardDependencyXMLConverters.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
12
13
14namespace Teuchos{
15
16
18 const XMLObject& xmlObj,
22 const IDtoValidatorMap& /*validatorIDsMap*/) const
23{
24 bool showIf = xmlObj.getWithDefault(
25 getShowIfAttributeName(), VisualDependency::getShowIfDefaultValue());
27 xmlObj,
30 showIf,
32}
33
46
61
72
73
94
97 const XMLObject& xmlObj,
100 bool showIf,
101 const XMLParameterListReader::EntryIDsMap& /*entryIDsMap*/) const
102{
105 "A StringVisualDependency can only have 1 dependee!" <<
106 std::endl << std::endl);
107
109 int valuesTagIndex = xmlObj.findFirstChild(getStringValuesTagName());
110
113 "Couldn't find " << getStringValuesTagName() << " tag for a " <<
114 "StringVisualDependency!" << std::endl <<std::endl);
115
117
118 for(int i=0; i<valuesTag.numChildren(); ++i){
119 XMLObject child = valuesTag.getChild(i);
120 valueList.push_back(child.getRequired(getValueAttributeName()));
121 }
122
123 return rcp(
125 *(dependees.begin()),
127 valueList,
128 showIf));
129}
130
136
139 const XMLObject& /* xmlObj */,
142 bool showIf,
143 const XMLParameterListReader::EntryIDsMap& /*entryIDsMap*/) const
144{
147 "A BoolVisualDependency can only have 1 dependee!" <<
148 std::endl << std::endl);
149 return rcp(new BoolVisualDependency(
150 *(dependees.begin()), dependents, showIf));
151}
152
164
183
184void
189{
194 castedDependency->getValuesAndValidators();
195 for(
196 StringValidatorDependency::ValueToValidatorMap::const_iterator it =
197 valuesAndValidators.begin();
198 it != valuesAndValidators.end();
199 ++it)
200 {
201 XMLObject pairTag(getPairTag());
202 pairTag.addAttribute(getValueAttributeName(), it->first);
203 if(validatorIDsMap.find(it->second) == validatorIDsMap.end()){
204 validatorIDsMap.insert(it->second);
205 }
206 pairTag.addAttribute(getValidatorIdAttributeName(),
207 validatorIDsMap.find(it->second)->second);
208 valueMapTag.addChild(pairTag);
209 }
210 xmlObj.addChild(valueMapTag);
212 castedDependency->getDefaultValidator();
213 if(nonnull(defaultVali)){
216 }
217 xmlObj.addAttribute(
218 getDefaultValidatorIdAttributeName(),
219 validatorIDsMap.find(defaultVali)->second);
220 }
221}
222
225 const XMLObject& xmlObj,
229{
232 xmlObj.findFirstChild(getValuesAndValidatorsTag());
233
236 "Error: All StringValidatorDependencies must have a " <<
237 getValuesAndValidatorsTag() << "tag!" << std::endl << std::endl);
238
240 for(int i=0; i < valuesAndValidatorTag.numChildren(); ++i){
242 std::string value = child.getRequired(getValueAttributeName());
245 getValidatorIdAttributeName());
248 "Could not find a validator corresponding to the ID " << valiID <<
249 " in the given validatorIDsMap!" << std::endl << std::endl);
251 validatorIDsMap.find(valiID)->second;
252 valueValidatorMap.insert(
254 }
255
257 if(xmlObj.hasAttribute(getDefaultValidatorIdAttributeName())){
260 getDefaultValidatorIdAttributeName());
264 "Could not find a validator (for the default validator) " <<
265 "corresponding to the ID " << defaultValiID <<
266 " in the given validatorIDsMap!" << std::endl << std::endl);
268 }
269
272}
273
274void
279{
282
284 castedDependency->getTrueValidator();
286 castedDependency->getFalseValidator();
287
288 if(nonnull(trueVali)){
289 if(validatorIDsMap.find(castedDependency->getTrueValidator()) ==
290 validatorIDsMap.end()){
291 validatorIDsMap.insert(castedDependency->getTrueValidator());
292 }
293 xmlObj.addAttribute(
294 getTrueValidatorIdAttributeName(),
295 validatorIDsMap.find(castedDependency->getTrueValidator())->second);
296 }
297
298 if(nonnull(falseVali)){
299 if(validatorIDsMap.find(falseVali) ==
300 validatorIDsMap.end()){
302 }
303 xmlObj.addAttribute(
304 getFalseValidatorIdAttributeName(),
305 validatorIDsMap.find(falseVali)->second);
306 }
307
308}
309
312 const XMLObject& xmlObj,
316{
317
320
321 if(xmlObj.hasAttribute(getTrueValidatorIdAttributeName())){
322
325 getTrueValidatorIdAttributeName());
326
329 ==
330 validatorIDsMap.end(),
332 "Could not find a Validator for the True validator " <<
333 "with ID " << trueID <<
334 " in the given validatorIDsMap!" << std::endl << std::endl);
335
337 validatorIDsMap.find(trueID)->second;
338 }
339
340
341 if(xmlObj.hasAttribute(getFalseValidatorIdAttributeName())){
344 getFalseValidatorIdAttributeName());
345
348 ==
349 validatorIDsMap.end(),
351 "Could not find a Validator for the False validator " <<
352 "with ID " << falseID <<
353 " in the given validatorIDsMap!" << std::endl << std::endl);
354
356 validatorIDsMap.find(falseID)->second;
357 }
358
359 return rcp(new BoolValidatorDependency(
361}
362
363
364
365} //namespace Teuchos
366
A database for ConditionXMLConverters.
A collection of standard DependencyXMLConverters.
std::vector< std::string >::const_iterator const_iterator
The type of a const forward iterator.
void convertSpecialValidatorAttributes(RCP< const ValidatorDependency > dependency, XMLObject &xmlObj, ValidatortoIDMap &validatorIDsMap) const
A BoolValidatorDependency says the following about the relationship between two parameters: Dependeni...
void convertSpecialVisualAttributes(RCP< const VisualDependency > dependency, XMLObject &xmlObj, const XMLParameterListWriter::EntryIDsMap &entryIDsMap) const
A bool visual dependency says the following about the relationship between two elements in a Paramete...
void convertSpecialVisualAttributes(RCP< const VisualDependency > dependency, XMLObject &xmlObj, const XMLParameterListWriter::EntryIDsMap &entryIDsMap) const
A condition visual dependency says the following about the relationship between elements in a Paramet...
static RCP< Condition > convertXML(const XMLObject &xmlObject, const XMLParameterListReader::EntryIDsMap &entryIDsMap)
Given an XMLObject and IDtoConditionMap, converts the XMLObject to a Condition.
static XMLObject convertCondition(RCP< const Condition > condition, const XMLParameterListWriter::EntryIDsMap &entryIDsMap)
Given a condition and ConditiontoIDMap, converts the condition to XML.
static const std::string & getXMLTagName()
std::set< RCP< ParameterEntry >, RCPComp > ParameterEntryList
A list of Dependees.
std::set< RCP< const ParameterEntry >, RCPConstComp > ConstParameterEntryList
A list of dependents.
Maps Validators to integers.
Thrown when no condtion tag is found when converting a ConditionVisualDependency from XML.
Thrown when converting a dependency that has validaotrs to and from XML. This excetpion indicates tha...
Thrown when converting a StrinvValidatorDependcny from XML and no valuesAndValidators tag is found.
Smart reference counting pointer class for automatic garbage collection.
void convertSpecialValidatorAttributes(RCP< const ValidatorDependency > dependency, XMLObject &xmlObj, ValidatortoIDMap &validatorIDsMap) const
A StringValidatorDependency says the following about the relationship between two parameters: Depende...
std::pair< std::string, RCP< const ParameterEntryValidator > > ValueToValidatorPair
Conveniece typedef.
std::map< std::string, RCP< const ParameterEntryValidator > > ValueToValidatorMap
Conveniece typedef.
static const std::string & getStringValuesTagName()
Gets the StringValues Tag.
void convertSpecialVisualAttributes(RCP< const VisualDependency > dependency, XMLObject &xmlObj, const XMLParameterListWriter::EntryIDsMap &entryIDsMap) const
A string visual dependency says the following about the relationship between two elements in a Parame...
Thrown when a Dependency has too many dependees specified in its XML.
void convertDependency(const RCP< const Dependency > dependency, XMLObject &xmlObj, const XMLParameterListWriter::EntryIDsMap &entryIDsMap, ValidatortoIDMap &validatorIDsMap) const
RCP< Dependency > convertXML(const XMLObject &xmlObj, const Dependency::ConstParameterEntryList dependees, const Dependency::ParameterEntryList dependets, const XMLParameterListReader::EntryIDsMap &entryIDsMap, const IDtoValidatorMap &validatorIDsMap) const
virtual void convertSpecialValidatorAttributes(RCP< const ValidatorDependency > dependency, XMLObject &xmlObj, ValidatortoIDMap &validatorIDsMap) const =0
Converts any special aspects of a specific validator dependency to xml.
A class for mapping validators to integers.
Thrown when a StringVisualDependency is being converted from XML and no Values tag is found.
void convertDependency(const RCP< const Dependency > dependency, XMLObject &xmlObj, const XMLParameterListWriter::EntryIDsMap &entryIDsMap, ValidatortoIDMap &validatorIDsMap) const
RCP< Dependency > convertXML(const XMLObject &xmlObj, const Dependency::ConstParameterEntryList dependees, const Dependency::ParameterEntryList dependets, const XMLParameterListReader::EntryIDsMap &entryIDsMap, const IDtoValidatorMap &validatorIDsMap) const
virtual void convertSpecialVisualAttributes(RCP< const VisualDependency > dependency, XMLObject &xmlObj, const XMLParameterListWriter::EntryIDsMap &entryIDsMap) const =0
Converts any special aspects of a specific visual dependency to xml.
Representation of an XML data tree. XMLObject is a ref-counted handle to a XMLObjectImplem object,...
std::map< ParameterEntry::ParameterEntryID, RCP< ParameterEntry > > EntryIDsMap
Convenience typedef.
std::map< RCP< const ParameterEntry >, ParameterEntry::ParameterEntryID, RCPConstComp > EntryIDsMap
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
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,...
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.