Teuchos - Trilinos Tools Package Version of the Day
Teuchos_DependencyXMLConverterDB.hpp
Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 //
00004 //                    Teuchos: Common Tools Package
00005 //                 Copyright (2004) Sandia Corporation
00006 //
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00038 //
00039 // ***********************************************************************
00040 // @HEADER
00041 
00042 
00043 #ifndef TEUCHOS_DEPENDENCYXMLCONVERTERDB_HPP
00044 #define TEUCHOS_DEPENDENCYXMLCONVERTERDB_HPP
00045 
00050 //Must include this and not just DependencyXMLConverter.hpp
00051 //because of convience macros
00052 #include "Teuchos_StandardDependencyXMLConverters.hpp"
00053 //Once again, done for the macros.
00054 #include "Teuchos_StandardDependencies.hpp"
00055 #include "Teuchos_XMLParameterListReader.hpp"
00056 
00057 
00058 namespace Teuchos {
00059 
00060 class Dependency;
00061 
00064 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT DependencyXMLConverterDB {
00065 public:
00066 
00069   
00076   static void addConverter(RCP<const Dependency> dependency,
00077     RCP<DependencyXMLConverter> converterToAdd);
00078   
00080 
00083   
00090   static RCP<const DependencyXMLConverter> getConverter(
00091     const Dependency& dependency);
00092 
00097   static RCP<const DependencyXMLConverter> 
00098     getConverter(const XMLObject& xmlObject);
00099 
00112   static XMLObject convertDependency(
00113     RCP<const Dependency> dependency,
00114     const XMLParameterListWriter::EntryIDsMap& entryIDsMap,
00115     ValidatortoIDMap& validatorIDsMap); 
00116 
00129   static RCP<Dependency> convertXML(
00130     const XMLObject& xmlObject, 
00131     const XMLParameterListReader::EntryIDsMap& entryIDsMap,
00132     const IDtoValidatorMap& validatorIDsMap); 
00133   
00135 
00138 
00144   static void printKnownConverters(std::ostream& out){
00145     out << "Known DependencyXMLConverters: " << std::endl;
00146     for(
00147       ConverterMap::const_iterator it = getConverterMap().begin();
00148       it != getConverterMap().end();
00149       ++it)
00150     {
00151       out << "\t" << it->first <<std::endl;
00152     }
00153   }
00154   
00156 
00157 private:
00158 
00161   
00163   typedef std::map<std::string, RCP<DependencyXMLConverter> > ConverterMap;
00164 
00166   typedef std::pair<std::string, RCP<DependencyXMLConverter> > 
00167     ConverterPair;
00168 
00172   static ConverterMap& getConverterMap();
00173   
00175 
00176 };
00177 
00178 } // end namespace Teuchos
00179 
00180 
00181 //
00182 // Helper Macros
00183 //
00184 
00189 #define TEUCHOS_ADD_DEP_CONVERTER(DEP_TYPE, CONVERTER) \
00190    Teuchos::DependencyXMLConverterDB::addConverter( \
00191         Teuchos::DummyObjectGetter< DEP_TYPE >:: \
00192           getDummyObject(), \
00193         Teuchos::rcp(new CONVERTER)); 
00194 
00201 #define TEUCHOS_ADD_TEMPLATED_NUMBER_DEPS(T) \
00202   TEUCHOS_ADD_NUMBER_VISUAL_DEP(T); \
00203   TEUCHOS_ADD_RANGE_VALIDATOR_DEP(T); \
00204   TEUCHOS_ADD_ARRAY_MODIFIER_DEP_GROUP(T);
00205 
00210 #define TEUCHOS_ADD_NUMBER_VISUAL_DEP(T) \
00211    Teuchos::DependencyXMLConverterDB::addConverter( \
00212       Teuchos::DummyObjectGetter<Teuchos::NumberVisualDependency< T > >:: \
00213       getDummyObject(), \
00214       Teuchos::rcp(new Teuchos::NumberVisualDependencyXMLConverter< T >));
00215 
00220 #define TEUCHOS_ADD_RANGE_VALIDATOR_DEP(T) \
00221    Teuchos::DependencyXMLConverterDB::addConverter( \
00222       Teuchos::DummyObjectGetter<Teuchos::RangeValidatorDependency< T > >:: \
00223         getDummyObject(), \
00224       Teuchos::rcp(new Teuchos::RangeValidatorDependencyXMLConverter< T >));
00225 
00229 #define TEUCHOS_ADD_NUMBER_ARRAY_LENGTH_DEP(DEPENDEE_TYPE , DEPENDENT_TYPE) \
00230    Teuchos::DependencyXMLConverterDB::addConverter( \
00231       Teuchos::DummyObjectGetter<Teuchos::NumberArrayLengthDependency< \
00232         DEPENDEE_TYPE , DEPENDENT_TYPE > >::getDummyObject(), \
00233         Teuchos::rcp(new Teuchos::NumberArrayLengthDependencyXMLConverter< \
00234         DEPENDEE_TYPE , DEPENDENT_TYPE >));
00235 
00240 #define TEUCHOS_ADD_TWODROW_DEP(DEPENDEE_TYPE , DEPENDENT_TYPE) \
00241    Teuchos::DependencyXMLConverterDB::addConverter( \
00242       Teuchos::DummyObjectGetter<Teuchos::TwoDRowDependency< \
00243         DEPENDEE_TYPE , DEPENDENT_TYPE > >::getDummyObject(), \
00244         Teuchos::rcp(new Teuchos::TwoDRowDependencyXMLConverter< \
00245         DEPENDEE_TYPE , DEPENDENT_TYPE >));
00246 
00250 #define TEUCHOS_ADD_TWODCOL_DEP(DEPENDEE_TYPE , DEPENDENT_TYPE) \
00251    Teuchos::DependencyXMLConverterDB::addConverter( \
00252       Teuchos::DummyObjectGetter<Teuchos::TwoDColDependency< \
00253         DEPENDEE_TYPE , DEPENDENT_TYPE > >::getDummyObject(), \
00254         Teuchos::rcp(new Teuchos::TwoDColDependencyXMLConverter< \
00255         DEPENDEE_TYPE , DEPENDENT_TYPE >));
00256 
00257 #ifdef HAVE_TEUCHOS_LONG_LONG_INT
00258 
00262 #define TEUCHOS_ADD_ARRAY_MODIFIER_DEP_GROUP(DEPENDEE_TYPE) \
00263   TEUCHOS_ADD_NUMBER_ARRAY_LENGTH_DEP( DEPENDEE_TYPE , std::string) \
00264   TEUCHOS_ADD_NUMBER_ARRAY_LENGTH_DEP( DEPENDEE_TYPE , int) \
00265   TEUCHOS_ADD_NUMBER_ARRAY_LENGTH_DEP( DEPENDEE_TYPE , long long int) \
00266   TEUCHOS_ADD_NUMBER_ARRAY_LENGTH_DEP( DEPENDEE_TYPE , double) \
00267   TEUCHOS_ADD_NUMBER_ARRAY_LENGTH_DEP( DEPENDEE_TYPE , float) \
00268   TEUCHOS_ADD_TWODROW_DEP( DEPENDEE_TYPE , std::string) \
00269   TEUCHOS_ADD_TWODROW_DEP( DEPENDEE_TYPE , int) \
00270   TEUCHOS_ADD_TWODROW_DEP( DEPENDEE_TYPE , long long int) \
00271   TEUCHOS_ADD_TWODROW_DEP( DEPENDEE_TYPE , double) \
00272   TEUCHOS_ADD_TWODROW_DEP( DEPENDEE_TYPE , float)  \
00273   TEUCHOS_ADD_TWODCOL_DEP( DEPENDEE_TYPE , std::string) \
00274   TEUCHOS_ADD_TWODCOL_DEP( DEPENDEE_TYPE , int) \
00275   TEUCHOS_ADD_TWODCOL_DEP( DEPENDEE_TYPE , long long int) \
00276   TEUCHOS_ADD_TWODCOL_DEP( DEPENDEE_TYPE , double) \
00277   TEUCHOS_ADD_TWODCOL_DEP( DEPENDEE_TYPE , float) 
00278 #else
00279 
00283 #define TEUCHOS_ADD_ARRAY_MODIFIER_DEP_GROUP(DEPENDEE_TYPE) \
00284   TEUCHOS_ADD_NUMBER_ARRAY_LENGTH_DEP( DEPENDEE_TYPE , std::string) \
00285   TEUCHOS_ADD_NUMBER_ARRAY_LENGTH_DEP( DEPENDEE_TYPE , int) \
00286   TEUCHOS_ADD_NUMBER_ARRAY_LENGTH_DEP( DEPENDEE_TYPE , double) \
00287   TEUCHOS_ADD_NUMBER_ARRAY_LENGTH_DEP( DEPENDEE_TYPE , float) \
00288   TEUCHOS_ADD_TWODROW_DEP( DEPENDEE_TYPE , std::string) \
00289   TEUCHOS_ADD_TWODROW_DEP( DEPENDEE_TYPE , int) \
00290   TEUCHOS_ADD_TWODROW_DEP( DEPENDEE_TYPE , double) \
00291   TEUCHOS_ADD_TWODROW_DEP( DEPENDEE_TYPE , float)  \
00292   TEUCHOS_ADD_TWODCOL_DEP( DEPENDEE_TYPE , std::string) \
00293   TEUCHOS_ADD_TWODCOL_DEP( DEPENDEE_TYPE , int) \
00294   TEUCHOS_ADD_TWODCOL_DEP( DEPENDEE_TYPE , double) \
00295   TEUCHOS_ADD_TWODCOL_DEP( DEPENDEE_TYPE , float) 
00296 #endif
00297 
00298 
00299 #endif // TEUCHOS_DEPENDENCYXMLCONVERTERDB_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines