Teuchos - Trilinos Tools Package Version of the Day
Loading...
Searching...
No Matches
Teuchos_StandardDependencyXMLConverters.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
44
45
46namespace Teuchos{
47
48
50 const XMLObject& xmlObj,
54 const IDtoValidatorMap& /*validatorIDsMap*/) const
55{
56 bool showIf = xmlObj.getWithDefault(
57 getShowIfAttributeName(), VisualDependency::getShowIfDefaultValue());
59 xmlObj,
62 showIf,
64}
65
78
93
104
105
126
129 const XMLObject& xmlObj,
132 bool showIf,
133 const XMLParameterListReader::EntryIDsMap& /*entryIDsMap*/) const
134{
137 "A StringVisualDependency can only have 1 dependee!" <<
138 std::endl << std::endl);
139
141 int valuesTagIndex = xmlObj.findFirstChild(getStringValuesTagName());
142
145 "Couldn't find " << getStringValuesTagName() << " tag for a " <<
146 "StringVisualDependency!" << std::endl <<std::endl);
147
149
150 for(int i=0; i<valuesTag.numChildren(); ++i){
151 XMLObject child = valuesTag.getChild(i);
152 valueList.push_back(child.getRequired(getValueAttributeName()));
153 }
154
155 return rcp(
157 *(dependees.begin()),
159 valueList,
160 showIf));
161}
162
168
171 const XMLObject& /* xmlObj */,
174 bool showIf,
175 const XMLParameterListReader::EntryIDsMap& /*entryIDsMap*/) const
176{
179 "A BoolVisualDependency can only have 1 dependee!" <<
180 std::endl << std::endl);
181 return rcp(new BoolVisualDependency(
182 *(dependees.begin()), dependents, showIf));
183}
184
196
215
216void
221{
226 castedDependency->getValuesAndValidators();
227 for(
228 StringValidatorDependency::ValueToValidatorMap::const_iterator it =
229 valuesAndValidators.begin();
230 it != valuesAndValidators.end();
231 ++it)
232 {
233 XMLObject pairTag(getPairTag());
234 pairTag.addAttribute(getValueAttributeName(), it->first);
235 if(validatorIDsMap.find(it->second) == validatorIDsMap.end()){
236 validatorIDsMap.insert(it->second);
237 }
238 pairTag.addAttribute(getValidatorIdAttributeName(),
239 validatorIDsMap.find(it->second)->second);
240 valueMapTag.addChild(pairTag);
241 }
242 xmlObj.addChild(valueMapTag);
244 castedDependency->getDefaultValidator();
245 if(nonnull(defaultVali)){
248 }
249 xmlObj.addAttribute(
250 getDefaultValidatorIdAttributeName(),
251 validatorIDsMap.find(defaultVali)->second);
252 }
253}
254
257 const XMLObject& xmlObj,
261{
264 xmlObj.findFirstChild(getValuesAndValidatorsTag());
265
268 "Error: All StringValidatorDependencies must have a " <<
269 getValuesAndValidatorsTag() << "tag!" << std::endl << std::endl);
270
272 for(int i=0; i < valuesAndValidatorTag.numChildren(); ++i){
274 std::string value = child.getRequired(getValueAttributeName());
277 getValidatorIdAttributeName());
280 "Could not find a validator corresponding to the ID " << valiID <<
281 " in the given validatorIDsMap!" << std::endl << std::endl);
283 validatorIDsMap.find(valiID)->second;
284 valueValidatorMap.insert(
286 }
287
289 if(xmlObj.hasAttribute(getDefaultValidatorIdAttributeName())){
292 getDefaultValidatorIdAttributeName());
296 "Could not find a validator (for the default validator) " <<
297 "corresponding to the ID " << defaultValiID <<
298 " in the given validatorIDsMap!" << std::endl << std::endl);
300 }
301
304}
305
306void
311{
314
316 castedDependency->getTrueValidator();
318 castedDependency->getFalseValidator();
319
320 if(nonnull(trueVali)){
321 if(validatorIDsMap.find(castedDependency->getTrueValidator()) ==
322 validatorIDsMap.end()){
323 validatorIDsMap.insert(castedDependency->getTrueValidator());
324 }
325 xmlObj.addAttribute(
326 getTrueValidatorIdAttributeName(),
327 validatorIDsMap.find(castedDependency->getTrueValidator())->second);
328 }
329
330 if(nonnull(falseVali)){
331 if(validatorIDsMap.find(falseVali) ==
332 validatorIDsMap.end()){
334 }
335 xmlObj.addAttribute(
336 getFalseValidatorIdAttributeName(),
337 validatorIDsMap.find(falseVali)->second);
338 }
339
340}
341
344 const XMLObject& xmlObj,
348{
349
352
353 if(xmlObj.hasAttribute(getTrueValidatorIdAttributeName())){
354
357 getTrueValidatorIdAttributeName());
358
361 ==
362 validatorIDsMap.end(),
364 "Could not find a Validator for the True validator " <<
365 "with ID " << trueID <<
366 " in the given validatorIDsMap!" << std::endl << std::endl);
367
369 validatorIDsMap.find(trueID)->second;
370 }
371
372
373 if(xmlObj.hasAttribute(getFalseValidatorIdAttributeName())){
376 getFalseValidatorIdAttributeName());
377
380 ==
381 validatorIDsMap.end(),
383 "Could not find a Validator for the False validator " <<
384 "with ID " << falseID <<
385 " in the given validatorIDsMap!" << std::endl << std::endl);
386
388 validatorIDsMap.find(falseID)->second;
389 }
390
391 return rcp(new BoolValidatorDependency(
393}
394
395
396
397} //namespace Teuchos
398
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 depdencies 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.