Teuchos - Trilinos Tools Package Version of the Day
Loading...
Searching...
No Matches
Teuchos_StandardConditionXMLConverters.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
14
15namespace Teuchos{
16
18 const XMLObject& xmlObj,
19 const XMLParameterListReader::EntryIDsMap& entryIDsMap) const
20{
21 Condition::ConstConditionList conditions;
22 for(int i = 0; i < xmlObj.numChildren(); ++i){
23 conditions.push_back(
24 ConditionXMLConverterDB::convertXML(xmlObj.getChild(i), entryIDsMap));
25 }
26 return getSpecificBoolLogicCondition(conditions);
27}
28
30 const RCP<const Condition> condition,
31 XMLObject& xmlObj,
32 const XMLParameterListWriter::EntryIDsMap& entryIDsMap) const
33{
36
37 const Condition::ConstConditionList conditions = castedCon->getConditions();
38 for(
40 it != conditions.end();
41 ++it)
42 {
44 }
45}
46
49 Condition::ConstConditionList& conditions) const
50{
51 return rcp( new OrCondition(conditions));
52}
53
56 Condition::ConstConditionList& conditions) const
57{
58 return rcp( new AndCondition(conditions));
59}
60
63 Condition::ConstConditionList& conditions) const
64{
65 return rcp( new EqualsCondition(conditions));
66}
67
69 const XMLObject& xmlObj,
70 const XMLParameterListReader::EntryIDsMap& entryIDsMap) const
71{
72 return rcp(new NotCondition(
73 ConditionXMLConverterDB::convertXML(xmlObj.getChild(0), entryIDsMap)));
74}
75
77 const RCP<const Condition> condition,
78 XMLObject& xmlObj,
79 const XMLParameterListWriter::EntryIDsMap& entryIDsMap) const
80{
81 RCP<const NotCondition> castedCondition =
84 castedCondition->getChildCondition(), entryIDsMap));
85}
86
88 const XMLObject& xmlObj,
89 const XMLParameterListReader::EntryIDsMap& entryIDsMap) const
90{
93 getParameterEntryIdAttributeName());
95 entryIDsMap.find(paramID) == entryIDsMap.end(),
97 "Can't find a parameter entry with id " << paramID << " in the "
98 "given entryIDsMap!" << std::endl << std::endl);
100 xmlObj, entryIDsMap.find(paramID)->second);
101}
102
104 const RCP<const Condition> condition,
105 XMLObject& xmlObj,
106 const XMLParameterListWriter::EntryIDsMap& entryIDsMap) const
107{
108 RCP<const ParameterCondition> castedCondition =
110
112 entryIDsMap.find(castedCondition->getParameter()) == entryIDsMap.end(),
114 "Couldn't find an id for the parameter in the given entryIDsMap!" <<
115 std::endl << std::endl);
116
117 xmlObj.addAttribute(
118 getParameterEntryIdAttributeName(),
119 entryIDsMap.find(castedCondition->getParameter())->second);
120
121 addSpecificXMLTraits(castedCondition, xmlObj);
122}
123
126 const XMLObject& xmlObj,
127 RCP<ParameterEntry> parameterEntry) const
128{
130 int result = xmlObj.findFirstChild(getValuesTagName());
131 TEUCHOS_TEST_FOR_EXCEPTION(result == -1,
133 "A StringCondtion must have a tag with the name " <<
134 getValuesTagName() << " as one of it's children!");
135
136 XMLObject valuesTag = xmlObj.getChild(result);
137 for(int i=0; i< valuesTag.numChildren(); ++i){
138 XMLObject child = valuesTag.getChild(i);
139 if(child.getTag() == getStringTagName()){
140 values.append(child.getRequired(getStringValueAttributeName()));
141 }
142 }
143 return rcp(new StringCondition(parameterEntry, values));
144}
145
147 RCP<const ParameterCondition> condition, XMLObject& xmlObj) const
148{
151 XMLObject valueTag(getValuesTagName());
152 for(
154 castedCon->getValueList().begin();
155 it != castedCon->getValueList().end();
156 ++it)
157 {
158 XMLObject stringTag(getStringTagName());
159 stringTag.addAttribute(getStringValueAttributeName(), *it);
160 valueTag.addChild(stringTag);
161 }
162 xmlObj.addChild(valueTag);
163}
164
167 const XMLObject& /* xmlObj */,
168 RCP<ParameterEntry> parameterEntry) const
169{
170 return rcp(new BoolCondition(parameterEntry));
171}
172
176
177
178} //namespace Teuchos
179
180
A database for ConditionXMLConverters.
A collection of standard ConditionXMLConverters.
A collection of Exceptions thrown when converting Conditions to and from XML.
A collection of Exceptions that can be potentially thrown when converting a ParameterList to and from...
RCP< BoolLogicCondition > getSpecificBoolLogicCondition(Condition::ConstConditionList &conditions) const
A Bool Logic Condition that returns the result or perfroming a logical AND on the conditions.
void push_back(const value_type &x)
std::vector< Teuchos::RCP< const Condition > >::const_iterator const_iterator
Array< T > & append(const T &x)
Add a new entry at the end of the array.
RCP< ParameterCondition > getSpecificParameterCondition(const XMLObject &xmlObj, RCP< ParameterEntry > parameterEntry) const
void addSpecificXMLTraits(RCP< const ParameterCondition > condition, XMLObject &xmlObj) const
A Bool Condition is a Parameter Condition that evaluates whether or not a Boolean parameter is ture.
virtual RCP< BoolLogicCondition > getSpecificBoolLogicCondition(Condition::ConstConditionList &conditions) const =0
Gets the specific BoolLogicCondition to be returned by this conveter when converting from XML.
virtual RCP< Condition > convertXML(const XMLObject &xmlObj, const XMLParameterListReader::EntryIDsMap &entryIDsMap) const
void convertCondition(const RCP< const Condition > condition, XMLObject &xmlObj, const XMLParameterListWriter::EntryIDsMap &entryIDsMap) const
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.
RCP< BoolLogicCondition > getSpecificBoolLogicCondition(Condition::ConstConditionList &conditions) const
A Bool Logic Condition that returns the result or perfroming a logical EQUALS on the conditions.
Thrown when a referenced ParameterEntry can't be found.
Thrown when a StringConditon is missing it's Value tag.
void convertCondition(const RCP< const Condition > condition, XMLObject &xmlObj, const XMLParameterListWriter::EntryIDsMap &entryIDsMap) const
virtual RCP< Condition > convertXML(const XMLObject &xmlObj, const XMLParameterListReader::EntryIDsMap &entryIDsMap) const
A Not condition returns the result of performing a logical NOT on a given condition.
RCP< BoolLogicCondition > getSpecificBoolLogicCondition(Condition::ConstConditionList &conditions) const
A Bool Logic Condition that returns the result or perfroming a logical OR on the conditions.
void convertCondition(const RCP< const Condition > condition, XMLObject &xmlObj, const XMLParameterListWriter::EntryIDsMap &entryIDsMap) const
virtual void addSpecificXMLTraits(RCP< const ParameterCondition > condition, XMLObject &xmlObj) const =0
Adds specific xml traits to the xmlObj for a particular ParmaterCondtion.
virtual RCP< ParameterCondition > getSpecificParameterCondition(const XMLObject &xmlObj, RCP< ParameterEntry > parameterEntry) const =0
Gets the specific ParameterCondition to be returned by this conveter when converting from XML.
virtual RCP< Condition > convertXML(const XMLObject &xmlObj, const XMLParameterListReader::EntryIDsMap &entryIDsMap) const
Smart reference counting pointer class for automatic garbage collection.
RCP< T2 > rcp_dynamic_cast(const RCP< T1 > &p1, bool throw_on_fail=false)
Dynamic cast of underlying RCP type from T1* to T2*.
void addSpecificXMLTraits(RCP< const ParameterCondition > condition, XMLObject &xmlObj) const
RCP< ParameterCondition > getSpecificParameterCondition(const XMLObject &xmlObj, RCP< ParameterEntry > parameterEntry) const
A String Condition is a Parameter Condition that evaluates whether or not a string parameter has take...
Array< std::string > ValueList
Convience typedef representing an array of strings.
Representation of an XML data tree. XMLObject is a ref-counted handle to a XMLObjectImplem object,...
void addChild(const XMLObject &child)
Add a child node to the node.
const std::string & getRequired(const std::string &name) const
Get an attribute, throwing an std::exception if it is not found.
const std::string & getTag() const
Return the tag of the current node.
void addAttribute(const std::string &name, T value)
Lookup whether or not Doubles are allowed.
const XMLObject & getChild(int i) const
Return the i-th child node.
int findFirstChild(std::string tagName) const
Returns the index of the first child found with the given tag name. Returns -1 if no child is found.
int numChildren() const
Return the number of child nodes owned by this node.
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.
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.