Teuchos - Trilinos Tools Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
15 namespace Teuchos{
16 
18  const XMLObject& xmlObj,
19  const XMLParameterListReader::EntryIDsMap& entryIDsMap) const
20 {
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 {
35  rcp_dynamic_cast<const BoolLogicCondition>(condition, true);
36 
37  const Condition::ConstConditionList conditions = castedCon->getConditions();
38  for(
39  Condition::ConstConditionList::const_iterator it = conditions.begin();
40  it != conditions.end();
41  ++it)
42  {
43  xmlObj.addChild(ConditionXMLConverterDB::convertCondition(*it, entryIDsMap));
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 =
82  rcp_dynamic_cast<const NotCondition>(condition);
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 =
109  rcp_dynamic_cast<const ParameterCondition>(condition, true);
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 {
149  RCP<const StringCondition> castedCon =
150  rcp_dynamic_cast<const StringCondition>(condition, true);
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 
174  RCP<const ParameterCondition> /* condition */, XMLObject& /* xmlObj */) const
175 {}
176 
177 
178 } //namespace Teuchos
179 
180 
void convertCondition(const RCP< const Condition > condition, XMLObject &xmlObj, const XMLParameterListWriter::EntryIDsMap &entryIDsMap) const
RCP< ParameterCondition > getSpecificParameterCondition(const XMLObject &xmlObj, RCP< ParameterEntry > parameterEntry) const
A Bool Logic Condition that returns the result or perfroming a logical OR on the conditions.
virtual RCP< Condition > convertXML(const XMLObject &xmlObj, const XMLParameterListReader::EntryIDsMap &entryIDsMap) const
const std::string & getTag() const
Return the tag of the current node.
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
A collection of Exceptions thrown when converting Conditions to and from XML.
static RCP< Condition > convertXML(const XMLObject &xmlObject, const XMLParameterListReader::EntryIDsMap &entryIDsMap)
Given an XMLObject and IDtoConditionMap, converts the XMLObject to a Condition.
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...
A Bool Logic Condition that returns the result or perfroming a logical AND on the conditions...
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
void addChild(const XMLObject &child)
Add a child node to the node.
A Not condition returns the result of performing a logical NOT on a given condition.
RCP< BoolLogicCondition > getSpecificBoolLogicCondition(Condition::ConstConditionList &conditions) const
Thrown when a referenced ParameterEntry can&#39;t be found.
Thrown when a StringConditon is missing it&#39;s Value tag.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
Representation of an XML data tree. XMLObject is a ref-counted handle to a XMLObjectImplem object...
A database for ConditionXMLConverters.
A String Condition is a Parameter Condition that evaluates whether or not a string parameter has take...
std::map< RCP< const ParameterEntry >, ParameterEntry::ParameterEntryID, RCPConstComp > EntryIDsMap
void convertCondition(const RCP< const Condition > condition, XMLObject &xmlObj, const XMLParameterListWriter::EntryIDsMap &entryIDsMap) const
void addAttribute(const std::string &name, T value)
Lookup whether or not Doubles are allowed.
A Bool Logic Condition that returns the result or perfroming a logical EQUALS on the conditions...
std::vector< T >::const_iterator const_iterator
The type of a const forward iterator.
virtual RCP< BoolLogicCondition > getSpecificBoolLogicCondition(Condition::ConstConditionList &conditions) const =0
Gets the specific BoolLogicCondition to be returned by this conveter when converting from XML...
RCP< BoolLogicCondition > getSpecificBoolLogicCondition(Condition::ConstConditionList &conditions) const
A Bool Condition is a Parameter Condition that evaluates whether or not a Boolean parameter is ture...
std::map< ParameterEntry::ParameterEntryID, RCP< ParameterEntry > > EntryIDsMap
Convenience typedef.
void push_back(const value_type &x)
static XMLObject convertCondition(RCP< const Condition > condition, const XMLParameterListWriter::EntryIDsMap &entryIDsMap)
Given a condition and ConditiontoIDMap, converts the condition to XML.
virtual void addSpecificXMLTraits(RCP< const ParameterCondition > condition, XMLObject &xmlObj) const =0
Adds specific xml traits to the xmlObj for a particular ParmaterCondtion.
RCP< BoolLogicCondition > getSpecificBoolLogicCondition(Condition::ConstConditionList &conditions) const
int numChildren() const
Return the number of child nodes owned by this node.
void addSpecificXMLTraits(RCP< const ParameterCondition > condition, XMLObject &xmlObj) const
A collection of Exceptions that can be potentially thrown when converting a ParameterList to and from...
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
An abstract parent class for all Bool Logic Conditions.
Smart reference counting pointer class for automatic garbage collection.
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...
const XMLObject & getChild(int i) const
Return the i-th child node.
void addSpecificXMLTraits(RCP< const ParameterCondition > condition, XMLObject &xmlObj) const
A collection of standard ConditionXMLConverters.
An Abstract Base class for all ParameterConditions.
const std::string & getRequired(const std::string &name) const
Get an attribute, throwing an std::exception if it is not found.
virtual RCP< Condition > convertXML(const XMLObject &xmlObj, const XMLParameterListReader::EntryIDsMap &entryIDsMap) const
Replacement for std::vector that is compatible with the Teuchos Memory Management classes...