Teuchos - Trilinos Tools Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_DependencyXMLConverterDB.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_DEPENDENCYXMLCONVERTERDB_HPP
44 #define TEUCHOS_DEPENDENCYXMLCONVERTERDB_HPP
45 
50 //Must include this and not just DependencyXMLConverter.hpp
51 //because of convience macros
53 //Once again, done for the macros.
56 
57 
58 namespace Teuchos {
59 
60 class Dependency;
61 
64 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT DependencyXMLConverterDB {
65 public:
66 
69 
76  static void addConverter(RCP<const Dependency> dependency,
77  RCP<DependencyXMLConverter> converterToAdd);
78 
80 
83 
90  static RCP<const DependencyXMLConverter> getConverter(
91  const Dependency& dependency);
92 
98  getConverter(const XMLObject& xmlObject);
99 
112  static XMLObject convertDependency(
113  RCP<const Dependency> dependency,
114  const XMLParameterListWriter::EntryIDsMap& entryIDsMap,
115  ValidatortoIDMap& validatorIDsMap);
116 
129  static RCP<Dependency> convertXML(
130  const XMLObject& xmlObject,
131  const XMLParameterListReader::EntryIDsMap& entryIDsMap,
132  const IDtoValidatorMap& validatorIDsMap);
133 
135 
138 
144  static void printKnownConverters(std::ostream& out){
145  out << "Known DependencyXMLConverters: " << std::endl;
146  for(
147  ConverterMap::const_iterator it = getConverterMap().begin();
148  it != getConverterMap().end();
149  ++it)
150  {
151  out << "\t" << it->first <<std::endl;
152  }
153  }
154 
156 
157 private:
158 
161 
163  typedef std::map<std::string, RCP<DependencyXMLConverter> > ConverterMap;
164 
166  typedef std::pair<std::string, RCP<DependencyXMLConverter> >
167  ConverterPair;
168 
172  static ConverterMap& getConverterMap();
173 
175 
176 };
177 
178 } // end namespace Teuchos
179 
180 
181 //
182 // Helper Macros
183 //
184 
189 #define TEUCHOS_ADD_DEP_CONVERTER(DEP_TYPE, CONVERTER) \
190  Teuchos::DependencyXMLConverterDB::addConverter( \
191  Teuchos::DummyObjectGetter< DEP_TYPE >:: \
192  getDummyObject(), \
193  Teuchos::rcp(new CONVERTER));
194 
201 #define TEUCHOS_ADD_TEMPLATED_NUMBER_DEPS(T) \
202  TEUCHOS_ADD_NUMBER_VISUAL_DEP(T); \
203  TEUCHOS_ADD_RANGE_VALIDATOR_DEP(T); \
204  TEUCHOS_ADD_ARRAY_MODIFIER_DEP_GROUP(T);
205 
210 #define TEUCHOS_ADD_NUMBER_VISUAL_DEP(T) \
211  Teuchos::DependencyXMLConverterDB::addConverter( \
212  Teuchos::DummyObjectGetter<Teuchos::NumberVisualDependency< T > >:: \
213  getDummyObject(), \
214  Teuchos::rcp(new Teuchos::NumberVisualDependencyXMLConverter< T >));
215 
220 #define TEUCHOS_ADD_RANGE_VALIDATOR_DEP(T) \
221  Teuchos::DependencyXMLConverterDB::addConverter( \
222  Teuchos::DummyObjectGetter<Teuchos::RangeValidatorDependency< T > >:: \
223  getDummyObject(), \
224  Teuchos::rcp(new Teuchos::RangeValidatorDependencyXMLConverter< T >));
225 
229 #define TEUCHOS_ADD_NUMBER_ARRAY_LENGTH_DEP(DEPENDEE_TYPE , DEPENDENT_TYPE) \
230  Teuchos::DependencyXMLConverterDB::addConverter( \
231  Teuchos::DummyObjectGetter<Teuchos::NumberArrayLengthDependency< \
232  DEPENDEE_TYPE , DEPENDENT_TYPE > >::getDummyObject(), \
233  Teuchos::rcp(new Teuchos::NumberArrayLengthDependencyXMLConverter< \
234  DEPENDEE_TYPE , DEPENDENT_TYPE >));
235 
240 #define TEUCHOS_ADD_TWODROW_DEP(DEPENDEE_TYPE , DEPENDENT_TYPE) \
241  Teuchos::DependencyXMLConverterDB::addConverter( \
242  Teuchos::DummyObjectGetter<Teuchos::TwoDRowDependency< \
243  DEPENDEE_TYPE , DEPENDENT_TYPE > >::getDummyObject(), \
244  Teuchos::rcp(new Teuchos::TwoDRowDependencyXMLConverter< \
245  DEPENDEE_TYPE , DEPENDENT_TYPE >));
246 
250 #define TEUCHOS_ADD_TWODCOL_DEP(DEPENDEE_TYPE , DEPENDENT_TYPE) \
251  Teuchos::DependencyXMLConverterDB::addConverter( \
252  Teuchos::DummyObjectGetter<Teuchos::TwoDColDependency< \
253  DEPENDEE_TYPE , DEPENDENT_TYPE > >::getDummyObject(), \
254  Teuchos::rcp(new Teuchos::TwoDColDependencyXMLConverter< \
255  DEPENDEE_TYPE , DEPENDENT_TYPE >));
256 
261 #define TEUCHOS_ADD_ARRAY_MODIFIER_DEP_GROUP(DEPENDEE_TYPE) \
262  TEUCHOS_ADD_NUMBER_ARRAY_LENGTH_DEP( DEPENDEE_TYPE , std::string) \
263  TEUCHOS_ADD_NUMBER_ARRAY_LENGTH_DEP( DEPENDEE_TYPE , int) \
264  TEUCHOS_ADD_NUMBER_ARRAY_LENGTH_DEP( DEPENDEE_TYPE , long long int) \
265  TEUCHOS_ADD_NUMBER_ARRAY_LENGTH_DEP( DEPENDEE_TYPE , double) \
266  TEUCHOS_ADD_NUMBER_ARRAY_LENGTH_DEP( DEPENDEE_TYPE , float) \
267  TEUCHOS_ADD_TWODROW_DEP( DEPENDEE_TYPE , std::string) \
268  TEUCHOS_ADD_TWODROW_DEP( DEPENDEE_TYPE , int) \
269  TEUCHOS_ADD_TWODROW_DEP( DEPENDEE_TYPE , long long int) \
270  TEUCHOS_ADD_TWODROW_DEP( DEPENDEE_TYPE , double) \
271  TEUCHOS_ADD_TWODROW_DEP( DEPENDEE_TYPE , float) \
272  TEUCHOS_ADD_TWODCOL_DEP( DEPENDEE_TYPE , std::string) \
273  TEUCHOS_ADD_TWODCOL_DEP( DEPENDEE_TYPE , int) \
274  TEUCHOS_ADD_TWODCOL_DEP( DEPENDEE_TYPE , long long int) \
275  TEUCHOS_ADD_TWODCOL_DEP( DEPENDEE_TYPE , double) \
276  TEUCHOS_ADD_TWODCOL_DEP( DEPENDEE_TYPE , float)
277 
278 
279 #endif // TEUCHOS_DEPENDENCYXMLCONVERTERDB_HPP
Writes an XML object to a parameter list.
Provides ability to lookup DependencyXMLConverterDB.
Maps Validators to integers.
This class represents a depndency between elements in a Parameter List.
static void printKnownConverters(std::ostream &out)
prints the xml tags associated with all known converters
Representation of an XML data tree. XMLObject is a ref-counted handle to a XMLObjectImplem object...
A collection of standard DependencyXMLConverters.
std::map< RCP< const ParameterEntry >, ParameterEntry::ParameterEntryID, RCPConstComp > EntryIDsMap
A class for mapping validators to integers.
A collection of standard dependencies.
std::map< ParameterEntry::ParameterEntryID, RCP< ParameterEntry > > EntryIDsMap
Convenience typedef.
Smart reference counting pointer class for automatic garbage collection.