Teuchos Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
Teuchos_StandardValidatorXMLConverters.hpp
Go to the documentation of this file.
1// @HEADER
2// ***********************************************************************
3//
4// Teuchos: Common Tools Package
5// Copyright (2004) Sandia Corporation
6//
7// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8// license for use of this work by or on behalf of the U.S. Government.
9//
10// Redistribution and use in source and binary forms, with or without
11// modification, are permitted provided that the following conditions are
12// met:
13//
14// 1. Redistributions of source code must retain the above copyright
15// notice, this list of conditions and the following disclaimer.
16//
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// 3. Neither the name of the Corporation nor the names of the
22// contributors may be used to endorse or promote products derived from
23// this software without specific prior written permission.
24//
25// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36//
37// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38//
39// ***********************************************************************
40// @HEADER
41
42
43#ifndef TEUCHOS_STANDARDVALIDATORXMLCONVERTERS_HPP
44#define TEUCHOS_STANDARDVALIDATORXMLCONVERTERS_HPP
45
55
56
57namespace Teuchos {
58
59
98template<class IntegralType>
101{
102
103public:
104
107
110 const XMLObject& xmlObj,
111 const IDtoValidatorMap& validatorIDsMap) const;
112
114 void convertValidator(
117 const ValidatortoIDMap& validatorIDsMap) const;
118
119 #ifdef HAVE_TEUCHOS_DEBUG
122 getDummyValidator() const{
123 return DummyObjectGetter<
125 }
126 #endif
127
129
130private:
131
134
136 static const std::string& getIntegralValueAttributeName() {
137 static const std::string integralValueAttributeName_ = "integralValue";
139 }
140
142 static const std::string& getStringTagName() {
143 static const std::string stringTagName_ = "String";
144 return stringTagName_;
145 }
146
148 static const std::string& getStringValueAttributeName() {
149 static const std::string stringValueAttributeName_ = "stringValue";
151 }
152
154 static const std::string& getStringDocAttributeName() {
155 static const std::string stringDocAttributeName_ = "stringDoc";
157 }
158
160 static const std::string& getDefaultParameterAttributeName() {
161 static const std::string defaultParameterAttributeName_ =
162 "defaultParameterName";
164 }
165
167 static const std::string& getCaseSensitiveAttributeName() {
168 static const std::string caseSensitiveAttributeName_ =
169 "caseSensitive";
171 }
172
174
175};
176
177
178//
179// Implementations
180//
181
182
183template<class IntegralType>
184RCP<ParameterEntryValidator>
186 const XMLObject& xmlObj,
187 const IDtoValidatorMap& /*validatorIDsMap*/) const
188{
192 for (int i=0; i<xmlObj.numChildren(); ++i) {
193 XMLObject currentChild = xmlObj.getChild(i);
194 TEUCHOS_TEST_FOR_EXCEPTION(currentChild.getTag() != getStringTagName(),
196 "Error converting xmlObject to "
197 "StringToIntegralParameterEntryValidator." << std::endl <<
198 "Unrecognized tag: " << currentChild.getTag());
199 strings.append(currentChild.getRequired(getStringValueAttributeName()));
200 if (currentChild.hasAttribute(getIntegralValueAttributeName())) {
201 integralValues.append(
202 currentChild.getRequired<IntegralType>(
203 getIntegralValueAttributeName()));
204 }
205 if (currentChild.hasAttribute(getStringDocAttributeName())) {
206 stringDocs.append(
207 currentChild.getRequired<std::string>(getStringDocAttributeName()));
208 }
209 }
210 std::string defaultParameterName =
211 xmlObj.getRequired(getDefaultParameterAttributeName());
212
213 // The "caseSensitive" attribute is not required. It is true by default.
214 const bool caseSensitive =
215 xmlObj.getWithDefault<bool> (getCaseSensitiveAttributeName (), true);
216
218 if (stringDocs.size() != 0 && integralValues.size() != 0) {
220 }
221 else if (integralValues.size() != 0) {
223 }
224 else {
226 }
227}
228
229
230template<class IntegralType>
234 const ValidatortoIDMap& /*validatorIDsMap*/) const
235{
238 rcp_dynamic_cast<
240 validator, true);
241
243 castedValidator->validStringValues();
245 castedValidator->getStringDocs();
246
247 bool hasStringDocs =
248 !(stringDocValues.is_null()) && (stringDocValues->size() != 0);
249 for (int i =0; i<stringValues->size(); ++i) {
250 XMLObject stringTag(getStringTagName());
251 stringTag.addAttribute(getStringValueAttributeName(), (*stringValues)[i]);
252 stringTag.addAttribute(getIntegralValueAttributeName(),
253 castedValidator->getIntegralValue((*stringValues)[i]));
254 if (hasStringDocs) {
255 stringTag.addAttribute(
256 getStringDocAttributeName(), (*stringDocValues)[i]);
257 }
258 xmlObj.addChild(stringTag);
259 }
260 xmlObj.addAttribute(getDefaultParameterAttributeName(),
261 castedValidator->getDefaultParameterName());
262
263 // Add "caseSensitive" bool attribute here.
264 const bool caseSensitive = castedValidator->isCaseSensitive ();
265 xmlObj.addBool (getCaseSensitiveAttributeName (), caseSensitive);
266
267 xmlObj.addAttribute(getIntegralValueAttributeName(),
269}
270
281{
282
283public:
284
287
290 const XMLObject& xmlObj,
291 const IDtoValidatorMap& validatorIDsMap) const;
292
294 void convertValidator(
297 const ValidatortoIDMap& validatorIDsMap) const;
298
299 #ifdef HAVE_TEUCHOS_DEBUG
302 #endif
303
305
306private:
307
310
311 // currently empty
312
314
315};
316
331{
332
333public:
334
337
340 const XMLObject& xmlObj,
341 const IDtoValidatorMap& validatorIDsMap) const;
342
344 void convertValidator(
347 const ValidatortoIDMap& validatorIDsMap) const;
348
349 #ifdef HAVE_TEUCHOS_DEBUG
352 #endif
353
355
356private:
357
360
362 static const std::string& getAllowIntAttributeName() {
363 static const std::string allowIntAttributeName_ = "allowInt";
365 }
366
368 static const std::string& getAllowDoubleAttributeName() {
369 static const std::string allowDoubleAttributeName_ = "allowDouble";
371 }
372
374 static const std::string& getAllowStringAttributeName() {
375 static const std::string allowStringAttributeName_ = "allowString";
377 }
378
380 static const std::string& getPrefferedTypeAttributeName() {
381 static const std::string prefferedTypeAttributeName_ = "prefferedType";
383 }
384
386
387};
388
389
404template<class T>
406{
407
408public:
409
412
415 const XMLObject& xmlObj,
416 const IDtoValidatorMap& validatorIDsMap) const;
417
419 void convertValidator(
422 const ValidatortoIDMap& validatorIDsMap) const;
423
424#ifdef HAVE_TEUCHOS_DEBUG
427 return DummyObjectGetter<EnhancedNumberValidator<T> >::getDummyObject();
428 }
429#endif
430
432
433private:
434
437
439 static const std::string& getMinAttributeName() {
440 static const std::string minAttributeName = "min";
441 return minAttributeName;
442 }
443
445 static const std::string& getMaxAttributeName() {
446 static const std::string maxAttributeName = "max";
447 return maxAttributeName;
448 }
449
451 static const std::string& getStepAttributeName() {
452 static const std::string stepAttributeName = "step";
453 return stepAttributeName;
454 }
455
457 static const std::string& getPrecisionAttributeName() {
458 static const std::string precisionAttributeName = "precision";
460 }
461
463
464};
465
466
467template<class T>
468RCP<ParameterEntryValidator>
470 const XMLObject& xmlObj,
471 const IDtoValidatorMap& /*validatorIDsMap*/) const
472{
475 T step = xmlObj.getWithDefault(
476 getStepAttributeName(), EnhancedNumberTraits<T>::defaultStep());
477 toReturn->setStep(step);
478 unsigned short int precision = xmlObj.getWithDefault(
479 getPrecisionAttributeName(),
481 toReturn->setPrecision(precision);
482 if (xmlObj.hasAttribute(getMinAttributeName())) {
483 toReturn->setMin(xmlObj.getRequired<T>(getMinAttributeName()));
484 }
485 if (xmlObj.hasAttribute(getMaxAttributeName())) {
486 toReturn->setMax(xmlObj.getRequired<T>(getMaxAttributeName()));
487 }
488 return toReturn;
489}
490
491
492template<class T>
496 const ValidatortoIDMap& /*validatorIDsMap*/) const
497{
500 if (castedValidator->hasMin()) {
501 xmlObj.addAttribute<T>(getMinAttributeName(), castedValidator->getMin());
502 }
503 if (castedValidator->hasMax()) {
504 xmlObj.addAttribute<T>(getMaxAttributeName(), castedValidator->getMax());
505 }
506 xmlObj.addAttribute<T>(getStepAttributeName(), castedValidator->getStep());
507 xmlObj.addAttribute<short unsigned int>(
508 getPrecisionAttributeName(), castedValidator->getPrecision());
509}
510
511
527{
528
529public:
530
533
536 const XMLObject& xmlObj,
537 const IDtoValidatorMap& validatorIDsMap) const;
538
540 void convertValidator(
543 const ValidatortoIDMap& validatorIDsMap) const;
544
545 #ifdef HAVE_TEUCHOS_DEBUG
548 #endif
549
551
552private:
553
556
558 static const std::string& getFileMustExistAttributeName() {
559 static const std::string fileMustExistAttributeName = "fileMustExist";
561 }
562
564
565};
566
567
583{
584
585public:
586
589
592 const XMLObject& xmlObj,
593 const IDtoValidatorMap& validatorIDsMap) const;
594
596 void convertValidator(
599 const ValidatortoIDMap& validatorIDsMap) const;
600
601 #ifdef HAVE_TEUCHOS_DEBUG
604 #endif
605
607
608private:
609
612
614 static const std::string& getStringTagName() {
615 static const std::string stringTagName = "String";
616 return stringTagName;
617 }
618
620 static const std::string& getStringValueAttributeName() {
621 static const std::string stringValueAttributeName = "value";
623 }
624
626
627};
628
629template<class ValidatorType, class EntryType>
660
661
662template<class ValidatorType, class EntryType>
665 const XMLObject& xmlObj,
667{
669 if(xmlObj.hasAttribute(
671 {
673 validatorIDsMap.find(
675 getPrototypeIdAttributeName()));
676 if (result != validatorIDsMap.end() ) {
679 }
680 else {
683 "Could not find prototype validator with id: "
685 getPrototypeIdAttributeName()) << std::endl<< std::endl);
686 }
687 }
688 else {
691 xmlObj.getChild(0), validatorIDsMap), true);
692 }
693 return getConcreteValidator(prototypeValidator);
694}
695
696template<class ValidatorType, class EntryType>
697void
720
748template<class ValidatorType, class EntryType>
772
800template<class ValidatorType, class EntryType>
827
828
829
830} // namespace Teuchos
831
832
833#endif // TEUCHOS_STANDARDVALIDATORXMLCONVERTERS_HPP
834
#define TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT
A database for ValidatorXMLConverters.
Converts back and forth between XML and ParameterEntryValidators.
Writes an XML object to a parameter list.
RCP< ParameterEntryValidator > convertXML(const XMLObject &xmlObj, const IDtoValidatorMap &validatorIDsMap) const
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
Converts AnyNumberParameterEntryValidators 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.
Thrown when xml tag is encountered that is either unrecognized or inappropriate for a given context.
Converts BoolParameterEntryValidators to and from XML.
int size(const Comm< Ordinal > &comm)
Get the number of processes in the communicator.
Class for retrieving a dummy object of type T.
Class defining the traits of the number type being used in an EnhancedNumberValidator.
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
Maps Validators to integers.
ValidatorMap::const_iterator const_iterator
Thrown when a referenced validator can't be found.
Concrete serial communicator subclass.
int getTag() const
The current tag.
Convert a StringToIntegralParameterEntryValidator to and from XML.
static const std::string & getDefaultParameterAttributeName()
Name (tag) of the default parameter attribute.
RCP< ParameterEntryValidator > convertXML(const XMLObject &xmlObj, const IDtoValidatorMap &validatorIDsMap) const
void convertValidator(const RCP< const ParameterEntryValidator > validator, XMLObject &xmlObj, const ValidatortoIDMap &validatorIDsMap) const
static const std::string & getCaseSensitiveAttributeName()
Name (tag) of the caseSensitive attribute.
virtual RCP< AbstractArrayValidator< ValidatorType, EntryType > > getConcreteValidator(RCP< ValidatorType > prototypeValidator) const
Returns a concrete validator that has AbstractArrayValidator as it's parent class.
Default traits class that just returns typeid(T).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,...
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.