|
Teuchos - Trilinos Tools Package
Version of the Day
|
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 #include "Teuchos_DependencyXMLConverterDB.hpp" 00043 #include "Teuchos_StaticSetupMacro.hpp" 00044 00045 00046 00047 namespace Teuchos { 00048 00049 00050 00051 void DependencyXMLConverterDB::addConverter( 00052 RCP<const Dependency> dependency, 00053 RCP<DependencyXMLConverter> converterToAdd) 00054 { 00055 getConverterMap().insert( 00056 ConverterPair(dependency->getTypeAttributeValue(), converterToAdd)); 00057 } 00058 00059 00060 RCP<const DependencyXMLConverter> 00061 DependencyXMLConverterDB::getConverter(const Dependency& dependency) 00062 { 00063 ConverterMap::const_iterator it = 00064 getConverterMap().find(dependency.getTypeAttributeValue()); 00065 TEUCHOS_TEST_FOR_EXCEPTION(it == getConverterMap().end(), 00066 CantFindDependencyConverterException, 00067 "Could not find a DependencyXMLConverter for a dependency with " 00068 "attribute tag " << dependency.getTypeAttributeValue() << 00069 "!" << std::endl << 00070 "Try adding an appropriate converter to the DependencyXMLConverterDB " << 00071 "in order to solve this problem." << std::endl << std::endl); 00072 return it->second; 00073 } 00074 00075 00076 RCP<const DependencyXMLConverter> 00077 DependencyXMLConverterDB::getConverter(const XMLObject& xmlObject) 00078 { 00079 std::string dependencyType = xmlObject.getRequired( 00080 DependencyXMLConverter::getTypeAttributeName()); 00081 ConverterMap::const_iterator it = getConverterMap().find(dependencyType); 00082 #ifdef HAVE_TEUCHOS_DEBUG 00083 std::ostringstream sout; 00084 printKnownConverters(sout); 00085 #endif 00086 std::string extraError = 00087 #ifdef HAVE_TEUCHOS_DEBUG 00088 sout.str(); 00089 #else 00090 ""; 00091 #endif 00092 00093 TEUCHOS_TEST_FOR_EXCEPTION(it == getConverterMap().end(), 00094 CantFindDependencyConverterException, 00095 "Could not find a DependencyXMLConverter for a dependency of type " << 00096 dependencyType << "!" << std::endl << 00097 "Try adding an appropriate converter to the DependencyXMLConverterDB " << 00098 "in order to solve this problem." << std::endl << std::endl << extraError 00099 ); 00100 return it->second; 00101 } 00102 00103 XMLObject DependencyXMLConverterDB::convertDependency( 00104 RCP<const Dependency> dependency, 00105 const XMLParameterListWriter::EntryIDsMap& entryIDsMap, 00106 ValidatortoIDMap& validatorIDsMap) 00107 { 00108 return getConverter(*dependency)->fromDependencytoXML( 00109 dependency, entryIDsMap, validatorIDsMap); 00110 } 00111 00112 RCP<Dependency> DependencyXMLConverterDB::convertXML( 00113 const XMLObject& xmlObject, 00114 const XMLParameterListReader::EntryIDsMap& entryIDsMap, 00115 const IDtoValidatorMap& validatorIDsMap) 00116 { 00117 return DependencyXMLConverterDB::getConverter(xmlObject)-> 00118 fromXMLtoDependency(xmlObject, entryIDsMap, validatorIDsMap); 00119 } 00120 00121 DependencyXMLConverterDB::ConverterMap& 00122 DependencyXMLConverterDB::getConverterMap() 00123 { 00124 static ConverterMap masterMap; 00125 return masterMap; 00126 } 00127 00128 00129 } // namespace Teuchos 00130 00131 00132 namespace { 00133 00134 00135 TEUCHOS_STATIC_SETUP() 00136 { 00137 TEUCHOS_ADD_TEMPLATED_NUMBER_DEPS(int) 00138 TEUCHOS_ADD_NUMBER_VISUAL_DEP(float) 00139 TEUCHOS_ADD_RANGE_VALIDATOR_DEP(float) 00140 TEUCHOS_ADD_NUMBER_VISUAL_DEP(double) 00141 TEUCHOS_ADD_RANGE_VALIDATOR_DEP(double) 00142 00143 #ifdef HAVE_TEUCHOS_LONG_LONG_INT 00144 TEUCHOS_ADD_TEMPLATED_NUMBER_DEPS(long long int) 00145 #endif // HAVE_TEUCHOS_LONG_LONG_INT 00146 00147 TEUCHOS_ADD_DEP_CONVERTER( 00148 Teuchos::StringValidatorDependency, 00149 Teuchos::StringValidatorDependencyXMLConverter) 00150 TEUCHOS_ADD_DEP_CONVERTER( 00151 Teuchos::StringVisualDependency, 00152 Teuchos::StringVisualDependencyXMLConverter) 00153 TEUCHOS_ADD_DEP_CONVERTER( 00154 Teuchos::BoolValidatorDependency, 00155 Teuchos::BoolValidatorDependencyXMLConverter) 00156 TEUCHOS_ADD_DEP_CONVERTER( 00157 Teuchos::BoolVisualDependency, 00158 Teuchos::BoolVisualDependencyXMLConverter) 00159 TEUCHOS_ADD_DEP_CONVERTER( 00160 Teuchos::ConditionVisualDependency, 00161 Teuchos::ConditionVisualDependencyXMLConverter) 00162 } 00163 00164 00165 } //namespace 00166
1.7.6.1