43 #ifndef TEUCHOS_STANDARDVALIDATORXMLCONVERTERS_HPP
44 #define TEUCHOS_STANDARDVALIDATORXMLCONVERTERS_HPP
88 template<
class IntegralType>
109 #ifdef HAVE_TEUCHOS_DEBUG
112 getDummyValidator()
const{
127 static const std::string integralValueAttributeName_ =
"integralValue";
128 return integralValueAttributeName_;
133 static const std::string stringTagName_ =
"String";
134 return stringTagName_;
139 static const std::string stringValueAttributeName_ =
"stringValue";
140 return stringValueAttributeName_;
145 static const std::string stringDocAttributeName_ =
"stringDoc";
146 return stringDocAttributeName_;
151 static const std::string defaultParameterAttributeName_ =
152 "defaultParameterName";
153 return defaultParameterAttributeName_;
166 template<
class IntegralType>
167 RCP<ParameterEntryValidator>
179 "Error converting xmlObject to "
180 "StringToIntegralParameterEntryValidator." << std::endl <<
181 "Unrecognized tag: " << currentChild.
getTag());
183 if (currentChild.
hasAttribute(getIntegralValueAttributeName())) {
186 getIntegralValueAttributeName()));
188 if (currentChild.
hasAttribute(getStringDocAttributeName())) {
190 currentChild.
getRequired<std::string>(getStringDocAttributeName()));
193 std::string defaultParameterName =
194 xmlObj.
getRequired(getDefaultParameterAttributeName());
196 if(stringDocs.
size() != 0 && integralValues.
size() != 0){
197 return stringToIntegralParameterEntryValidator<IntegralType>(
198 strings, stringDocs, integralValues(), defaultParameterName);
200 else if(integralValues.
size() != 0){
201 return stringToIntegralParameterEntryValidator<IntegralType>(
202 strings, integralValues(), defaultParameterName);
205 return stringToIntegralParameterEntryValidator<IntegralType>(
206 strings, defaultParameterName);
211 template<
class IntegralType>
224 castedValidator->validStringValues();
226 castedValidator->getStringDocs();
229 !(stringDocValues.
is_null()) && (stringDocValues->size() != 0);
230 for (
int i =0; i<stringValues->size(); ++i) {
232 stringTag.
addAttribute(getStringValueAttributeName(), (*stringValues)[i]);
234 castedValidator->getIntegralValue((*stringValues)[i]));
237 getStringDocAttributeName(), (*stringDocValues)[i]);
242 castedValidator->getDefaultParameterName());
274 void convertValidator(
279 #ifdef HAVE_TEUCHOS_DEBUG
293 static const std::string allowIntAttributeName_ =
"allowInt";
294 return allowIntAttributeName_;
299 static const std::string allowDoubleAttributeName_ =
"allowDouble";
300 return allowDoubleAttributeName_;
305 static const std::string allowStringAttributeName_ =
"allowString";
306 return allowStringAttributeName_;
311 static const std::string prefferedTypeAttributeName_ =
"prefferedType";
312 return prefferedTypeAttributeName_;
354 #ifdef HAVE_TEUCHOS_DEBUG
370 static const std::string minAttributeName =
"min";
371 return minAttributeName;
376 static const std::string maxAttributeName =
"max";
377 return maxAttributeName;
382 static const std::string stepAttributeName =
"step";
383 return stepAttributeName;
388 static const std::string precisionAttributeName =
"precision";
389 return precisionAttributeName;
398 RCP<ParameterEntryValidator>
407 toReturn->setStep(step);
409 getPrecisionAttributeName(),
411 toReturn->setPrecision(precision);
413 toReturn->setMin(xmlObj.
getRequired<T>(getMinAttributeName()));
416 toReturn->setMax(xmlObj.
getRequired<T>(getMaxAttributeName()));
430 if (castedValidator->hasMin()) {
431 xmlObj.
addAttribute<T>(getMinAttributeName(), castedValidator->getMin());
433 if (castedValidator->hasMax()) {
434 xmlObj.
addAttribute<T>(getMaxAttributeName(), castedValidator->getMax());
436 xmlObj.
addAttribute<T>(getStepAttributeName(), castedValidator->getStep());
438 getPrecisionAttributeName(), castedValidator->getPrecision());
470 void convertValidator(
475 #ifdef HAVE_TEUCHOS_DEBUG
489 static const std::string fileMustExistAttributeName =
"fileMustExist";
490 return fileMustExistAttributeName;
526 void convertValidator(
531 #ifdef HAVE_TEUCHOS_DEBUG
545 static const std::string stringTagName =
"String";
546 return stringTagName;
551 static const std::string stringValueAttributeName =
"value";
552 return stringValueAttributeName;
559 template<
class Val
idatorType,
class EntryType>
592 template<
class Val
idatorType,
class EntryType>
603 validatorIDsMap.
find(
605 getPrototypeIdAttributeName()));
606 if (result != validatorIDsMap.
end() ) {
608 rcp_dynamic_cast<ValidatorType>(result->second,
true);
613 "Could not find prototype validator with id: "
615 getPrototypeIdAttributeName()) << std::endl<< std::endl);
619 prototypeValidator = rcp_dynamic_cast<ValidatorType>(
621 xmlObj.
getChild(0), validatorIDsMap),
true);
623 return getConcreteValidator(prototypeValidator);
626 template<
class Val
idatorType,
class EntryType>
636 if(validatorIDsMap.
find(castedValidator->getPrototype())
637 == validatorIDsMap.
end())
640 castedValidator->getPrototype(), validatorIDsMap,
false));
644 validatorIDsMap.
find(castedValidator->getPrototype())->second;
647 getPrototypeIdAttributeName(), prototypeID);
678 template<
class Val
idatorType,
class EntryType>
691 #ifdef HAVE_TEUCHOS_DEBUG
730 template<
class Val
idatorType,
class EntryType>
745 #ifdef HAVE_TEUCHOS_DEBUG
763 #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()
Converts StringToIntegralParameterEntryValidators 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 some integra...
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.
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.
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.