10 #ifndef TEUCHOS_STANDARDVALIDATORXMLCONVERTERS_HPP
11 #define TEUCHOS_STANDARDVALIDATORXMLCONVERTERS_HPP
18 #include "Teuchos_StandardParameterEntryValidators.hpp"
65 template<
class IntegralType>
86 #ifdef HAVE_TEUCHOS_DEBUG
89 getDummyValidator()
const{
103 static const std::string& getIntegralValueAttributeName() {
104 static const std::string integralValueAttributeName_ =
"integralValue";
105 return integralValueAttributeName_;
109 static const std::string& getStringTagName() {
110 static const std::string stringTagName_ =
"String";
111 return stringTagName_;
115 static const std::string& getStringValueAttributeName() {
116 static const std::string stringValueAttributeName_ =
"stringValue";
117 return stringValueAttributeName_;
121 static const std::string& getStringDocAttributeName() {
122 static const std::string stringDocAttributeName_ =
"stringDoc";
123 return stringDocAttributeName_;
127 static const std::string& getDefaultParameterAttributeName() {
128 static const std::string defaultParameterAttributeName_ =
129 "defaultParameterName";
130 return defaultParameterAttributeName_;
134 static const std::string& getCaseSensitiveAttributeName() {
135 static const std::string caseSensitiveAttributeName_ =
137 return caseSensitiveAttributeName_;
150 template<
class IntegralType>
163 "Error converting xmlObject to "
164 "StringToIntegralParameterEntryValidator." << std::endl <<
165 "Unrecognized tag: " << currentChild.
getTag());
167 if (currentChild.
hasAttribute(getIntegralValueAttributeName())) {
170 getIntegralValueAttributeName()));
172 if (currentChild.
hasAttribute(getStringDocAttributeName())) {
174 currentChild.
getRequired<std::string>(getStringDocAttributeName()));
177 std::string defaultParameterName =
178 xmlObj.
getRequired(getDefaultParameterAttributeName());
181 const bool caseSensitive =
182 xmlObj.
getWithDefault<
bool> (getCaseSensitiveAttributeName (),
true);
185 if (stringDocs.
size() != 0 && integralValues.
size() != 0) {
186 return rcp (
new ret_type (strings, stringDocs, integralValues (), defaultParameterName, caseSensitive));
188 else if (integralValues.
size() != 0) {
189 return rcp (
new ret_type (strings, integralValues(), defaultParameterName, caseSensitive));
192 return rcp (
new ret_type (strings, defaultParameterName, caseSensitive));
197 template<
class IntegralType>
210 castedValidator->validStringValues();
212 castedValidator->getStringDocs();
215 !(stringDocValues.
is_null()) && (stringDocValues->size() != 0);
216 for (
int i =0; i<stringValues->size(); ++i) {
218 stringTag.
addAttribute(getStringValueAttributeName(), (*stringValues)[i]);
220 castedValidator->getIntegralValue((*stringValues)[i]));
223 getStringDocAttributeName(), (*stringDocValues)[i]);
228 castedValidator->getDefaultParameterName());
231 const bool caseSensitive = castedValidator->isCaseSensitive ();
232 xmlObj.
addBool (getCaseSensitiveAttributeName (), caseSensitive);
261 void convertValidator(
266 #ifdef HAVE_TEUCHOS_DEBUG
311 void convertValidator(
316 #ifdef HAVE_TEUCHOS_DEBUG
329 static const std::string& getAllowIntAttributeName() {
330 static const std::string allowIntAttributeName_ =
"allowInt";
331 return allowIntAttributeName_;
335 static const std::string& getAllowDoubleAttributeName() {
336 static const std::string allowDoubleAttributeName_ =
"allowDouble";
337 return allowDoubleAttributeName_;
341 static const std::string& getAllowStringAttributeName() {
342 static const std::string allowStringAttributeName_ =
"allowString";
343 return allowStringAttributeName_;
347 static const std::string& getPrefferedTypeAttributeName() {
348 static const std::string prefferedTypeAttributeName_ =
"prefferedType";
349 return prefferedTypeAttributeName_;
391 #ifdef HAVE_TEUCHOS_DEBUG
406 static const std::string& getMinAttributeName() {
407 static const std::string minAttributeName =
"min";
408 return minAttributeName;
412 static const std::string& getMaxAttributeName() {
413 static const std::string maxAttributeName =
"max";
414 return maxAttributeName;
418 static const std::string& getStepAttributeName() {
419 static const std::string stepAttributeName =
"step";
420 return stepAttributeName;
424 static const std::string& getPrecisionAttributeName() {
425 static const std::string precisionAttributeName =
"precision";
426 return precisionAttributeName;
444 toReturn->setStep(step);
446 getPrecisionAttributeName(),
448 toReturn->setPrecision(precision);
450 toReturn->setMin(xmlObj.
getRequired<T>(getMinAttributeName()));
453 toReturn->setMax(xmlObj.
getRequired<T>(getMaxAttributeName()));
467 if (castedValidator->hasMin()) {
468 xmlObj.
addAttribute<T>(getMinAttributeName(), castedValidator->getMin());
470 if (castedValidator->hasMax()) {
471 xmlObj.
addAttribute<T>(getMaxAttributeName(), castedValidator->getMax());
473 xmlObj.
addAttribute<T>(getStepAttributeName(), castedValidator->getStep());
475 getPrecisionAttributeName(), castedValidator->getPrecision());
507 void convertValidator(
512 #ifdef HAVE_TEUCHOS_DEBUG
525 static const std::string& getFileMustExistAttributeName() {
526 static const std::string fileMustExistAttributeName =
"fileMustExist";
527 return fileMustExistAttributeName;
563 void convertValidator(
568 #ifdef HAVE_TEUCHOS_DEBUG
581 static const std::string& getStringTagName() {
582 static const std::string stringTagName =
"String";
583 return stringTagName;
587 static const std::string& getStringValueAttributeName() {
588 static const std::string stringValueAttributeName =
"value";
589 return stringValueAttributeName;
596 template<
class Val
idatorType,
class EntryType>
609 void convertValidator(
629 template<
class Val
idatorType,
class EntryType>
630 RCP<ParameterEntryValidator>
631 AbstractArrayValidatorXMLConverter<ValidatorType, EntryType>::convertXML(
632 const XMLObject& xmlObj,
633 const IDtoValidatorMap& validatorIDsMap)
const
635 RCP<ValidatorType> prototypeValidator;
636 if(xmlObj.hasAttribute(
640 validatorIDsMap.find(
642 getPrototypeIdAttributeName()));
643 if (result != validatorIDsMap.end() ) {
645 rcp_dynamic_cast<ValidatorType>(result->second,
true);
649 MissingValidatorDefinitionException,
650 "Could not find prototype validator with id: "
652 getPrototypeIdAttributeName()) << std::endl<< std::endl);
656 prototypeValidator = rcp_dynamic_cast<ValidatorType>(
658 xmlObj.getChild(0), validatorIDsMap),
true);
660 return getConcreteValidator(prototypeValidator);
663 template<
class Val
idatorType,
class EntryType>
665 AbstractArrayValidatorXMLConverter<ValidatorType, EntryType>::convertValidator(
666 const RCP<const ParameterEntryValidator> validator,
668 const ValidatortoIDMap& validatorIDsMap)
const
670 RCP<const AbstractArrayValidator<ValidatorType, EntryType> > castedValidator =
671 rcp_dynamic_cast<
const AbstractArrayValidator<ValidatorType, EntryType> >(
673 if(validatorIDsMap.find(castedValidator->getPrototype())
674 == validatorIDsMap.end())
677 castedValidator->getPrototype(), validatorIDsMap,
false));
681 validatorIDsMap.find(castedValidator->getPrototype())->second;
684 getPrototypeIdAttributeName(), prototypeID);
715 template<
class Val
idatorType,
class EntryType>
717 public AbstractArrayValidatorXMLConverter<ValidatorType, EntryType>
728 #ifdef HAVE_TEUCHOS_DEBUG
767 template<
class Val
idatorType,
class EntryType>
769 public AbstractArrayValidatorXMLConverter<ValidatorType, EntryType>
782 #ifdef HAVE_TEUCHOS_DEBUG
800 #endif // TEUCHOS_STANDARDVALIDATORXMLCONVERTERS_HPP
Writes an XML object to a parameter list.
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.
Maps Validators to integers.
void addBool(const std::string &name, bool val)
Add a bool as an attribute.
Convert a StringToIntegralParameterEntryValidator to and from XML.
Converts StringValidators to and from XML.
Converts AnyNumberParameterEntryValidators to and from XML.
Converts FileNameValidators to and from XML.
ValidatorMap::const_iterator const_iterator
#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.
Standard implementation of a ParameterEntryValidator that maps from a list of strings to an enum or i...
Converts EnhancedNumberValidators to and from XML.
Converts TwoDArrayValidators to and from XML.
Takes a validator, wraps it, and applies it to a TwoDArray.
void convertValidator(const RCP< const ParameterEntryValidator > validator, XMLObject &xmlObj, const ValidatortoIDMap &validatorIDsMap) const
Converts ArrayValidators to and from XML.
static XMLObject convertValidator(RCP< const ParameterEntryValidator > validator, const ValidatortoIDMap &validatorIDsMap, bool assignedID=true)
Given a validator converts the validator to XML.
RCP< ParameterEntryValidator > convertXML(const XMLObject &xmlObj, const IDtoValidatorMap &validatorIDsMap) const
RCP< ParameterEntryValidator > convertXML(const XMLObject &xmlObj, const IDtoValidatorMap &validatorIDsMap) const
static const std::string & getPrototypeIdAttributeName()
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...
Converts back and forth between XML and ParameterEntryValidators.
A database for ValidatorXMLConverters.
A class for mapping validators to integers.
void addAttribute(const std::string &name, T value)
Lookup whether or not Doubles are allowed.
Takes a validator, wraps it, and applies it to an array.
static RCP< ParameterEntryValidator > convertXML(const XMLObject &xmlObject, const IDtoValidatorMap &validatorIDsMap)
Given an XMLObject converts the XMLObject to a ParameterEntryValidator and inserts the validator into...
void convertValidator(const RCP< const ParameterEntryValidator > validator, XMLObject &xmlObj, const ValidatortoIDMap &validatorIDsMap) const
Default traits class that just returns typeid(T).name().
Class for retrieving a dummy object of type T.
int numChildren() const
Return the number of child nodes owned by this node.
Class uesd to validate a particular type of number.
Class defining the traits of the number type being used in an EnhancedNumberValidator.
Converts BoolParameterEntryValidators to and from XML.
Smart reference counting pointer class for automatic garbage collection.
Thrown when xml tag is encountered that is either unrecognized or inappropriate for a given context...
const XMLObject & getChild(int i) const
Return the i-th child node.
bool hasAttribute(const std::string &name) const
Find out if the current node has an attribute of the specified name.
T getWithDefault(const std::string &name, const T &defaultValue) const
Get an attribute, assigning a default value if the requested attribute does not exist.
const std::string & getRequired(const std::string &name) const
Get an attribute, throwing an std::exception if it is not found.
An abstract base class for converting ParameterEntryValidators to and from XML.
bool is_null() const
Returns true if the underlying pointer is null.