43#ifndef TEUCHOS_STANDARDVALIDATORXMLCONVERTERS_HPP
44#define TEUCHOS_STANDARDVALIDATORXMLCONVERTERS_HPP
51#include "Teuchos_StandardParameterEntryValidators.hpp"
98template<
class IntegralType>
119 #ifdef HAVE_TEUCHOS_DEBUG
122 getDummyValidator()
const{
136 static const std::string& getIntegralValueAttributeName() {
137 static const std::string integralValueAttributeName_ =
"integralValue";
138 return integralValueAttributeName_;
142 static const std::string& getStringTagName() {
143 static const std::string stringTagName_ =
"String";
144 return stringTagName_;
148 static const std::string& getStringValueAttributeName() {
149 static const std::string stringValueAttributeName_ =
"stringValue";
150 return stringValueAttributeName_;
154 static const std::string& getStringDocAttributeName() {
155 static const std::string stringDocAttributeName_ =
"stringDoc";
156 return stringDocAttributeName_;
160 static const std::string& getDefaultParameterAttributeName() {
161 static const std::string defaultParameterAttributeName_ =
162 "defaultParameterName";
163 return defaultParameterAttributeName_;
167 static const std::string& getCaseSensitiveAttributeName() {
168 static const std::string caseSensitiveAttributeName_ =
170 return caseSensitiveAttributeName_;
183template<
class IntegralType>
196 "Error converting xmlObject to "
197 "StringToIntegralParameterEntryValidator." << std::endl <<
198 "Unrecognized tag: " << currentChild.
getTag());
200 if (currentChild.
hasAttribute(getIntegralValueAttributeName())) {
203 getIntegralValueAttributeName()));
205 if (currentChild.
hasAttribute(getStringDocAttributeName())) {
207 currentChild.
getRequired<std::string>(getStringDocAttributeName()));
210 std::string defaultParameterName =
211 xmlObj.
getRequired(getDefaultParameterAttributeName());
214 const bool caseSensitive =
215 xmlObj.
getWithDefault<
bool> (getCaseSensitiveAttributeName (),
true);
218 if (stringDocs.
size() != 0 && integralValues.
size() != 0) {
219 return rcp (
new ret_type (strings, stringDocs, integralValues (), defaultParameterName, caseSensitive));
221 else if (integralValues.
size() != 0) {
222 return rcp (
new ret_type (strings, integralValues(), defaultParameterName, caseSensitive));
225 return rcp (
new ret_type (strings, defaultParameterName, caseSensitive));
230template<
class IntegralType>
243 castedValidator->validStringValues();
245 castedValidator->getStringDocs();
248 !(stringDocValues.
is_null()) && (stringDocValues->size() != 0);
249 for (
int i =0; i<stringValues->size(); ++i) {
251 stringTag.
addAttribute(getStringValueAttributeName(), (*stringValues)[i]);
253 castedValidator->getIntegralValue((*stringValues)[i]));
256 getStringDocAttributeName(), (*stringDocValues)[i]);
261 castedValidator->getDefaultParameterName());
264 const bool caseSensitive = castedValidator->isCaseSensitive ();
265 xmlObj.
addBool (getCaseSensitiveAttributeName (), caseSensitive);
294 void convertValidator(
299 #ifdef HAVE_TEUCHOS_DEBUG
344 void convertValidator(
349 #ifdef HAVE_TEUCHOS_DEBUG
362 static const std::string& getAllowIntAttributeName() {
363 static const std::string allowIntAttributeName_ =
"allowInt";
364 return allowIntAttributeName_;
368 static const std::string& getAllowDoubleAttributeName() {
369 static const std::string allowDoubleAttributeName_ =
"allowDouble";
370 return allowDoubleAttributeName_;
374 static const std::string& getAllowStringAttributeName() {
375 static const std::string allowStringAttributeName_ =
"allowString";
376 return allowStringAttributeName_;
380 static const std::string& getPrefferedTypeAttributeName() {
381 static const std::string prefferedTypeAttributeName_ =
"prefferedType";
382 return prefferedTypeAttributeName_;
424#ifdef HAVE_TEUCHOS_DEBUG
439 static const std::string& getMinAttributeName() {
440 static const std::string minAttributeName =
"min";
441 return minAttributeName;
445 static const std::string& getMaxAttributeName() {
446 static const std::string maxAttributeName =
"max";
447 return maxAttributeName;
451 static const std::string& getStepAttributeName() {
452 static const std::string stepAttributeName =
"step";
453 return stepAttributeName;
457 static const std::string& getPrecisionAttributeName() {
458 static const std::string precisionAttributeName =
"precision";
459 return precisionAttributeName;
477 toReturn->setStep(step);
479 getPrecisionAttributeName(),
481 toReturn->setPrecision(precision);
483 toReturn->setMin(xmlObj.
getRequired<T>(getMinAttributeName()));
486 toReturn->setMax(xmlObj.
getRequired<T>(getMaxAttributeName()));
499 rcp_dynamic_cast<const EnhancedNumberValidator<T> >(validator,
true);
500 if (castedValidator->hasMin()) {
501 xmlObj.
addAttribute<T>(getMinAttributeName(), castedValidator->getMin());
503 if (castedValidator->hasMax()) {
504 xmlObj.
addAttribute<T>(getMaxAttributeName(), castedValidator->getMax());
506 xmlObj.
addAttribute<T>(getStepAttributeName(), castedValidator->getStep());
508 getPrecisionAttributeName(), castedValidator->getPrecision());
540 void convertValidator(
545 #ifdef HAVE_TEUCHOS_DEBUG
558 static const std::string& getFileMustExistAttributeName() {
559 static const std::string fileMustExistAttributeName =
"fileMustExist";
560 return fileMustExistAttributeName;
596 void convertValidator(
601 #ifdef HAVE_TEUCHOS_DEBUG
614 static const std::string& getStringTagName() {
615 static const std::string stringTagName =
"String";
616 return stringTagName;
620 static const std::string& getStringValueAttributeName() {
621 static const std::string stringValueAttributeName =
"value";
622 return stringValueAttributeName;
629template<
class Val
idatorType,
class EntryType>
642 void convertValidator(
662template<
class Val
idatorType,
class EntryType>
663RCP<ParameterEntryValidator>
664AbstractArrayValidatorXMLConverter<ValidatorType, EntryType>::convertXML(
665 const XMLObject& xmlObj,
666 const IDtoValidatorMap& validatorIDsMap)
const
668 RCP<ValidatorType> prototypeValidator;
669 if(xmlObj.hasAttribute(
673 validatorIDsMap.find(
675 getPrototypeIdAttributeName()));
676 if (result != validatorIDsMap.end() ) {
678 rcp_dynamic_cast<ValidatorType>(result->second,
true);
682 MissingValidatorDefinitionException,
683 "Could not find prototype validator with id: "
685 getPrototypeIdAttributeName()) << std::endl<< std::endl);
689 prototypeValidator = rcp_dynamic_cast<ValidatorType>(
691 xmlObj.getChild(0), validatorIDsMap),
true);
693 return getConcreteValidator(prototypeValidator);
696template<
class Val
idatorType,
class EntryType>
698AbstractArrayValidatorXMLConverter<ValidatorType, EntryType>::convertValidator(
699 const RCP<const ParameterEntryValidator> validator,
701 const ValidatortoIDMap& validatorIDsMap)
const
703 RCP<const AbstractArrayValidator<ValidatorType, EntryType> > castedValidator =
704 rcp_dynamic_cast<const AbstractArrayValidator<ValidatorType, EntryType> >(
706 if(validatorIDsMap.find(castedValidator->getPrototype())
707 == validatorIDsMap.end())
710 castedValidator->getPrototype(), validatorIDsMap,
false));
714 validatorIDsMap.find(castedValidator->getPrototype())->second;
717 getPrototypeIdAttributeName(), prototypeID);
748template<
class Val
idatorType,
class EntryType>
750 public AbstractArrayValidatorXMLConverter<ValidatorType, EntryType>
761#ifdef HAVE_TEUCHOS_DEBUG
800template<
class Val
idatorType,
class EntryType>
802 public AbstractArrayValidatorXMLConverter<ValidatorType, EntryType>
815#ifdef HAVE_TEUCHOS_DEBUG
A database for ValidatorXMLConverters.
Converts back and forth between XML and ParameterEntryValidators.
Writes an XML object to a parameter list.
Converts AnyNumberParameterEntryValidators to and from XML.
Converts ArrayValidators to and from XML.
Takes a validator, wraps it, and applies it to an array.
Replacement for std::vector that is compatible with the Teuchos Memory Management classes.
Array< T > & append(const T &x)
Add a new entry at the end of the array.
Thrown when xml tag is encountered that is either unrecognized or inappropriate for a given context.
Converts BoolParameterEntryValidators to and from XML.
Class for retrieving a dummy object of type T.
Class defining the traits of the number type being used in an EnhancedNumberValidator.
Converts EnhancedNumberValidators to and from XML.
void convertValidator(const RCP< const ParameterEntryValidator > validator, XMLObject &xmlObj, const ValidatortoIDMap &validatorIDsMap) const
RCP< ParameterEntryValidator > convertXML(const XMLObject &xmlObj, const IDtoValidatorMap &validatorIDsMap) const
Class uesd to validate a particular type of number.
Converts FileNameValidators to and from XML.
Maps Validators to integers.
ValidatorMap::const_iterator const_iterator
Smart reference counting pointer class for automatic garbage collection.
bool is_null() const
Returns true if the underlying pointer is null.
Standard implementation of a ParameterEntryValidator that maps from a list of strings to an enum or i...
Convert a StringToIntegralParameterEntryValidator to and from XML.
RCP< ParameterEntryValidator > convertXML(const XMLObject &xmlObj, const IDtoValidatorMap &validatorIDsMap) const
void convertValidator(const RCP< const ParameterEntryValidator > validator, XMLObject &xmlObj, const ValidatortoIDMap &validatorIDsMap) const
Converts StringValidators to and from XML.
Converts TwoDArrayValidators to and from XML.
Takes a validator, wraps it, and applies it to a TwoDArray.
Default traits class that just returns typeid(T).name().
static XMLObject convertValidator(RCP< const ParameterEntryValidator > validator, const ValidatortoIDMap &validatorIDsMap, bool assignedID=true)
Given a validator converts the validator to XML.
static RCP< ParameterEntryValidator > convertXML(const XMLObject &xmlObject, const IDtoValidatorMap &validatorIDsMap)
Given an XMLObject converts the XMLObject to a ParameterEntryValidator and inserts the validator into...
An abstract base class for converting ParameterEntryValidators to and from XML.
static const std::string & getPrototypeIdAttributeName()
A class for mapping validators to integers.
Representation of an XML data tree. XMLObject is a ref-counted handle to a XMLObjectImplem object,...
void addBool(const std::string &name, bool val)
Add a bool as an attribute.
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.
T getWithDefault(const std::string &name, const T &defaultValue) const
Get an attribute, assigning a default value if the requested attribute does not exist.
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.
bool hasAttribute(const std::string &name) const
Find out if the current node has an attribute of the specified name.
int numChildren() const
Return the number of child nodes owned by this node.
#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,...
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.