Teuchos Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
Teuchos_StandardConditionXMLConverters.cpp
Go to the documentation of this file.
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
47namespace 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(
72 it != conditions.end();
73 ++it)
74 {
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{
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(
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()){
173 }
174 }
175 return rcp(new StringCondition(parameterEntry, values));
176}
177
179 RCP<const ParameterCondition> condition, XMLObject& xmlObj) const
180{
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());
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
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.
Replacement for std::vector that is compatible with the Teuchos Memory Management classes.
iterator begin()
void push_back(const value_type &x)
std::vector< T >::const_iterator const_iterator
The type of a const forward 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.
static const std::string & getParameterEntryIdAttributeName()
gets the ParameterEntryID attribute name.
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.
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...
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.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.