10#ifndef TEUCHOS_STANDARDVALIDATORXMLCONVERTERS_HPP
11#define TEUCHOS_STANDARDVALIDATORXMLCONVERTERS_HPP
18#include "Teuchos_StandardParameterEntryValidators.hpp"
65template<
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_;
150template<
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));
197template<
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);
266 #ifdef HAVE_TEUCHOS_DEBUG
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());
512 #ifdef HAVE_TEUCHOS_DEBUG
525 static const std::string& getFileMustExistAttributeName() {
526 static const std::string fileMustExistAttributeName =
"fileMustExist";
527 return fileMustExistAttributeName;
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;
596template<
class Val
idatorType,
class EntryType>
609 void convertValidator(
629template<
class Val
idatorType,
class EntryType>
630RCP<ParameterEntryValidator>
631AbstractArrayValidatorXMLConverter<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() ) {
650 "Could not find prototype validator with id: "
652 getPrototypeIdAttributeName()) << std::endl<< std::endl);
658 xmlObj.getChild(0), validatorIDsMap),
true);
660 return getConcreteValidator(prototypeValidator);
663template<
class Val
idatorType,
class EntryType>
665AbstractArrayValidatorXMLConverter<ValidatorType, EntryType>::convertValidator(
673 if(validatorIDsMap.find(castedValidator->getPrototype())
674 == validatorIDsMap.end())
677 castedValidator->getPrototype(), validatorIDsMap,
false));
681 validatorIDsMap.find(castedValidator->getPrototype())->second;
684 getPrototypeIdAttributeName(), prototypeID);
715template<
class Val
idatorType,
class EntryType>
717 public AbstractArrayValidatorXMLConverter<ValidatorType, EntryType>
728#ifdef HAVE_TEUCHOS_DEBUG
767template<
class Val
idatorType,
class EntryType>
769 public AbstractArrayValidatorXMLConverter<ValidatorType, EntryType>
782#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.
RCP< ParameterEntryValidator > convertXML(const XMLObject &xmlObj, const IDtoValidatorMap &validatorIDsMap) const
void convertValidator(const RCP< const ParameterEntryValidator > validator, XMLObject &xmlObj, const ValidatortoIDMap &validatorIDsMap) const
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.
void convertValidator(const RCP< const ParameterEntryValidator > validator, XMLObject &xmlObj, const ValidatortoIDMap &validatorIDsMap) const
RCP< ParameterEntryValidator > convertXML(const XMLObject &xmlObj, const IDtoValidatorMap &validatorIDsMap) const
Class for retrieving a dummy object of type T.
static unsigned short defaultPrecision()
Gets the default precision with which the number type should be displayed.
static T defaultStep()
gets default amount a value of the number type should be incremented by when being utilizied in a UI.
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.
RCP< ParameterEntryValidator > convertXML(const XMLObject &xmlObj, const IDtoValidatorMap &validatorIDsMap) const
void convertValidator(const RCP< const ParameterEntryValidator > validator, XMLObject &xmlObj, const ValidatortoIDMap &validatorIDsMap) const
Maps Validators to integers.
ValidatorMap::const_iterator const_iterator
Thrown when a referenced validator can't be found.
Smart reference counting pointer class for automatic garbage collection.
RCP< T2 > rcp_dynamic_cast(const RCP< T1 > &p1, bool throw_on_fail=false)
Dynamic cast of underlying RCP type from T1* to T2*.
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.
void convertValidator(const RCP< const ParameterEntryValidator > validator, XMLObject &xmlObj, const ValidatortoIDMap &validatorIDsMap) const
RCP< ParameterEntryValidator > convertXML(const XMLObject &xmlObj, const IDtoValidatorMap &validatorIDsMap) const
Converts TwoDArrayValidators to and from XML.
Takes a validator, wraps it, and applies it to a TwoDArray.
static std::string 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.