Teuchos - Trilinos Tools Package Version of the Day
Loading...
Searching...
No Matches
Teuchos_ValidatorXMLConverterDB.cpp
1// @HEADER
2// *****************************************************************************
3// Teuchos: Common Tools Package
4//
5// Copyright 2004 NTESS and the Teuchos contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
11#include "Teuchos_StandardParameterEntryValidators.hpp"
13#include "Teuchos_StaticSetupMacro.hpp"
14
15
16
17namespace Teuchos {
18
19
23 getConverterMap().insert(ConverterPair(
24 validator->getXMLTypeName(), converterToAdd));
25}
26
27
30{
31 ConverterMap::const_iterator it = getConverterMap().find(validator.getXMLTypeName());
32 TEUCHOS_TEST_FOR_EXCEPTION(it == getConverterMap().end(),
34 "Could not find a ValidatorXMLConverter for validator type " <<
35 validator.getXMLTypeName() << std::endl <<
36 "Try adding an appropriate converter to the ValidatorXMLConverterDB " <<
37 "in order solve this problem." << std::endl << std::endl
38 )
39 return it->second;
40}
41
42
45{
46 std::string validatorType = xmlObject.getRequired(
48 ConverterMap::const_iterator it = getConverterMap().find(validatorType);
49 TEUCHOS_TEST_FOR_EXCEPTION(it == getConverterMap().end(),
51 "Could not find a ValidatorXMLConverter for type " << validatorType <<
52 std::endl <<
53 "Try adding an appropriate converter to the ValidatorXMLConverterDB " <<
54 "in order solve this problem." << std::endl << std::endl
55 )
56 return it->second;
57}
58
59
63 bool assignID)
64{
65 return getConverter(*validator)->fromValidatortoXML(
66 validator, validatorIDsMap, assignID);
67}
68
69
77
78
79ValidatorXMLConverterDB::ConverterMap&
80ValidatorXMLConverterDB::getConverterMap()
81{
82 static ConverterMap masterMap;
83 return masterMap;
84 // See default setup code below!
85}
86
87
89 out << "Known ValidatorXMLConverters: " << std::endl;
90 for(
91 ConverterMap::const_iterator it = getConverterMap().begin();
92 it != getConverterMap().end();
93 ++it)
94 {
95 out << "\t" << it->first <<std::endl;
96 }
97}
98
99
100} // namespace Teuchos
101
102
103namespace {
104
105
106TEUCHOS_STATIC_SETUP()
107{
111
114
117
119
121
126
127}
128
129
130} // namespace
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.
Smart reference counting pointer class for automatic garbage collection.
A simple validator that only allows certain string values to be choosen or simply enforces that a par...
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.
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 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.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...