00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
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
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
00064 typename FamilyMap::const_iterator it = library.find(name);
00065
00066
00067 if (it == library.end())
00068 return false;
00069
00070
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
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
00101 typename FamilyMap::iterator it = library.find(name);
00102
00103
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
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
00121 typename FamilyMap::iterator it = library.find(name);
00122
00123
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
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
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 }