10 #ifndef TEUCHOS_STANDARDVALIDATORXMLCONVERTERS_HPP
11 #define TEUCHOS_STANDARDVALIDATORXMLCONVERTERS_HPP
65 template<
class IntegralType>
86 #ifdef HAVE_TEUCHOS_DEBUG
89 getDummyValidator()
const{
104 static const std::string integralValueAttributeName_ =
"integralValue";
105 return integralValueAttributeName_;
110 static const std::string stringTagName_ =
"String";
111 return stringTagName_;
116 static const std::string stringValueAttributeName_ =
"stringValue";
117 return stringValueAttributeName_;
122 static const std::string stringDocAttributeName_ =
"stringDoc";
123 return stringDocAttributeName_;
128 static const std::string defaultParameterAttributeName_ =
129 "defaultParameterName";
130 return defaultParameterAttributeName_;
135 static const std::string caseSensitiveAttributeName_ =
137 return caseSensitiveAttributeName_;
150 template<
class IntegralType>
151 RCP<ParameterEntryValidator>
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
330 static const std::string allowIntAttributeName_ =
"allowInt";
331 return allowIntAttributeName_;
336 static const std::string allowDoubleAttributeName_ =
"allowDouble";
337 return allowDoubleAttributeName_;
342 static const std::string allowStringAttributeName_ =
"allowString";
343 return allowStringAttributeName_;
348 static const std::string prefferedTypeAttributeName_ =
"prefferedType";
349 return prefferedTypeAttributeName_;
391 #ifdef HAVE_TEUCHOS_DEBUG
407 static const std::string minAttributeName =
"min";
408 return minAttributeName;
413 static const std::string maxAttributeName =
"max";
414 return maxAttributeName;
419 static const std::string stepAttributeName =
"step";
420 return stepAttributeName;
425 static const std::string precisionAttributeName =
"precision";
426 return precisionAttributeName;
435 RCP<ParameterEntryValidator>
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
526 static const std::string fileMustExistAttributeName =
"fileMustExist";
527 return fileMustExistAttributeName;
563 void convertValidator(
568 #ifdef HAVE_TEUCHOS_DEBUG
582 static const std::string stringTagName =
"String";
583 return stringTagName;
588 static const std::string stringValueAttributeName =
"value";
589 return stringValueAttributeName;
596 template<
class Val
idatorType,
class EntryType>
629 template<
class Val
idatorType,
class EntryType>
640 validatorIDsMap.
find(
642 getPrototypeIdAttributeName()));
643 if (result != validatorIDsMap.
end() ) {
645 rcp_dynamic_cast<ValidatorType>(result->second,
true);
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>
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>
728 #ifdef HAVE_TEUCHOS_DEBUG
767 template<
class Val
idatorType,
class EntryType>
782 #ifdef HAVE_TEUCHOS_DEBUG
800 #endif // TEUCHOS_STANDARDVALIDATORXMLCONVERTERS_HPP
const_iterator find(int id) const
Retrieves and iterator to a validator and id based on the id given.
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.
static const std::string & getAllowDoubleAttributeName()
static const std::string & getDefaultParameterAttributeName()
Name (tag) of the default parameter attribute.
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.
static const std::string & getStepAttributeName()
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.
static const std::string & getIntegralValueAttributeName()
Standard implementation of a ParameterEntryValidator that maps from a list of strings to an enum or i...
static const std::string & getMaxAttributeName()
static const std::string & getMinAttributeName()
Converts EnhancedNumberValidators to and from XML.
Converts TwoDArrayValidators to and from XML.
static const std::string & getFileMustExistAttributeName()
Takes a validator, wraps it, and applies it to a TwoDArray.
static const std::string & getStringTagName()
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()
static const std::string & getPrefferedTypeAttributeName()
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.
const_iterator end() const
Returns a const_reference to the end of the map.
void convertValidator(const RCP< const ParameterEntryValidator > validator, XMLObject &xmlObj, const ValidatortoIDMap &validatorIDsMap) const
RCP< ParameterEntryValidator > convertXML(const XMLObject &xmlObj, const IDtoValidatorMap &validatorIDsMap) const
An abstract base class for all ArrayValidators.
A class for mapping validators to integers.
void addAttribute(const std::string &name, T value)
Lookup whether or not Doubles are allowed.
static const std::string & getAllowIntAttributeName()
Takes a validator, wraps it, and applies it to an array.
const_iterator end() const
Returns a const_reference to the end of the map.
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
#define TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT
const_iterator find(const RCP< const ParameterEntryValidator > validator) const
Returns an iterator to the validator and id specified by the validator.
virtual RCP< AbstractArrayValidator< ValidatorType, EntryType > > getConcreteValidator(RCP< ValidatorType > prototypeValidator) const =0
Returns a concrete validator that has AbstractArrayValidator as it's parent class.
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.
static const std::string & getStringDocAttributeName()
Class uesd to validate a particular type of number.
static const std::string & getStringTagName()
static const std::string & getAllowStringAttributeName()
Class defining the traits of the number type being used in an EnhancedNumberValidator.
Converts BoolParameterEntryValidators to and from XML.
static const std::string & getStringValueAttributeName()
virtual RCP< AbstractArrayValidator< ValidatorType, EntryType > > getConcreteValidator(RCP< ValidatorType > prototypeValidator) const
Returns a concrete validator that has AbstractArrayValidator as it's parent class.
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.
static const std::string & getStringValueAttributeName()
T getWithDefault(const std::string &name, const T &defaultValue) const
Get an attribute, assigning a default value if the requested attribute does not exist.
static const std::string & getCaseSensitiveAttributeName()
Name (tag) of the caseSensitive attribute.
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.
Thrown when a referenced validator can't be found.
virtual RCP< AbstractArrayValidator< ValidatorType, EntryType > > getConcreteValidator(RCP< ValidatorType > prototypeValidator) const
Returns a concrete validator that has AbstractArrayValidator as it's parent class.
static const std::string & getPrecisionAttributeName()
bool is_null() const
Returns true if the underlying pointer is null.