43 #ifndef TEUCHOS_STANDARDVALIDATORXMLCONVERTERS_HPP 44 #define TEUCHOS_STANDARDVALIDATORXMLCONVERTERS_HPP 98 template<
class IntegralType>
119 #ifdef HAVE_TEUCHOS_DEBUG 122 getDummyValidator()
const{
137 static const std::string integralValueAttributeName_ =
"integralValue";
138 return integralValueAttributeName_;
143 static const std::string stringTagName_ =
"String";
144 return stringTagName_;
149 static const std::string stringValueAttributeName_ =
"stringValue";
150 return stringValueAttributeName_;
155 static const std::string stringDocAttributeName_ =
"stringDoc";
156 return stringDocAttributeName_;
161 static const std::string defaultParameterAttributeName_ =
162 "defaultParameterName";
163 return defaultParameterAttributeName_;
168 static const std::string caseSensitiveAttributeName_ =
170 return caseSensitiveAttributeName_;
183 template<
class IntegralType>
184 RCP<ParameterEntryValidator>
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 363 static const std::string allowIntAttributeName_ =
"allowInt";
364 return allowIntAttributeName_;
369 static const std::string allowDoubleAttributeName_ =
"allowDouble";
370 return allowDoubleAttributeName_;
375 static const std::string allowStringAttributeName_ =
"allowString";
376 return allowStringAttributeName_;
381 static const std::string prefferedTypeAttributeName_ =
"prefferedType";
382 return prefferedTypeAttributeName_;
424 #ifdef HAVE_TEUCHOS_DEBUG 440 static const std::string minAttributeName =
"min";
441 return minAttributeName;
446 static const std::string maxAttributeName =
"max";
447 return maxAttributeName;
452 static const std::string stepAttributeName =
"step";
453 return stepAttributeName;
458 static const std::string precisionAttributeName =
"precision";
459 return precisionAttributeName;
468 RCP<ParameterEntryValidator>
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 559 static const std::string fileMustExistAttributeName =
"fileMustExist";
560 return fileMustExistAttributeName;
596 void convertValidator(
601 #ifdef HAVE_TEUCHOS_DEBUG 615 static const std::string stringTagName =
"String";
616 return stringTagName;
621 static const std::string stringValueAttributeName =
"value";
622 return stringValueAttributeName;
629 template<
class Val
idatorType,
class EntryType>
662 template<
class Val
idatorType,
class EntryType>
673 validatorIDsMap.
find(
675 getPrototypeIdAttributeName()));
676 if (result != validatorIDsMap.
end() ) {
678 rcp_dynamic_cast<ValidatorType>(result->second,
true);
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>
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>
761 #ifdef HAVE_TEUCHOS_DEBUG 800 template<
class Val
idatorType,
class EntryType>
815 #ifdef HAVE_TEUCHOS_DEBUG 833 #endif // TEUCHOS_STANDARDVALIDATORXMLCONVERTERS_HPP Writes an XML object to a parameter list.
bool hasAttribute(const std::string &name) const
Find out if the current node has an attribute of the specified name.
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
const_iterator find(const RCP< const ParameterEntryValidator > validator) const
Returns an iterator to the validator and id specified by the validator.
#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.
const XMLObject & getChild(int i) const
Return the i-th child node.
void convertValidator(const RCP< const ParameterEntryValidator > validator, XMLObject &xmlObj, const ValidatortoIDMap &validatorIDsMap) const
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 & 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.
virtual RCP< AbstractArrayValidator< ValidatorType, EntryType > > getConcreteValidator(RCP< ValidatorType > prototypeValidator) const
Returns a concrete validator that has AbstractArrayValidator as it's parent class.
void convertValidator(const RCP< const ParameterEntryValidator > validator, XMLObject &xmlObj, const ValidatortoIDMap &validatorIDsMap) const
Converts TwoDArrayValidators to and from XML.
static const std::string & getFileMustExistAttributeName()
Takes a validator, wraps it, and applies it to a TwoDArray.
bool is_null() const
Returns true if the underlying pointer is null.
static const std::string & getStringTagName()
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.
static const std::string & getPrototypeIdAttributeName()
RCP< ParameterEntryValidator > convertXML(const XMLObject &xmlObj, const IDtoValidatorMap &validatorIDsMap) const
static const std::string & getPrefferedTypeAttributeName()
const_iterator find(int id) const
Retrieves and iterator to a validator and id based on the id given.
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.
An abstract base class for all ArrayValidators.
RCP< ParameterEntryValidator > convertXML(const XMLObject &xmlObj, const IDtoValidatorMap &validatorIDsMap) const
A class for mapping validators to integers.
void addAttribute(const std::string &name, T value)
Lookup whether or not Doubles are allowed.
const_iterator end() const
Returns a const_reference to the end of the map.
static const std::string & getAllowIntAttributeName()
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...
const std::string & getTag() const
Return the tag of the current node.
#define TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT
T getWithDefault(const std::string &name, const T &defaultValue) const
Get an attribute, assigning a default value if the requested attribute does not exist.
virtual RCP< AbstractArrayValidator< ValidatorType, EntryType > > getConcreteValidator(RCP< ValidatorType > prototypeValidator) const =0
Returns a concrete validator that has AbstractArrayValidator as it's parent class.
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.
const std::string & getRequired(const std::string &name) const
Get an attribute, throwing an std::exception if it is not found.
static const std::string & getStringDocAttributeName()
Class uesd to validate a particular type of number.
static const std::string & getStringTagName()
int numChildren() const
Return the number of child nodes owned by this node.
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()
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...
RCP< ParameterEntryValidator > convertXML(const XMLObject &xmlObj, const IDtoValidatorMap &validatorIDsMap) const
static const std::string & getStringValueAttributeName()
const_iterator end() const
Returns a const_reference to the end of the map.
static const std::string & getCaseSensitiveAttributeName()
Name (tag) of the caseSensitive attribute.
An abstract base class for converting ParameterEntryValidators to and from XML.
Thrown when a referenced validator can't be found.
static const std::string & getPrecisionAttributeName()