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 //
4 // Teuchos: Common Tools Package
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
46 
47 namespace Teuchos{
48 
50  const XMLObject& xmlObj,
51  const XMLParameterListReader::EntryIDsMap& entryIDsMap) const
52 {
54  for(int i = 0; i < xmlObj.numChildren(); ++i){
55  conditions.push_back(
56  ConditionXMLConverterDB::convertXML(xmlObj.getChild(i), entryIDsMap));
57  }
58  return getSpecificBoolLogicCondition(conditions);
59 }
60 
62  const RCP<const Condition> condition,
63  XMLObject& xmlObj,
64  const XMLParameterListWriter::EntryIDsMap& entryIDsMap) const
65 {
67  rcp_dynamic_cast<const BoolLogicCondition>(condition, true);
68 
69  const Condition::ConstConditionList conditions = castedCon->getConditions();
70  for(
71  Condition::ConstConditionList::const_iterator it = conditions.begin();
72  it != conditions.end();
73  ++it)
74  {
75  xmlObj.addChild(ConditionXMLConverterDB::convertCondition(*it, entryIDsMap));
76  }
77 }
78 
81  Condition::ConstConditionList& conditions) const
82 {
83  return rcp( new OrCondition(conditions));
84 }
85 
88  Condition::ConstConditionList& conditions) const
89 {
90  return rcp( new AndCondition(conditions));
91 }
92 
95  Condition::ConstConditionList& conditions) const
96 {
97  return rcp( new EqualsCondition(conditions));
98 }
99 
101  const XMLObject& xmlObj,
102  const XMLParameterListReader::EntryIDsMap& entryIDsMap) const
103 {
104  return rcp(new NotCondition(
105  ConditionXMLConverterDB::convertXML(xmlObj.getChild(0), entryIDsMap)));
106 }
107 
109  const RCP<const Condition> condition,
110  XMLObject& xmlObj,
111  const XMLParameterListWriter::EntryIDsMap& entryIDsMap) const
112 {
113  RCP<const NotCondition> castedCondition =
114  rcp_dynamic_cast<const NotCondition>(condition);
116  castedCondition->getChildCondition(), entryIDsMap));
117 }
118 
120  const XMLObject& xmlObj,
121  const XMLParameterListReader::EntryIDsMap& entryIDsMap) const
122 {
125  getParameterEntryIdAttributeName());
127  entryIDsMap.find(paramID) == entryIDsMap.end(),
129  "Can't find a parameter entry with id " << paramID << " in the "
130  "given entryIDsMap!" << std::endl << std::endl);
132  xmlObj, entryIDsMap.find(paramID)->second);
133 }
134 
136  const RCP<const Condition> condition,
137  XMLObject& xmlObj,
138  const XMLParameterListWriter::EntryIDsMap& entryIDsMap) const
139 {
140  RCP<const ParameterCondition> castedCondition =
141  rcp_dynamic_cast<const ParameterCondition>(condition, true);
142 
144  entryIDsMap.find(castedCondition->getParameter()) == entryIDsMap.end(),
146  "Couldn't find an id for the parameter in the given entryIDsMap!" <<
147  std::endl << std::endl);
148 
149  xmlObj.addAttribute(
150  getParameterEntryIdAttributeName(),
151  entryIDsMap.find(castedCondition->getParameter())->second);
152 
153  addSpecificXMLTraits(castedCondition, xmlObj);
154 }
155 
158  const XMLObject& xmlObj,
159  RCP<ParameterEntry> parameterEntry) const
160 {
162  int result = xmlObj.findFirstChild(getValuesTagName());
163  TEUCHOS_TEST_FOR_EXCEPTION(result == -1,
165  "A StringCondtion must have a tag with the name " <<
166  getValuesTagName() << " as one of it's children!");
167 
168  XMLObject valuesTag = xmlObj.getChild(result);
169  for(int i=0; i< valuesTag.numChildren(); ++i){
170  XMLObject child = valuesTag.getChild(i);
171  if(child.getTag() == getStringTagName()){
172  values.append(child.getRequired(getStringValueAttributeName()));
173  }
174  }
175  return rcp(new StringCondition(parameterEntry, values));
176 }
177 
179  RCP<const ParameterCondition> condition, XMLObject& xmlObj) const
180 {
181  RCP<const StringCondition> castedCon =
182  rcp_dynamic_cast<const StringCondition>(condition, true);
183  XMLObject valueTag(getValuesTagName());
184  for(
186  castedCon->getValueList().begin();
187  it != castedCon->getValueList().end();
188  ++it)
189  {
190  XMLObject stringTag(getStringTagName());
191  stringTag.addAttribute(getStringValueAttributeName(), *it);
192  valueTag.addChild(stringTag);
193  }
194  xmlObj.addChild(valueTag);
195 }
196 
199  const XMLObject& /* xmlObj */,
200  RCP<ParameterEntry> parameterEntry) const
201 {
202  return rcp(new BoolCondition(parameterEntry));
203 }
204 
206  RCP<const ParameterCondition> /* condition */, XMLObject& /* xmlObj */) const
207 {}
208 
209 
210 } //namespace Teuchos
211 
212 
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...