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/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 return derived().get_impl()->get_attributes();
00034 }
00035
00036 template <typename Derived>
00037 impl::attribute_interface*
00038 attribute<Derived>::get_attr (void) const
00039 {
00040 return derived().get_impl()->get_attributes();
00041 }
00042
00043 template <typename Derived>
00044 saga::impl::object*
00045 attribute<Derived>::get_target_object (void) const
00046 {
00047 return boost::get_pointer(derived().get_impl());
00048 }
00049
00050 template <typename Derived>
00051 inline void
00052 attribute<Derived>::init (strmap_type const& scalar_ro,
00053 strmap_type const& scalar_rw, strmap_type const& vector_ro,
00054 strmap_type const& vector_rw)
00055 {
00056 derived().get_impl()->get_attributes()->init(scalar_ro, scalar_rw, vector_ro, vector_rw);
00057 }
00058
00059 template <typename Derived>
00060 inline void
00061 attribute<Derived>::init (bool extensible, bool cache_only)
00062 {
00063 derived().get_impl()->get_attributes()->init(extensible, cache_only);
00064 }
00065
00066 template <typename Derived>
00067 inline void
00068 attribute<Derived>::init_keynames (strvec_type const& keynames)
00069 {
00070 derived().get_impl()->get_attributes()->init_keynames(keynames);
00071 }
00072
00074
00076
00077 struct get_attribute_priv
00078 {
00079 template <typename Derived>
00080 static task
00081 call (Derived& this_, std::string const& key, bool sync)
00082 {
00083 if (!this_.attribute_exists(key))
00084 {
00085
00086 SAGA_THROW_VERBATIM(this_.get_target_object(),
00087 "attribute '" + key + "' does not exist",
00088 saga::DoesNotExist);
00089 }
00090 return this_.get_attr()->get_attribute (key, sync);
00091 }
00092 };
00093
00094 template <typename Derived, typename Tag>
00095 inline task
00096 attribute_priv<Derived, Tag>::get_attributepriv (Derived const& this_,
00097 std::string const& key)
00098 {
00099 return dispatch_priv<Tag>::
00100 template call<get_attribute_priv>(this_, key);
00101 }
00102
00104 struct set_attribute_priv
00105 {
00106 template <typename Derived>
00107 static task
00108 call (Derived& this_,
00109 std::string const& key, std::string const& val, bool sync)
00110 {
00111 if (this_.attribute_exists(key) &&
00112 this_.attribute_is_readonly(key))
00113 {
00114
00115 SAGA_THROW_VERBATIM(this_.get_target_object(),
00116 "attribute '" + key + "' is readonly", saga::PermissionDenied);
00117 }
00118 return this_.get_attr()->set_attribute (key, val, sync);
00119 }
00120 };
00121
00122 template <typename Derived, typename Tag>
00123 inline task
00124 attribute_priv<Derived, Tag>::set_attributepriv (Derived& this_,
00125 std::string const& key, std::string const& val)
00126 {
00127 return dispatch_priv<Tag>::
00128 template call<set_attribute_priv>(this_, key, val);
00129 }
00130
00132 struct get_vector_attribute_priv
00133 {
00134 template <typename Derived>
00135 static task
00136 call (Derived& this_, std::string const& key, bool sync)
00137 {
00138 if (!this_.attribute_exists (key))
00139 {
00140
00141 SAGA_THROW_VERBATIM(this_.get_target_object(),
00142 "attribute '" + key + "' does not exist",
00143 saga::DoesNotExist);
00144 }
00145 return this_.get_attr()->get_vector_attribute (key, sync);
00146 }
00147 };
00148
00149 template <typename Derived, typename Tag>
00150 inline task
00151 attribute_priv<Derived, Tag>::get_vector_attributepriv (Derived const& this_,
00152 std::string const& key)
00153 {
00154 return dispatch_priv<Tag>::
00155 template call<get_vector_attribute_priv>(this_, key);
00156 }
00157
00159 struct set_vector_attribute_priv
00160 {
00161 template <typename Derived>
00162 static task
00163 call (Derived& this_, std::string const& key,
00164 typename attribute<Derived>::strvec_type const& val, bool sync)
00165 {
00166 if (this_.attribute_exists(key) &&
00167 this_.attribute_is_readonly(key))
00168 {
00169
00170 SAGA_THROW_VERBATIM(this_.get_target_object(),
00171 "attribute '" + key + "' is readonly", saga::PermissionDenied);
00172 }
00173 return this_.get_attr()->set_vector_attribute (key, val, sync);
00174 }
00175 };
00176
00177 template <typename Derived, typename Tag>
00178 inline task
00179 attribute_priv<Derived, Tag>::set_vector_attributepriv (Derived& this_,
00180 std::string const& key, strvec_type const& val)
00181 {
00182 return dispatch_priv<Tag>::
00183 template call<set_vector_attribute_priv>(this_, key, val);
00184 }
00185
00187 struct remove_attribute_priv
00188 {
00189 template <typename Derived>
00190 static task
00191 call (Derived& this_, std::string const& key, bool sync)
00192 {
00193 impl::attribute_interface* attr = this_.get_attr();
00194 if (!this_.attribute_exists(key))
00195 {
00196
00197 SAGA_THROW_VERBATIM(this_.get_target_object(),
00198 "attribute '" + key + "' does not exist",
00199 saga::DoesNotExist);
00200 }
00201 if (!this_.get_target_object()->get_attributes()->attributes_extensible() ||
00202 this_.attribute_is_readonly(key))
00203 {
00204
00205 SAGA_THROW_VERBATIM(this_.get_target_object(),
00206 "attribute '" + key + "' is readonly", saga::PermissionDenied);
00207 }
00208 if (!this_.attribute_is_removable(key))
00209 {
00210
00211 SAGA_THROW_VERBATIM(this_.get_target_object(),
00212 "attribute '" + key + "' is readonly", saga::PermissionDenied);
00213 }
00214 return attr->remove_attribute(key, sync);
00215 }
00216 };
00217
00218 template <typename Derived, typename Tag>
00219 inline task
00220 attribute_priv<Derived, Tag>::remove_attributepriv (Derived& this_,
00221 std::string const& key)
00222 {
00223 return dispatch_priv<Tag>::
00224 template call<remove_attribute_priv>(this_, key);
00225 }
00226
00228
00229 struct list_attributes_priv
00230 {
00231 template <typename Derived>
00232 static task
00233 call (Derived& this_, bool sync)
00234 {
00235 return this_.get_attr()->list_attributes(sync);
00236 }
00237 };
00238
00239 template <typename Derived, typename Tag>
00240 inline task
00241 attribute_priv<Derived, Tag>::list_attributespriv (Derived const& this_)
00242 {
00243 return dispatch_priv<Tag>::template call<list_attributes_priv>(this_);
00244 }
00245
00247 struct find_attributes_priv
00248 {
00249 template <typename Derived>
00250 static task
00251 call (Derived& this_, std::string const& pattern, bool sync)
00252 {
00253 return this_.get_attr()->find_attributes(pattern, sync);
00254 }
00255 };
00256
00257 template <typename Derived, typename Tag>
00258 inline task
00259 attribute_priv<Derived, Tag>::find_attributespriv (Derived const& this_,
00260 std::string const& pattern)
00261 {
00262 return dispatch_priv<Tag>::
00263 template call<find_attributes_priv>(this_, pattern);
00264 }
00265
00267 struct attribute_exists_priv
00268 {
00269 template <typename Derived>
00270 static task
00271 call (Derived& this_, std::string const& key, bool sync)
00272 {
00273 return this_.get_attr()->attribute_exists(key, sync);
00274 }
00275 };
00276
00277 template <typename Derived, typename Tag>
00278 inline task
00279 attribute_priv<Derived, Tag>::attribute_existspriv (Derived const& this_,
00280 std::string const& key)
00281 {
00282 return dispatch_priv<Tag>::
00283 template call<attribute_exists_priv>(this_, key);
00284 }
00285
00287 struct attribute_is_readonly_priv
00288 {
00289 template <typename Derived>
00290 static task
00291 call (Derived& this_, std::string const& key, bool sync)
00292 {
00293 if (!this_.attribute_exists(key))
00294 {
00295
00296 SAGA_THROW_VERBATIM(this_.get_target_object(),
00297 "attribute '" + key + "' does not exist",
00298 saga::DoesNotExist);
00299 }
00300 return this_.get_attr()->attribute_is_readonly(key, sync);
00301 }
00302 };
00303
00304 template <typename Derived, typename Tag>
00305 inline task
00306 attribute_priv<Derived, Tag>::attribute_is_readonlypriv (
00307 Derived const& this_, std::string const& key)
00308 {
00309 return dispatch_priv<Tag>::
00310 template call<attribute_is_readonly_priv>(this_, key);
00311 }
00312
00314 struct attribute_is_writable_priv
00315 {
00316 template <typename Derived>
00317 static task
00318 call (Derived& this_, std::string const& key, bool sync)
00319 {
00320 if (!this_.attribute_exists(key))
00321 {
00322
00323 SAGA_THROW_VERBATIM(this_.get_target_object(),
00324 "attribute '" + key + "' does not exist",
00325 saga::DoesNotExist);
00326 }
00327 return this_.get_attr()->attribute_is_writable (key, sync);
00328 }
00329 };
00330
00331 template <typename Derived, typename Tag>
00332 inline task
00333 attribute_priv<Derived, Tag>::attribute_is_writablepriv (
00334 Derived const& this_, std::string const& key)
00335 {
00336 return dispatch_priv<Tag>::
00337 template call<attribute_is_writable_priv>(this_, key);
00338 }
00339
00341 struct attribute_is_vector_priv
00342 {
00343 template <typename Derived>
00344 static task
00345 call (Derived& this_, std::string const& key, bool sync)
00346 {
00347 if (!this_.attribute_exists(key))
00348 {
00349
00350 SAGA_THROW_VERBATIM(this_.get_target_object(),
00351 "attribute '" + key + "' does not exist",
00352 saga::DoesNotExist);
00353 }
00354 return this_.get_attr()->attribute_is_vector(key, sync);
00355 }
00356 };
00357
00358 template <typename Derived, typename Tag>
00359 inline task
00360 attribute_priv<Derived, Tag>::attribute_is_vectorpriv (
00361 Derived const& this_, std::string const& key)
00362 {
00363 return dispatch_priv<Tag>::
00364 template call<attribute_is_vector_priv>(this_, key);
00365 }
00366
00368 struct attribute_is_removable_priv
00369 {
00370 template <typename Derived>
00371 static task
00372 call (Derived& this_, std::string const& key, bool sync)
00373 {
00374 if (!this_.attribute_exists(key))
00375 {
00376
00377 SAGA_THROW_VERBATIM(this_.get_target_object(),
00378 "attribute '" + key + "' does not exist",
00379 saga::DoesNotExist);
00380 }
00381 return this_.get_attr()->attribute_is_extended(key, sync);
00382 }
00383 };
00384
00385 template <typename Derived, typename Tag>
00386 inline task
00387 attribute_priv<Derived, Tag>::attribute_is_removablepriv (
00388 Derived const& this_, std::string const& key)
00389 {
00390 return dispatch_priv<Tag>::
00391 template call<attribute_is_removable_priv>(this_, key);
00392 }
00393
00395
00397 }}
00398
00399 #endif // SAGA_SAGA_DETAIL_ATTRIBUTE_IMPL_HPP
00400