Teuchos Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
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
49namespace Teuchos {
50
51
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
95 bool assignID)
96{
97 return getConverter(*validator)->fromValidatortoXML(
98 validator, validatorIDsMap, assignID);
99}
100
101
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
135namespace {
136
137
139{
143
146
149
151
153
158
159}
160
161
162} // namespace
#define TEUCHOS_STATIC_SETUP()
Run setup code statically in a translation unit.
A database for ValidatorXMLConverters.
#define TEUCHOS_ADD_ARRAYVALIDATOR_CONVERTER(VALIDATORTYPE, ENTRYTYPE)
Add ArrayValidator<VALIDATORTYPE, ENTRYTYPE> to set of supported parameter types.
#define TEUCHOS_ADD_ENHANCEDNUMBERVALIDATOR_CONVERTER(T)
Add EnhancedNumberValidator<T> to the set of supported parameter types.
#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...
#define TEUCHOS_ADD_NUMBERTYPE_VALIDATOR_CONVERTERS(T)
Add numeric parameter types for type T.
#define TEUCHOS_ADD_STRINGTOINTEGRALVALIDATOR_CONVERTER(INTEGRALTYPE)
Add StringToIntegralParameterEntryValidator<INTEGRAL_TYPE> to set of supported parameter types.
Standard implementation of a ParameterEntryValidator that accepts numbers from a number of different ...
Converts AnyNumberParameterEntryValidators to and from XML.
Standard implementation of a BoolParameterEntryValidator that accepts bool values (true/false) or str...
Converts BoolParameterEntryValidators to and from XML.
Thrown when the ValidatorXMLConverterDB can't find an appropriate converter.
Maps Validators to integers.
Abstract interface for an object that can validate a ParameterEntry's value.
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.
Concrete serial communicator subclass.
A simple validator that only allows certain string values to be choosen or simply enforces that a par...
std::pair< std::string, RCP< ValidatorXMLConverter > > ConverterPair
convience typedef.
static void addConverter(RCP< const ParameterEntryValidator > validator, RCP< ValidatorXMLConverter > converterToAdd)
Add a converter to the database.
static XMLObject convertValidator(RCP< const ParameterEntryValidator > validator, const ValidatortoIDMap &validatorIDsMap, bool assignedID=true)
Given a validator converts the validator to XML.
std::map< std::string, RCP< ValidatorXMLConverter > > ConverterMap
convience class.
static void printKnownConverters(std::ostream &out)
prints the xml tags associated with all known converters
static RCP< const ValidatorXMLConverter > getConverter(const ParameterEntryValidator &validator)
Get an appropriate ValidatorXMLConverter given a Validator.
static ConverterMap & getConverterMap()
Gets the default converter to be used to convert Validators.
static RCP< ParameterEntryValidator > convertXML(const XMLObject &xmlObject, const IDtoValidatorMap &validatorIDsMap)
Given an XMLObject converts the XMLObject to a ParameterEntryValidator and inserts the validator into...
static const std::string & getTypeAttributeName()
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.
EVerbosityLevel
Verbosity level.