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);
303 #ifdef HAVE_TEUCHOS_DEBUG 316 static const std::string& getAllowIntAttributeName() {
317 static const std::string allowIntAttributeName_ =
"allowInt";
318 return allowIntAttributeName_;
322 static const std::string& getAllowDoubleAttributeName() {
323 static const std::string allowDoubleAttributeName_ =
"allowDouble";
324 return allowDoubleAttributeName_;
328 static const std::string& getAllowStringAttributeName() {
329 static const std::string allowStringAttributeName_ =
"allowString";
330 return allowStringAttributeName_;
334 static const std::string& getPrefferedTypeAttributeName() {
335 static const std::string prefferedTypeAttributeName_ =
"prefferedType";
336 return prefferedTypeAttributeName_;
378 #ifdef HAVE_TEUCHOS_DEBUG 393 static const std::string& getMinAttributeName() {
394 static const std::string minAttributeName =
"min";
395 return minAttributeName;
399 static const std::string& getMaxAttributeName() {
400 static const std::string maxAttributeName =
"max";
401 return maxAttributeName;
405 static const std::string& getStepAttributeName() {
406 static const std::string stepAttributeName =
"step";
407 return stepAttributeName;
411 static const std::string& getPrecisionAttributeName() {
412 static const std::string precisionAttributeName =
"precision";
413 return precisionAttributeName;
431 toReturn->setStep(step);
433 getPrecisionAttributeName(),
435 toReturn->setPrecision(precision);
437 toReturn->setMin(xmlObj.
getRequired<T>(getMinAttributeName()));
440 toReturn->setMax(xmlObj.
getRequired<T>(getMaxAttributeName()));
454 if (castedValidator->hasMin()) {
455 xmlObj.
addAttribute<T>(getMinAttributeName(), castedValidator->getMin());
457 if (castedValidator->hasMax()) {
458 xmlObj.
addAttribute<T>(getMaxAttributeName(), castedValidator->getMax());
460 xmlObj.
addAttribute<T>(getStepAttributeName(), castedValidator->getStep());
462 getPrecisionAttributeName(), castedValidator->getPrecision());
499 #ifdef HAVE_TEUCHOS_DEBUG 512 static const std::string& getFileMustExistAttributeName() {
513 static const std::string fileMustExistAttributeName =
"fileMustExist";
514 return fileMustExistAttributeName;
555 #ifdef HAVE_TEUCHOS_DEBUG 568 static const std::string& getStringTagName() {
569 static const std::string stringTagName =
"String";
570 return stringTagName;
574 static const std::string& getStringValueAttributeName() {
575 static const std::string stringValueAttributeName =
"value";
576 return stringValueAttributeName;
583 template<
class Val
idatorType,
class EntryType>
616 template<
class Val
idatorType,
class EntryType>
618 AbstractArrayValidatorXMLConverter<ValidatorType, EntryType>::convertXML(
627 validatorIDsMap.
find(
630 if (result != validatorIDsMap.
end() ) {
632 rcp_dynamic_cast<ValidatorType>(result->second,
true);
637 "Could not find prototype validator with id: " 643 prototypeValidator = rcp_dynamic_cast<ValidatorType>(
645 xmlObj.
getChild(0), validatorIDsMap),
true);
647 return getConcreteValidator(prototypeValidator);
650 template<
class Val
idatorType,
class EntryType>
652 AbstractArrayValidatorXMLConverter<ValidatorType, EntryType>::convertValidator(
660 if(validatorIDsMap.
find(castedValidator->getPrototype())
661 == validatorIDsMap.
end())
664 castedValidator->getPrototype(), validatorIDsMap,
false));
668 validatorIDsMap.
find(castedValidator->getPrototype())->second;
702 template<
class Val
idatorType,
class EntryType>
704 public AbstractArrayValidatorXMLConverter<ValidatorType, EntryType>
715 #ifdef HAVE_TEUCHOS_DEBUG 754 template<
class Val
idatorType,
class EntryType>
756 public AbstractArrayValidatorXMLConverter<ValidatorType, EntryType>
769 #ifdef HAVE_TEUCHOS_DEBUG 787 #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.
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.
const std::string & getRequired(const std::string &name) const
Get an attribute, throwing an std::exception if it is not found.
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.
const_iterator end() const
Returns a const_reference to the end of the map.
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.
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
const_iterator find(const RCP< const ParameterEntryValidator > validator) const
Returns an iterator to the validator and id specified by the validator.
Default traits class that just returns typeid(T).name().
Class for retrieving a dummy object of type T.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos, as well as a number of utility routines.
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.
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.
An abstract base class for converting ParameterEntryValidators to and from XML.
Thrown when a referenced validator can't be found.
bool is_null() const
Returns true if the underlying pointer is null.