Sacado_ParameterLibraryBaseImp.hpp

Go to the documentation of this file.
00001 // $Id: Sacado_ParameterLibraryBaseImp.hpp,v 1.3 2007/07/09 17:04:03 etphipp Exp $ 
00002 // $Source: /space/CVS/Trilinos/packages/sacado/src/parameter/Sacado_ParameterLibraryBaseImp.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 FamilyType, template<typename> class EntryType>
00035 Sacado::ParameterLibraryBase<FamilyType,EntryType>::
00036 ParameterLibraryBase()
00037 {
00038 }
00039 
00040 template <typename FamilyType, template<typename> class EntryType>
00041 Sacado::ParameterLibraryBase<FamilyType,EntryType>::
00042 ~ParameterLibraryBase()
00043 {
00044 }
00045 
00046 template <typename FamilyType, template<typename> class EntryType>
00047 bool
00048 Sacado::ParameterLibraryBase<FamilyType,EntryType>::
00049 isParameter(const std::string& name) const
00050 {
00051   // Get family
00052   typename FamilyMap::const_iterator it = library.find(name);
00053 
00054   return (it != library.end());
00055 }
00056 
00057 template <typename FamilyType, template<typename> class EntryType>
00058 template <class ValueType>
00059 bool
00060 Sacado::ParameterLibraryBase<FamilyType,EntryType>::
00061 isParameterForType(const std::string& name) const
00062 {
00063   // Get family
00064   typename FamilyMap::const_iterator it = library.find(name);
00065 
00066   // First check parameter is in the library
00067   if (it == library.end())
00068     return false;
00069 
00070   // Determine if type is in the family
00071   return (*it).second->template hasType<ValueType>();
00072 }
00073 
00074 template <typename FamilyType, template<typename> class EntryType>
00075 bool
00076 Sacado::ParameterLibraryBase<FamilyType,EntryType>::
00077 addParameterFamily(const std::string& name, 
00078       bool supports_ad, 
00079       bool supports_analytic)
00080 {
00081   // Check that the parameter is not in the library
00082   if (isParameter(name))
00083     return false;
00084 
00085   Teuchos::RCP<FamilyType> f = 
00086     Teuchos::rcp(new FamilyType(name, supports_ad, supports_analytic));
00087   library.insert(std::pair< std::string, 
00088                 Teuchos::RCP<FamilyType> >(name, f));
00089 
00090   return true;
00091 }
00092 
00093 template <typename FamilyType, template<typename> class EntryType>
00094 template <class ValueType>
00095 bool
00096 Sacado::ParameterLibraryBase<FamilyType,EntryType>::
00097 addEntry(const std::string& name, 
00098    const Teuchos::RCP< EntryType<ValueType> >& entry)
00099 {
00100   // Get family
00101   typename FamilyMap::iterator it = library.find(name);
00102   
00103   // First check parameter is in the library
00104   TEST_FOR_EXCEPTION(it == library.end(), 
00105          std::logic_error,
00106          std::string("Sacado::ParameterLibraryBase::addEntry():  ")
00107          + "Parameter family " + name
00108          + " is not in the library");
00109 
00110   // Call family's addEntry method
00111   return (*it).second->addEntry(entry);
00112 }
00113 
00114 template <typename FamilyType, template<typename> class EntryType>
00115 template <class ValueType>
00116 Teuchos::RCP< EntryType<ValueType> >
00117 Sacado::ParameterLibraryBase<FamilyType,EntryType>::
00118 getEntry(const std::string& name)
00119 {
00120   // Get family
00121   typename FamilyMap::iterator it = library.find(name);
00122   
00123   // First check parameter is in the library
00124   TEST_FOR_EXCEPTION(it == library.end(), 
00125          std::logic_error,
00126          std::string("Sacado::ParameterLibraryBase::getEntry():  ")
00127          + "Parameter family " + name
00128          + " is not in the library");
00129 
00130   // Call family's getEntry method
00131   return (*it).second->template getEntry<ValueType>();
00132 }
00133 
00134 template <typename FamilyType, template<typename> class EntryType>
00135 template <typename BaseValueType>
00136 void
00137 Sacado::ParameterLibraryBase<FamilyType,EntryType>::
00138 fillVector(const Teuchos::Array<std::string>& names,
00139      const Teuchos::Array<BaseValueType>& values,
00140      ParameterVectorBase<FamilyType,BaseValueType>& pv)
00141 {
00142   typename FamilyMap::iterator it;
00143 
00144   // Fill in parameters
00145   for (unsigned int i=0; i<names.size(); i++) {
00146     it = library.find(names[i]);
00147     TEST_FOR_EXCEPTION(
00148        it == library.end(), 
00149        std::logic_error,
00150        std::string("Sacado::ParameterLibraryBase::fillVector():  ")
00151        + "Invalid parameter family " + names[i]);
00152     pv.addParam((*it).second, values[i]);
00153   }
00154 }

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