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 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
00084 std::string valueTypeString = getTypeName<ValueType>();
00085
00086
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
00101 std::string valueTypeString = getTypeName<ValueType>();
00102
00103
00104 iterator it = family.find(valueTypeString);
00105
00106
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
00126 std::string valueTypeString = getTypeName<ValueType>();
00127
00128
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
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
00157 std::string valueTypeString = getTypeName<ValueType>();
00158
00159
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
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
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 }