43 #ifndef TEUCHOS_STANDARDVALIDATORXMLCONVERTERS_HPP
44 #define TEUCHOS_STANDARDVALIDATORXMLCONVERTERS_HPP
51 #include "Teuchos_StandardParameterEntryValidators.hpp"
98 template<
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_;
183 template<
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));
230 template<
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()));
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;
629 template<
class Val
idatorType,
class EntryType>
642 void convertValidator(
662 template<
class Val
idatorType,
class EntryType>
663 RCP<ParameterEntryValidator>
664 AbstractArrayValidatorXMLConverter<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);
696 template<
class Val
idatorType,
class EntryType>
698 AbstractArrayValidatorXMLConverter<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);
748 template<
class Val
idatorType,
class EntryType>
750 public AbstractArrayValidatorXMLConverter<ValidatorType, EntryType>
761 #ifdef HAVE_TEUCHOS_DEBUG
800 template<
class Val
idatorType,
class EntryType>
802 public AbstractArrayValidatorXMLConverter<ValidatorType, EntryType>
815 #ifdef HAVE_TEUCHOS_DEBUG
833 #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.