Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_ValidatorXMLConverterDB.cpp
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 
46 
47 
48 
49 namespace Teuchos {
50 
51 
54  RCP<ValidatorXMLConverter> converterToAdd){
56  validator->getXMLTypeName(), converterToAdd));
57 }
58 
59 
62 {
63  ConverterMap::const_iterator it = getConverterMap().find(validator.getXMLTypeName());
66  "Could not find a ValidatorXMLConverter for validator type " <<
67  validator.getXMLTypeName() << std::endl <<
68  "Try adding an appropriate converter to the ValidatorXMLConverterDB " <<
69  "in order solve this problem." << std::endl << std::endl
70  )
71  return it->second;
72 }
73 
74 
77 {
78  std::string validatorType = xmlObject.getRequired(
80  ConverterMap::const_iterator it = getConverterMap().find(validatorType);
83  "Could not find a ValidatorXMLConverter for type " << validatorType <<
84  std::endl <<
85  "Try adding an appropriate converter to the ValidatorXMLConverterDB " <<
86  "in order solve this problem." << std::endl << std::endl
87  )
88  return it->second;
89 }
90 
91 
94  const ValidatortoIDMap& validatorIDsMap,
95  bool assignID)
96 {
97  return getConverter(*validator)->fromValidatortoXML(
98  validator, validatorIDsMap, assignID);
99 }
100 
101 
103  const XMLObject& xmlObject,
104  const IDtoValidatorMap& validatorIDsMap)
105 {
107  getConverter(xmlObject)->fromXMLtoValidator(xmlObject, validatorIDsMap);
108 }
109 
110 
113 {
114  static ConverterMap masterMap;
115  return masterMap;
116  // See default setup code below!
117 }
118 
119 
121  out << "Known ValidatorXMLConverters: " << std::endl;
122  for(
123  ConverterMap::const_iterator it = getConverterMap().begin();
124  it != getConverterMap().end();
125  ++it)
126  {
127  out << "\t" << it->first <<std::endl;
128  }
129 }
130 
131 
132 } // namespace Teuchos
133 
134 
135 namespace {
136 
137 
139 {
143 
146 
149 
151 
153 
158 
159 }
160 
161 
162 } // namespace
EVerbosityLevel
Verbosity level.
Maps Validators to integers.
Converts StringValidators to and from XML.
static void addConverter(RCP< const ParameterEntryValidator > validator, RCP< ValidatorXMLConverter > converterToAdd)
Add a converter to the database.
Converts AnyNumberParameterEntryValidators to and from XML.
Converts FileNameValidators to and from XML.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
#define TEUCHOS_ADD_ARRAYVALIDATOR_CONVERTER(VALIDATORTYPE, ENTRYTYPE)
Add ArrayValidator&lt;VALIDATORTYPE, ENTRYTYPE&gt; to set of supported parameter types. ...
virtual const std::string getXMLTypeName() const =0
Get a string that should be used as a value of the type attribute when serializing it to XML...
static RCP< const ValidatorXMLConverter > getConverter(const ParameterEntryValidator &validator)
Get an appropriate ValidatorXMLConverter given a Validator.
#define TEUCHOS_ADD_NUMBERTYPE_VALIDATOR_CONVERTERS(T)
Add numeric parameter types for type T.
#define TEUCHOS_ADD_ENHANCEDNUMBERVALIDATOR_CONVERTER(T)
Add EnhancedNumberValidator&lt;T&gt; to the set of supported parameter types.
static const std::string & getTypeAttributeName()
static XMLObject convertValidator(RCP< const ParameterEntryValidator > validator, const ValidatortoIDMap &validatorIDsMap, bool assignedID=true)
Given a validator converts the validator to XML.
Thrown when the ValidatorXMLConverterDB can&#39;t find an appropriate converter.
Representation of an XML data tree. XMLObject is a ref-counted handle to a XMLObjectImplem object...
#define TEUCHOS_ADD_VALIDATOR_CONVERTER(VALIDATOR_TYPE, CONVERTER_TYPE)
Add a validator converter of type CONVERTER_TYPE which converts validators of VALIDATOR_TYPE to the m...
A database for ValidatorXMLConverters.
Standard implementation of a BoolParameterEntryValidator that accepts bool values (true/false) or str...
A class for mapping validators to integers.
std::pair< std::string, RCP< ValidatorXMLConverter > > ConverterPair
convience typedef.
static RCP< ParameterEntryValidator > convertXML(const XMLObject &xmlObject, const IDtoValidatorMap &validatorIDsMap)
Given an XMLObject converts the XMLObject to a ParameterEntryValidator and inserts the validator into...
A simple validator that only allows certain string values to be choosen or simply enforces that a par...
Abstract interface for an object that can validate a ParameterEntry&#39;s value.
#define TEUCHOS_ADD_STRINGTOINTEGRALVALIDATOR_CONVERTER(INTEGRALTYPE)
Add StringToIntegralParameterEntryValidator&lt;INTEGRAL_TYPE&gt; to set of supported parameter types...
Class uesd to validate a particular type of number.
static void printKnownConverters(std::ostream &out)
prints the xml tags associated with all known converters
std::map< std::string, RCP< ValidatorXMLConverter > > ConverterMap
convience class.
Converts BoolParameterEntryValidators to and from XML.
Smart reference counting pointer class for automatic garbage collection.
static ConverterMap & getConverterMap()
Gets the default converter to be used to convert Validators.
Standard implementation of a ParameterEntryValidator that accepts numbers from a number of different ...
const std::string & getRequired(const std::string &name) const
Get an attribute, throwing an std::exception if it is not found.
TEUCHOS_STATIC_SETUP()