00001
00002
00003
00004
00005
00006 #ifndef SAGA_SAGA_DETAIL_ATTRIBUTE_IMPL_HPP
00007 #define SAGA_SAGA_DETAIL_ATTRIBUTE_IMPL_HPP
00008
00009
00010 #include <vector>
00011 #include <string>
00012
00013 #include <saga/saga/impl_base.hpp>
00014 #include <saga/impl/engine/metric.hpp>
00015
00016
00017 #include <saga/saga/detail/attribute.hpp>
00018 #include <saga/saga/detail/dispatch_priv.hpp>
00019
00020
00021 #if defined(BOOST_MSVC)
00022 #pragma warning(push)
00023 #pragma warning(disable : 4251 4231 4660)
00024 #endif
00025
00027 namespace saga { namespace detail
00028 {
00029 template <typename Derived>
00030 impl::attribute_interface*
00031 attribute<Derived>::get_attr (void)
00032 {
00033 if (!derived().get_impl()) {
00034 SAGA_THROW("The object has not been properly initialized.",
00035 saga::IncorrectState);
00036 }
00037 return derived().get_impl()->get_attributes();
00038 }
00039
00040 template <typename Derived>
00041 impl::attribute_interface*
00042 attribute<Derived>::get_attr (void) const
00043 {
00044 if (!derived().get_impl()) {
00045 SAGA_THROW("The object has not been properly initialized.",
00046 saga::IncorrectState);
00047 }
00048 return derived().get_impl()->get_attributes();
00049 }
00050
00051 template <typename Derived>
00052 template <typename ImplType>
00053 ImplType*
00054 attribute<Derived>::get_target_object (void) const
00055 {
00056 if (!derived().get_impl()) {
00057 SAGA_THROW("The object has not been properly initialized.",
00058 saga::IncorrectState);
00059 }
00060 return boost::get_pointer(derived().get_impl());
00061 }
00062
00063 template <typename Derived>
00064 inline void
00065 attribute<Derived>::init (strmap_type const& scalar_ro,
00066 strmap_type const& scalar_rw, strmap_type const& vector_ro,
00067 strmap_type const& vector_rw)
00068 {
00069 if (!derived().get_impl()) {
00070 SAGA_THROW("The object has not been properly initialized.",
00071 saga::IncorrectState);
00072 }
00073 derived().get_impl()->get_attributes()->init(scalar_ro, scalar_rw, vector_ro, vector_rw);
00074 }
00075
00076 template <typename Derived>
00077 inline void
00078 attribute<Derived>::init (bool extensible, bool cache_only)
00079 {
00080 if (!derived().get_impl()) {
00081 SAGA_THROW("The object has not been properly initialized.",
00082 saga::IncorrectState);
00083 }
00084 derived().get_impl()->get_attributes()->init(extensible, cache_only);
00085 }
00086
00087 template <typename Derived>
00088 inline void
00089 attribute<Derived>::init_keynames (strvec_type const& keynames)
00090 {
00091 if (!derived().get_impl()) {
00092 SAGA_THROW("The object has not been properly initialized.",
00093 saga::IncorrectState);
00094 }
00095 derived().get_impl()->get_attributes()->init_keynames(keynames);
00096 }
00097
00099
00101
00102 struct get_attribute_priv
00103 {
00104 template <typename Derived>
00105 static task
00106 call (Derived& this_, std::string const& key, bool sync)
00107 {
00108 if (!this_.attribute_exists(key))
00109 {
00110
00111 typedef typename Derived::implementation_base_type base_type;
00112 SAGA_THROW_VERBATIM(
00113 this_.template get_target_object<base_type>(),
00114 "attribute '" + key + "' does not exist",
00115 saga::DoesNotExist);
00116 }
00117 return this_.get_attr()->get_attribute (key, sync);
00118 }
00119 };
00120
00121 template <typename Derived, typename Tag>
00122 inline task
00123 attribute_priv<Derived, Tag>::get_attributepriv (Derived const& this_,
00124 std::string const& key)
00125 {
00126 return dispatch_priv<Tag>::
00127 template call<get_attribute_priv>(this_, key);
00128 }
00129
00131 struct set_attribute_priv
00132 {
00133 template <typename Derived>
00134 static task
00135 call (Derived& this_,
00136 std::string const& key, std::string const& val, bool sync)
00137 {
00138 if (this_.attribute_exists(key) &&
00139 this_.attribute_is_readonly(key))
00140 {
00141
00142 typedef typename Derived::implementation_base_type base_type;
00143 SAGA_THROW_VERBATIM(
00144 this_.template get_target_object<base_type>(),
00145 "attribute '" + key + "' is readonly", saga::PermissionDenied);
00146 }
00147 return this_.get_attr()->set_attribute (key, val, sync);
00148 }
00149 };
00150
00151 template <typename Derived, typename Tag>
00152 inline task
00153 attribute_priv<Derived, Tag>::set_attributepriv (Derived& this_,
00154 std::string const& key, std::string const& val)
00155 {
00156 return dispatch_priv<Tag>::
00157 template call<set_attribute_priv>(this_, key, val);
00158 }
00159
00161 struct get_vector_attribute_priv
00162 {
00163 template <typename Derived>
00164 static task
00165 call (Derived& this_, std::string const& key, bool sync)
00166 {
00167 if (!this_.attribute_exists (key))
00168 {
00169
00170 typedef typename Derived::implementation_base_type base_type;
00171 SAGA_THROW_VERBATIM(
00172 this_.template get_target_object<base_type>(),
00173 "attribute '" + key + "' does not exist",
00174 saga::DoesNotExist);
00175 }
00176 return this_.get_attr()->get_vector_attribute (key, sync);
00177 }
00178 };
00179
00180 template <typename Derived, typename Tag>
00181 inline task
00182 attribute_priv<Derived, Tag>::get_vector_attributepriv (Derived const& this_,
00183 std::string const& key)
00184 {
00185 return dispatch_priv<Tag>::
00186 template call<get_vector_attribute_priv>(this_, key);
00187 }
00188
00190 struct set_vector_attribute_priv
00191 {
00192 template <typename Derived>
00193 static task
00194 call (Derived& this_, std::string const& key,
00195 typename attribute<Derived>::strvec_type const& val, bool sync)
00196 {
00197 if (this_.attribute_exists(key) &&
00198 this_.attribute_is_readonly(key))
00199 {
00200
00201 typedef typename Derived::implementation_base_type base_type;
00202 SAGA_THROW_VERBATIM(
00203 this_.template get_target_object<base_type>(),
00204 "attribute '" + key + "' is readonly", saga::PermissionDenied);
00205 }
00206 return this_.get_attr()->set_vector_attribute (key, val, sync);
00207 }
00208 };
00209
00210 template <typename Derived, typename Tag>
00211 inline task
00212 attribute_priv<Derived, Tag>::set_vector_attributepriv (Derived& this_,
00213 std::string const& key, strvec_type const& val)
00214 {
00215 return dispatch_priv<Tag>::
00216 template call<set_vector_attribute_priv>(this_, key, val);
00217 }
00218
00220 struct remove_attribute_priv
00221 {
00222 template <typename Derived>
00223 static task
00224 call (Derived& this_, std::string const& key, bool sync)
00225 {
00226 typedef typename Derived::implementation_base_type base_type;
00227
00228 impl::attribute_interface* attr = this_.get_attr();
00229 if (!this_.attribute_exists(key))
00230 {
00231
00232 SAGA_THROW_VERBATIM(
00233 this_.template get_target_object<base_type>(),
00234 "attribute '" + key + "' does not exist",
00235 saga::DoesNotExist);
00236 }
00237 if (!this_.template get_target_object<base_type>()->get_attributes()->attributes_extensible() ||
00238 this_.attribute_is_readonly(key))
00239 {
00240
00241 SAGA_THROW_VERBATIM(
00242 this_.template get_target_object<base_type>(),
00243 "attribute '" + key + "' is readonly", saga::PermissionDenied);
00244 }
00245 if (!this_.attribute_is_removable(key))
00246 {
00247
00248 SAGA_THROW_VERBATIM(
00249 this_.template get_target_object<base_type>(),
00250 "attribute '" + key + "' is readonly", saga::PermissionDenied);
00251 }
00252 return attr->remove_attribute(key, sync);
00253 }
00254 };
00255
00256 template <typename Derived, typename Tag>
00257 inline task
00258 attribute_priv<Derived, Tag>::remove_attributepriv (Derived& this_,
00259 std::string const& key)
00260 {
00261 return dispatch_priv<Tag>::
00262 template call<remove_attribute_priv>(this_, key);
00263 }
00264
00266
00267 struct list_attributes_priv
00268 {
00269 template <typename Derived>
00270 static task
00271 call (Derived& this_, bool sync)
00272 {
00273 return this_.get_attr()->list_attributes(sync);
00274 }
00275 };
00276
00277 template <typename Derived, typename Tag>
00278 inline task
00279 attribute_priv<Derived, Tag>::list_attributespriv (Derived const& this_)
00280 {
00281 return dispatch_priv<Tag>::template call<list_attributes_priv>(this_);
00282 }
00283
00285 struct find_attributes_priv
00286 {
00287 template <typename Derived>
00288 static task
00289 call (Derived& this_, std::string const& pattern, bool sync)
00290 {
00291 return this_.get_attr()->find_attributes(pattern, sync);
00292 }
00293 };
00294
00295 template <typename Derived, typename Tag>
00296 inline task
00297 attribute_priv<Derived, Tag>::find_attributespriv (Derived const& this_,
00298 std::string const& pattern)
00299 {
00300 return dispatch_priv<Tag>::
00301 template call<find_attributes_priv>(this_, pattern);
00302 }
00303
00305 struct attribute_exists_priv
00306 {
00307 template <typename Derived>
00308 static task
00309 call (Derived& this_, std::string const& key, bool sync)
00310 {
00311 return this_.get_attr()->attribute_exists(key, sync);
00312 }
00313 };
00314
00315 template <typename Derived, typename Tag>
00316 inline task
00317 attribute_priv<Derived, Tag>::attribute_existspriv (Derived const& this_,
00318 std::string const& key)
00319 {
00320 return dispatch_priv<Tag>::
00321 template call<attribute_exists_priv>(this_, key);
00322 }
00323
00325 struct attribute_is_readonly_priv
00326 {
00327 template <typename Derived>
00328 static task
00329 call (Derived& this_, std::string const& key, bool sync)
00330 {
00331 if (!this_.attribute_exists(key))
00332 {
00333
00334 typedef typename Derived::implementation_base_type base_type;
00335 SAGA_THROW_VERBATIM(
00336 this_.template get_target_object<base_type>(),
00337 "attribute '" + key + "' does not exist",
00338 saga::DoesNotExist);
00339 }
00340 return this_.get_attr()->attribute_is_readonly(key, sync);
00341 }
00342 };
00343
00344 template <typename Derived, typename Tag>
00345 inline task
00346 attribute_priv<Derived, Tag>::attribute_is_readonlypriv (
00347 Derived const& this_, std::string const& key)
00348 {
00349 return dispatch_priv<Tag>::
00350 template call<attribute_is_readonly_priv>(this_, key);
00351 }
00352
00354 struct attribute_is_writable_priv
00355 {
00356 template <typename Derived>
00357 static task
00358 call (Derived& this_, std::string const& key, bool sync)
00359 {
00360 if (!this_.attribute_exists(key))
00361 {
00362
00363 typedef typename Derived::implementation_base_type base_type;
00364 SAGA_THROW_VERBATIM(
00365 this_.template get_target_object<base_type>(),
00366 "attribute '" + key + "' does not exist",
00367 saga::DoesNotExist);
00368 }
00369 return this_.get_attr()->attribute_is_writable (key, sync);
00370 }
00371 };
00372
00373 template <typename Derived, typename Tag>
00374 inline task
00375 attribute_priv<Derived, Tag>::attribute_is_writablepriv (
00376 Derived const& this_, std::string const& key)
00377 {
00378 return dispatch_priv<Tag>::
00379 template call<attribute_is_writable_priv>(this_, key);
00380 }
00381
00383 struct attribute_is_vector_priv
00384 {
00385 template <typename Derived>
00386 static task
00387 call (Derived& this_, std::string const& key, bool sync)
00388 {
00389 if (!this_.attribute_exists(key))
00390 {
00391
00392 typedef typename Derived::implementation_base_type base_type;
00393 SAGA_THROW_VERBATIM(
00394 this_.template get_target_object<base_type>(),
00395 "attribute '" + key + "' does not exist",
00396 saga::DoesNotExist);
00397 }
00398 return this_.get_attr()->attribute_is_vector(key, sync);
00399 }
00400 };
00401
00402 template <typename Derived, typename Tag>
00403 inline task
00404 attribute_priv<Derived, Tag>::attribute_is_vectorpriv (
00405 Derived const& this_, std::string const& key)
00406 {
00407 return dispatch_priv<Tag>::
00408 template call<attribute_is_vector_priv>(this_, key);
00409 }
00410
00412 struct attribute_is_removable_priv
00413 {
00414 template <typename Derived>
00415 static task
00416 call (Derived& this_, std::string const& key, bool sync)
00417 {
00418 if (!this_.attribute_exists(key))
00419 {
00420
00421 typedef typename Derived::implementation_base_type base_type;
00422 SAGA_THROW_VERBATIM(
00423 this_.template get_target_object<base_type>(),
00424 "attribute '" + key + "' does not exist",
00425 saga::DoesNotExist);
00426 }
00427 return this_.get_attr()->attribute_is_extended(key, sync);
00428 }
00429 };
00430
00431 template <typename Derived, typename Tag>
00432 inline task
00433 attribute_priv<Derived, Tag>::attribute_is_removablepriv (
00434 Derived const& this_, std::string const& key)
00435 {
00436 return dispatch_priv<Tag>::
00437 template call<attribute_is_removable_priv>(this_, key);
00438 }
00439
00441
00443 }}
00444
00445 #endif // SAGA_SAGA_DETAIL_ATTRIBUTE_IMPL_HPP
00446