Sacado_ParameterFamilyBaseImp.hpp

Go to the documentation of this file.
00001 // $Id: Sacado_ParameterFamilyBaseImp.hpp,v 1.2 2007/07/09 17:04:03 etphipp Exp $ 
00002 // $Source: /space/CVS/Trilinos/packages/sacado/src/parameter/Sacado_ParameterFamilyBaseImp.hpp,v $ 
00003 // @HEADER
00004 // ***********************************************************************
00005 // 
00006 //                           Sacado Package
00007 //                 Copyright (2006) Sandia Corporation
00008 // 
00009 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00010 // the U.S. Government retains certain rights in this software.
00011 // 
00012 // This library is free software; you can redistribute it and/or modify
00013 // it under the terms of the GNU Lesser General Public License as
00014 // published by the Free Software Foundation; either version 2.1 of the
00015 // License, or (at your option) any later version.
00016 //  
00017 // This library is distributed in the hope that it will be useful, but
00018 // WITHOUT ANY WARRANTY; without even the implied warranty of
00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020 // Lesser General Public License for more details.
00021 //  
00022 // You should have received a copy of the GNU Lesser General Public
00023 // License along with this library; if not, write to the Free Software
00024 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00025 // USA
00026 // Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
00027 // (etphipp@sandia.gov).
00028 // 
00029 // ***********************************************************************
00030 // @HEADER
00031 
00032 #include "Teuchos_TestForException.hpp"
00033 
00034 template <typename EntryBase, template<typename> class EntryType>
00035 Sacado::ParameterFamilyBase<EntryBase,EntryType>::
00036 ParameterFamilyBase(const std::string& name_, 
00037         bool supports_ad_, 
00038         bool supports_analytic_) :
00039   family(),
00040   name(name_),
00041   supports_ad(supports_ad_),
00042   supports_analytic(supports_analytic_)
00043 {
00044 }
00045 
00046 template <typename EntryBase, template<typename> class EntryType>
00047 Sacado::ParameterFamilyBase<EntryBase,EntryType>::
00048 ~ParameterFamilyBase() 
00049 {
00050 }
00051 
00052 template <typename EntryBase, template<typename> class EntryType>
00053 std::string
00054 Sacado::ParameterFamilyBase<EntryBase,EntryType>::
00055 getName() const 
00056 {
00057   return name;
00058 }
00059 
00060 template <typename EntryBase, template<typename> class EntryType>
00061 bool
00062 Sacado::ParameterFamilyBase<EntryBase,EntryType>::
00063 supportsAD() const
00064 {
00065   return supports_ad;
00066 }
00067 
00068 template <typename EntryBase, template<typename> class EntryType>
00069 bool
00070 Sacado::ParameterFamilyBase<EntryBase,EntryType>::
00071 supportsAnalytic() const
00072 {
00073   return supports_analytic;
00074 }
00075 
00076 template <typename EntryBase, template<typename> class EntryType>
00077 template <class ValueType>
00078 bool
00079 Sacado::ParameterFamilyBase<EntryBase,EntryType>::
00080 hasType() const 
00081 {
00082 
00083   // Convert typename ValueType to string
00084   std::string valueTypeString = getTypeName<ValueType>();
00085 
00086   // Find entry corresponding to this ValueType
00087   const_iterator it = family.find(valueTypeString);
00088   if (it == family.end()) 
00089     return false;
00090 
00091   return true;
00092 }
00093 
00094 template <typename EntryBase, template<typename> class EntryType>
00095 template <class ValueType>
00096 bool
00097 Sacado::ParameterFamilyBase<EntryBase,EntryType>::
00098 addEntry(const Teuchos::RCP< EntryType<ValueType> >& entry)
00099 {
00100   // Get string representation of ValueType
00101   std::string valueTypeString = getTypeName<ValueType>();
00102     
00103   // Determine if entry already exists for parameter and type
00104   iterator it = family.find(valueTypeString);
00105 
00106   // If it does not, add it
00107   if (it == family.end()) {
00108     family.insert(std::pair<std::string, 
00109       Teuchos::RCP<EntryBase> >(valueTypeString, entry));
00110   }
00111 
00112   else {
00113     return false;
00114   }
00115 
00116   return true;
00117 }
00118 
00119 template <typename EntryBase, template<typename> class EntryType>
00120 template <class ValueType>
00121 Teuchos::RCP< EntryType<ValueType> >
00122 Sacado::ParameterFamilyBase<EntryBase,EntryType>::
00123 getEntry() {
00124 
00125   // Convert typename ValueType to string
00126   std::string valueTypeString = getTypeName<ValueType>();
00127 
00128   // Find entry corresponding to this ValueType
00129   iterator it = family.find(valueTypeString);
00130   TEST_FOR_EXCEPTION(it == family.end(), 
00131          std::logic_error,
00132          std::string("Sacado::ParameterFamilyBase::getEntry():  ")
00133          + "Parameter entry " + name
00134          + " does not have a parameter of type" 
00135          + valueTypeString);
00136 
00137   // Cast entry to LOCA::Parameter::Entry<ValueType>
00138   Teuchos::RCP< EntryType<ValueType> > entry = 
00139     Teuchos::rcp_dynamic_cast< EntryType<ValueType> >((*it).second);
00140   TEST_FOR_EXCEPTION(entry == Teuchos::null, 
00141          std::logic_error,
00142          std::string("Sacado::ParameterFamilyBase::getEntry():  ")
00143          + "Parameter entry " + name
00144          + " of type" + valueTypeString
00145          + " has incorrect entry type");
00146   
00147   return entry;
00148 }
00149 
00150 template <typename EntryBase, template<typename> class EntryType>
00151 template <class ValueType>
00152 Teuchos::RCP< const EntryType<ValueType> >
00153 Sacado::ParameterFamilyBase<EntryBase,EntryType>::
00154 getEntry() const {
00155 
00156   // Convert typename ValueType to string
00157   std::string valueTypeString = getTypeName<ValueType>();
00158 
00159   // Find entry corresponding to this ValueType
00160   const_iterator it = family.find(valueTypeString);
00161   TEST_FOR_EXCEPTION(it == family.end(), 
00162          std::logic_error,
00163          std::string("Sacado::ParameterFamilyBase::getEntry():  ")
00164          + "Parameter entry " + name
00165          + " does not have a parameter of type" 
00166          + valueTypeString);
00167 
00168   // Cast entry to LOCA::Parameter::Entry<ValueType>
00169   Teuchos::RCP< const EntryType<ValueType> > entry =
00170     Teuchos::rcp_dynamic_cast< const EntryType<ValueType> >((*it).second);
00171   TEST_FOR_EXCEPTION(entry == Teuchos::null, 
00172          std::logic_error,
00173          std::string("Sacado::ParameterFamilyBase::getEntry():  ")
00174          + "Parameter entry " + name
00175          + " of type" + valueTypeString
00176          + " has incorrect entry type");
00177 
00178   return entry;
00179 }
00180 
00181 template <typename EntryBase, template<typename> class EntryType>
00182 void
00183 Sacado::ParameterFamilyBase<EntryBase,EntryType>::
00184 printFamily(std::ostream& os) const
00185 {
00186   os << "Parameter family map:  " << name << std::endl;
00187 
00188   // Loop over all entries
00189   for (const_iterator it = family.begin(); it != family.end(); it++) {
00190     os << "\t" << (*it).first << std::endl;
00191   }
00192 
00193 }
00194 
00195 template <typename EntryBase, template<typename> class EntryType>
00196 template <class ValueType>
00197 std::string
00198 Sacado::ParameterFamilyBase<EntryBase,EntryType>::
00199 getTypeName() const {
00200   return typeid(ValueType).name();
00201 }

Generated on Wed May 12 21:59:04 2010 for Sacado Package Browser (Single Doxygen Collection) by  doxygen 1.4.7