Teuchos - Trilinos Tools Package Version of the Day
Loading...
Searching...
No Matches
Teuchos_StandardDependencyXMLConverters.hpp
Go to the documentation of this file.
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
10#ifndef TEUCHOS_STANDARDDEPENDENCYXMLCONVERTERS_HPP
11#define TEUCHOS_STANDARDDEPENDENCYXMLCONVERTERS_HPP
12
22
23
24namespace Teuchos {
25
26
29class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT VisualDependencyXMLConverter : public DependencyXMLConverter{
30
31public:
32
35
50
63 const XMLObject& xmlObj,
66 bool showIf,
68
70
73
75 RCP<Dependency> convertXML(
76 const XMLObject& xmlObj,
81
83 void convertDependency(
88
90
91private:
92
95
97 static const std::string& getShowIfAttributeName(){
98 static const std::string showIfAttributeName = "showIf";
100 }
101
103
104};
105
169
188class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT StringVisualDependencyXMLConverter : public VisualDependencyXMLConverter{
189
190public:
191
194
196 void convertSpecialVisualAttributes(
200
202 RCP<VisualDependency> convertSpecialVisualAttributes(
203 const XMLObject& xmlObj,
206 bool showIf,
208
210 static const std::string& getStringValuesTagName(){
211 static const std::string stringValuesTagName = "StringValues";
212 return stringValuesTagName;
213 }
214
216
217private:
218
221
223 static const std::string& getStringTagName(){
224 static const std::string stringTagName = "String";
225 return stringTagName;
226 }
227
229 static const std::string& getValueAttributeName(){
230 static const std::string valueAttributeName = "value";
231 return valueAttributeName;
232 }
233
235
236};
237
251class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT BoolVisualDependencyXMLConverter : public VisualDependencyXMLConverter{
252
253public:
254
257
259 void convertSpecialVisualAttributes(
263
265 RCP<VisualDependency> convertSpecialVisualAttributes(
266 const XMLObject& xmlObj,
269 bool showIf,
271
273
274};
275
292template<class T>
317
318template<class T>
336
337template<class T>
360
377class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT ConditionVisualDependencyXMLConverter :
379{
380
381public:
382
385
387 void convertSpecialVisualAttributes(
391
393 RCP<VisualDependency> convertSpecialVisualAttributes(
394 const XMLObject& xmlObj,
397 bool showIf,
399
401
402};
403
404
424class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT StringValidatorDependencyXMLConverter :
426
427public:
428
431
433 void convertSpecialValidatorAttributes(
437
439 RCP<ValidatorDependency> convertSpecialValidatorAttributes(
440 const XMLObject& xmlObj,
443 const IDtoValidatorMap& validatorIDsMap) const;
444
446 static const std::string& getValuesAndValidatorsTag(){
447 static const std::string valuesAndValidatorsTag = "ValuesAndValidators";
449 }
450
452
453private:
456
458 static const std::string& getPairTag(){
459 static const std::string pairTag = "Pair";
460 return pairTag;
461 }
462
464 static const std::string& getValueAttributeName(){
465 static const std::string valueAttributeName = "value";
466 return valueAttributeName;
467 }
468
470 static const std::string& getValidatorIdAttributeName(){
471 static const std::string validatorIDAttributeName = "validatorId";
472 return validatorIDAttributeName;
473 }
474
476 static const std::string& getDefaultValidatorIdAttributeName(){
477 static const std::string defaultValidatorIdAttributeName =
478 "defaultValidatorId";
479 return defaultValidatorIdAttributeName;
480 }
481
483
484};
485
502class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT BoolValidatorDependencyXMLConverter : public ValidatorDependencyXMLConverter{
503
504public:
505
508
510 void convertSpecialValidatorAttributes(
514
516 RCP<ValidatorDependency> convertSpecialValidatorAttributes(
517 const XMLObject& xmlObj,
520 const IDtoValidatorMap& validatorIDsMap) const;
521
523
524private:
525
528
530 static const std::string& getFalseValidatorIdAttributeName(){
531 static const std::string falseValidatorIdAttributeName =
532 "falseValidatorId";
534 }
535
537 static const std::string& getTrueValidatorIdAttributeName(){
538 static const std::string trueValidatorIdAttributeName =
539 "trueValidatorId";
541 }
542
544
545};
546
569template<class T>
572
573public:
574
577
583
586 const XMLObject& xmlObj,
589 const IDtoValidatorMap& validatorIDsMap) const;
590
592 static const std::string& getRangesAndValidatorsTag(){
593 static const std::string rangesAndValidatorsTag = "RangesAndValidators";
595 }
596
598
599private:
602
603
605 static const std::string& getPairTag(){
606 static const std::string pairTag = "Pair";
607 return pairTag;
608 }
609
611 static const std::string& getMinAttributeName(){
612 static const std::string minAttributeName = "min";
613 return minAttributeName;
614 }
615
617 static const std::string& getMaxAttributeName(){
618 static const std::string maxAttributeName = "max";
619 return maxAttributeName;
620 }
621
622
624 static const std::string& getValidatorIdAttributeName(){
625 static const std::string validatorIdAttributeName = "validatorId";
626 return validatorIdAttributeName;
627 }
628
630 static const std::string& getDefaultValidatorIdAttributeName(){
631 static const std::string defaultValidatorIdAttributeName =
632 "defaultValidatorId";
633 return defaultValidatorIdAttributeName;
634 }
635
637
638};
639
640template<class T>
641void
646{
649
650 XMLObject rangesAndValidatorsTag(getRangesAndValidatorsTag());
651
652 castedDependency->getRangeToValidatorMap();
653 for(
655 it = castedDependency->getRangeToValidatorMap().begin();
656 it != castedDependency->getRangeToValidatorMap().end();
657 ++it)
658 {
659 T min = it->first.first;
660 T max = it->first.second;
661 if(validatorIDsMap.find(it->second) == validatorIDsMap.end()){
662 validatorIDsMap.insert(it->second);
663 }
665 validatorIDsMap.find(it->second)->second;
666 XMLObject pairTag(getPairTag());
667 pairTag.addAttribute(getMinAttributeName(), min);
668 pairTag.addAttribute(getMaxAttributeName(), max);
669 pairTag.addAttribute(getValidatorIdAttributeName(), validatorID);
671 }
674 castedDependency->getDefaultValidator();
678 }
679 xmlObj.addAttribute(
680 getDefaultValidatorIdAttributeName(),
681 validatorIDsMap.find(defaultValidator)->second);
682 }
683}
684
685template<class T>
688 const XMLObject& xmlObj,
692{
693
694 int result = xmlObj.findFirstChild(getRangesAndValidatorsTag());
697 "Error: All RangeValidatorDependencies must have a " <<
698 getRangesAndValidatorsTag() << " tag!" << std::endl << std::endl);
699
701
704 for(int i = 0 ; i < rangesAndValidatorsTag.numChildren(); ++i){
706 T min = child.getRequired<T>(getMinAttributeName());
707 T max = child.getRequired<T>(getMaxAttributeName());
710 getValidatorIdAttributeName());
711
715 "Could not find validator in given ValidatorIDsMap! " << std::endl <<
716 std::endl);
718 validatorIDsMap.find(currentID)->second;
719
720 rangesAndValidators.insert(
722 typename RangeValidatorDependency<T>::Range(min, max), validator));
723 }
724
726 if(xmlObj.hasAttribute(getDefaultValidatorIdAttributeName())){
729 getDefaultValidatorIdAttributeName());
733 "Could not find a validator (for the default validator) " <<
734 "corresponding to the ID " << defaultValiID <<
735 " in the given validatorIDsMap!" << std::endl << std::endl);
737 }
738
741}
742
747template<class DependeeType, class DependentType>
798
799template<class DependeeType, class DependentType>
802 const XMLObject& xmlObj,
805 const XMLParameterListReader::EntryIDsMap& /* entryIDsMap */,
806 const IDtoValidatorMap& /* validatorIDsMap */) const
807{
810 "A ArrayModifierDependency can only have 1 dependee!" <<
811 std::endl << std::endl);
813 int functionIndex = xmlObj.findFirstChild(FunctionObject::getXMLTagName());
814 if(functionIndex != -1){
817 }
818 return
819 getConcreteDependency(*(dependees.begin()), dependents, functionObject);
820}
821
822template<class DependeeType, class DependentType>
823void
841
842
857template<class DependeeType, class DependentType>
873
874template<class DependeeType, class DependentType>
885
886
903template<class DependeeType, class DependentType>
920
921template<class DependeeType, class DependentType>
932
949template<class DependeeType, class DependentType>
966
967template<class DependeeType, class DependentType>
978
979
980
981} // namespace Teuchos
982
983
984#endif // TEUCHOS_STANDARDDEPENDENCYXMLCONVERTERS_HPP
Converts back and forth between XML and Dependencies.
A database for FunctionObjectXMLConverters.
A collection of standard dependencies.
A collection of Exceptions thrown when converting Dependencys to and from XML.
A converter used to convert ArrayModifierDepdencies to and from 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 RCP< ArrayModifierDependency< DependeeType, DependentType > > getConcreteDependency(RCP< const ParameterEntry > dependee, Dependency::ParameterEntryList dependents, RCP< const SimpleFunctionObject< DependeeType > > function) const =0
Obtains a concrete ArrayModifierDependency given a dependee, dependtns, and a funciton object.
An abstract base class for converting Dependencies to and from XML.
std::set< RCP< ParameterEntry >, RCPComp > ParameterEntryList
A list of Dependees.
std::set< RCP< const ParameterEntry >, RCPConstComp > ConstParameterEntryList
A list of dependents.
static XMLObject convertFunctionObject(RCP< const FunctionObject > function)
Given a FunctionObject, converts the FunctionObject to XML.
static RCP< FunctionObject > convertXML(const XMLObject &xmlObject)
Given an XMLObject, converts the XMLObject to a FunctionObject.
static const std::string & getXMLTagName()
Returns the name of the XML tag used to indicate a funciton object.
Maps Validators to integers.
Thrown when the rangesAndValidators tag for the RangeValidatorDepencyConverter can't be found.
Thrown when converting a dependency that has validaotrs to and from XML. This excetpion indicates tha...
virtual RCP< ArrayModifierDependency< DependeeType, DependentType > > getConcreteDependency(RCP< const ParameterEntry > dependee, Dependency::ParameterEntryList dependents, RCP< const SimpleFunctionObject< DependeeType > > function) const
Obtains a concrete ArrayModifierDependency given a dependee, dependtns, and a funciton object.
void convertSpecialVisualAttributes(RCP< const VisualDependency > dependency, XMLObject &xmlObj, const XMLParameterListWriter::EntryIDsMap &entryIDsMap) const
Smart reference counting pointer class for automatic garbage collection.
RCP< T > rcp(const boost::shared_ptr< T > &sptr)
Conversion function that takes in a boost::shared_ptr object and spits out a Teuchos::RCP object.
bool nonnull(const RCP< T > &p)
Returns true if p.get()!=NULL.
void convertSpecialValidatorAttributes(RCP< const ValidatorDependency > dependency, XMLObject &xmlObj, ValidatortoIDMap &validatorIDsMap) const
A RangeValidatorDependency says the following about the relationship between two parameters: Dependen...
std::pair< Range, RCP< const ParameterEntryValidator > > RangeValidatorPair
Convenience typedef.
std::map< Range, RCP< const ParameterEntryValidator > > RangeToValidatorMap
Convenience typedef.
std::pair< T, T > Range
Convenience typedef.
static const std::string & getStringValuesTagName()
Gets the StringValues Tag.
Thrown when a Dependency has too many dependees specified in its XML.
A class for converting TwoDColDependencies to and from XML.
virtual RCP< ArrayModifierDependency< DependeeType, DependentType > > getConcreteDependency(RCP< const ParameterEntry > dependee, Dependency::ParameterEntryList dependents, RCP< const SimpleFunctionObject< DependeeType > > function) const
Obtains a concrete ArrayModifierDependency given a dependee, dependtns, and a funciton object.
A class for converting TwoDRowDependencies to and from XML.
virtual RCP< ArrayModifierDependency< DependeeType, DependentType > > getConcreteDependency(RCP< const ParameterEntry > dependee, Dependency::ParameterEntryList dependents, RCP< const SimpleFunctionObject< DependeeType > > function) const
Obtains a concrete ArrayModifierDependency given a dependee, dependtns, and a funciton object.
virtual RCP< ValidatorDependency > convertSpecialValidatorAttributes(const XMLObject &xmlObj, RCP< const ParameterEntry > dependee, const Dependency::ParameterEntryList dependents, const IDtoValidatorMap &validatorIDsMap) const =0
Converts any special aspects of a specific validator dependency from xml.
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.
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.
virtual RCP< VisualDependency > convertSpecialVisualAttributes(const XMLObject &xmlObj, const Dependency::ConstParameterEntryList dependees, const Dependency::ParameterEntryList dependets, bool showIf, const XMLParameterListReader::EntryIDsMap &entryIDsMap) const =0
Converts any special aspects of a specific visual dependency from 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.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...