SAGA C++ API 1.6
attribute_impl.hpp
Go to the documentation of this file.
00001 //  Copyright (c) 2005-2009 Hartmut Kaiser
00002 // 
00003 //  Distributed under the Boost Software License, Version 1.0. (See accompanying 
00004 //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
00005 
00006 #ifndef SAGA_SAGA_DETAIL_ATTRIBUTE_IMPL_HPP
00007 #define SAGA_SAGA_DETAIL_ATTRIBUTE_IMPL_HPP
00008 
00009 // include stl
00010 #include <vector>
00011 #include <string>
00012 
00013 #include <saga/saga/impl_base.hpp>
00014 #include <saga/impl/engine/metric.hpp>
00015 
00016 // include dependent spec sections
00017 #include <saga/saga/detail/attribute.hpp>
00018 #include <saga/saga/detail/dispatch_priv.hpp>
00019 
00020 // suppress warnings about dependent classes not being exported from the dll
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().is_impl_valid()) {
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().is_impl_valid()) {
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().is_impl_valid()) {
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 (
00066         char const* const* scalar_ro, char const* const* scalar_rw,
00067         char const* const* vector_ro, char const* const* vector_rw)
00068     {
00069         if (!derived().is_impl_valid()) {
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 (strmap_type const& scalar_ro,
00079         strmap_type const& scalar_rw, strmap_type const& vector_ro,
00080         strmap_type const& vector_rw)
00081     {
00082         if (!derived().is_impl_valid()) {
00083             SAGA_THROW("The object has not been properly initialized.",
00084                 saga::IncorrectState);
00085         }
00086         derived().get_impl()->get_attributes()->init(scalar_ro, scalar_rw, vector_ro, vector_rw);
00087     }
00088 
00089     template <typename Derived>
00090     inline void 
00091     attribute<Derived>::init (bool extensible, bool cache_only)
00092     {
00093         if (!derived().is_impl_valid()) {
00094             SAGA_THROW("The object has not been properly initialized.",
00095                 saga::IncorrectState);
00096         }
00097         derived().get_impl()->get_attributes()->init(extensible, cache_only);
00098     }
00099 
00100     template <typename Derived>
00101     inline void 
00102     attribute<Derived>::init_keynames(char const* const* keynames)
00103     {
00104         if (!derived().is_impl_valid()) {
00105             SAGA_THROW("The object has not been properly initialized.",
00106                 saga::IncorrectState);
00107         }
00108         derived().get_impl()->get_attributes()->init_keynames(keynames);
00109     }
00110 
00111     template <typename Derived>
00112     inline void 
00113     attribute<Derived>::init_keynames (strvec_type const& keynames)
00114     {
00115         if (!derived().is_impl_valid()) {
00116             SAGA_THROW("The object has not been properly initialized.",
00117                 saga::IncorrectState);
00118         }
00119         derived().get_impl()->get_attributes()->init_keynames(keynames);
00120     }
00121 
00123 
00125     /* setters/getters */
00126     struct get_attribute_priv
00127     {
00128         template <typename Derived>
00129         static task
00130         call (Derived& this_, std::string const& key, bool sync) 
00131         {
00132             impl::attribute_interface* attr = this_.get_attr();
00133             if (!attr->attribute_exists_sync(key))
00134             {
00135               // DoesNotExist
00136               typedef typename Derived::implementation_base_type base_type;
00137               SAGA_THROW_VERBATIM(
00138                   this_.template get_target_object<base_type>(), 
00139                   "attribute '" + key + "' does not exist", 
00140                   saga::DoesNotExist);
00141             }
00142             return attr->get_attribute (key, sync);
00143         }
00144     };
00145 
00146     template <typename Derived, typename Tag>
00147     inline task
00148     attribute_priv<Derived, Tag>::get_attributepriv (
00149         Derived const& this_, std::string const& key) 
00150     {
00151         return dispatch_priv<Tag>::
00152             template call<get_attribute_priv>(this_, key);
00153     }
00154 
00156     template <typename Derived>
00157     inline std::string
00158     attribute_sync<Derived>::get_attribute(
00159         Derived const& this_, std::string const& key) 
00160     {
00161         impl::attribute_interface* attr = this_.get_attr();
00162         if (!attr->attribute_exists_sync(key))
00163         {
00164             // DoesNotExist
00165             typedef typename Derived::implementation_base_type base_type;
00166             SAGA_THROW_VERBATIM(
00167                 this_.template get_target_object<base_type>(), 
00168                 "attribute '" + key + "' does not exist", 
00169                 saga::DoesNotExist);
00170         }
00171         return attr->get_attribute_sync(key);
00172     }
00173 
00175     struct set_attribute_priv
00176     {
00177         template <typename Derived>
00178         static task
00179         call (Derived& this_, 
00180             std::string const& key, std::string const& val, bool sync)
00181         {
00182             impl::attribute_interface* attr = this_.get_attr();
00183             if (attr->attribute_exists_sync(key) && 
00184                 attr->attribute_is_readonly_sync(key))
00185             {
00186                 // ReadOnly
00187                 typedef typename Derived::implementation_base_type base_type;
00188                 SAGA_THROW_VERBATIM(
00189                     this_.template get_target_object<base_type>(), 
00190                     "attribute '" + key + "' is readonly", saga::PermissionDenied);
00191             }
00192             return attr->set_attribute (key, val, sync);
00193         }
00194     };
00195 
00196     template <typename Derived, typename Tag>
00197     inline task
00198     attribute_priv<Derived, Tag>::set_attributepriv (Derived& this_,
00199         std::string const& key, std::string const& val) 
00200     {
00201         return dispatch_priv<Tag>::
00202             template call<set_attribute_priv>(this_, key, val);
00203     }
00204 
00206     template <typename Derived>
00207     inline void
00208     attribute_sync<Derived>::set_attribute(
00209         Derived& this_, std::string const& key, std::string const& val) 
00210     {
00211         impl::attribute_interface* attr = this_.get_attr();
00212         if (attr->attribute_exists_sync(key) && 
00213             attr->attribute_is_readonly_sync(key))
00214         {
00215             // ReadOnly
00216             typedef typename Derived::implementation_base_type base_type;
00217             SAGA_THROW_VERBATIM(
00218                 this_.template get_target_object<base_type>(), 
00219                 "attribute '" + key + "' is readonly", saga::PermissionDenied);
00220         }
00221         attr->set_attribute_sync(key, val);
00222     }
00223 
00225     struct get_vector_attribute_priv
00226     {
00227         template <typename Derived>
00228         static task
00229         call (Derived& this_, std::string const& key, bool sync) 
00230         {
00231             impl::attribute_interface* attr = this_.get_attr();
00232             if (!attr->attribute_exists_sync(key))
00233             {
00234                 // DoesNotExist
00235                 typedef typename Derived::implementation_base_type base_type;
00236                 SAGA_THROW_VERBATIM(
00237                     this_.template get_target_object<base_type>(),
00238                     "attribute '" + key + "' does not exist", 
00239                     saga::DoesNotExist);
00240             }
00241             return attr->get_vector_attribute (key, sync);
00242         }
00243     };
00244 
00245     template <typename Derived, typename Tag>
00246     inline task
00247     attribute_priv<Derived, Tag>::get_vector_attributepriv (
00248         Derived const& this_, std::string const& key) 
00249     {
00250         return dispatch_priv<Tag>::
00251             template call<get_vector_attribute_priv>(this_, key);
00252     }
00253 
00255     template <typename Derived>
00256     inline void
00257     attribute_sync<Derived>::get_vector_attribute(
00258         Derived const& this_, std::string const& key, strvec_type& retval) 
00259     {
00260         impl::attribute_interface* attr = this_.get_attr();
00261         if (!attr->attribute_exists_sync(key))
00262         {
00263             // DoesNotExist
00264             typedef typename Derived::implementation_base_type base_type;
00265             SAGA_THROW_VERBATIM(
00266                 this_.template get_target_object<base_type>(),
00267                 "attribute '" + key + "' does not exist", 
00268                 saga::DoesNotExist);
00269         }
00270         attr->get_vector_attribute_sync(key, retval);
00271     }
00272 
00274     struct set_vector_attribute_priv
00275     {
00276         template <typename Derived>
00277         static task
00278         call (Derived& this_, std::string const& key, 
00279             typename attribute<Derived>::strvec_type const& val, bool sync)
00280         { 
00281             impl::attribute_interface* attr = this_.get_attr();
00282             if (attr->attribute_exists_sync(key) && 
00283                 attr->attribute_is_readonly_sync(key))
00284             {
00285                 // ReadOnly
00286                 typedef typename Derived::implementation_base_type base_type;
00287                 SAGA_THROW_VERBATIM(
00288                     this_.template get_target_object<base_type>(),
00289                     "attribute '" + key + "' is readonly", saga::PermissionDenied);
00290             }
00291             return attr->set_vector_attribute (key, val, sync);
00292         }
00293      };
00294 
00295     template <typename Derived, typename Tag>
00296     inline task
00297     attribute_priv<Derived, Tag>::set_vector_attributepriv (
00298         Derived& this_, std::string const& key, strvec_type const& val) 
00299     {
00300         return dispatch_priv<Tag>::
00301             template call<set_vector_attribute_priv>(this_, key, val);
00302     }
00303 
00305     template <typename Derived>
00306     inline void
00307     attribute_sync<Derived>::set_vector_attribute(
00308         Derived& this_, std::string const& key, strvec_type const& val) 
00309     {
00310         impl::attribute_interface* attr = this_.get_attr();
00311         if (attr->attribute_exists_sync(key) && 
00312             attr->attribute_is_readonly_sync(key))
00313         {
00314             // ReadOnly
00315             typedef typename Derived::implementation_base_type base_type;
00316             SAGA_THROW_VERBATIM(
00317                 this_.template get_target_object<base_type>(),
00318                 "attribute '" + key + "' is readonly", saga::PermissionDenied);
00319         }
00320         attr->set_vector_attribute_sync(key, val);
00321     }
00322 
00324     struct remove_attribute_priv
00325     {
00326         template <typename Derived>
00327         static task
00328         call (Derived& this_, std::string const& key, bool sync)
00329         {
00330             typedef typename Derived::implementation_base_type base_type;
00331 
00332             impl::attribute_interface* attr = this_.get_attr();
00333             if (!attr->attribute_exists_sync(key))
00334             {
00335                 // DoesNotExist
00336                 SAGA_THROW_VERBATIM(
00337                     this_.template get_target_object<base_type>(), 
00338                     "attribute '" + key + "' does not exist", 
00339                     saga::DoesNotExist);
00340             }
00341             if (!this_.template get_target_object<base_type>()->get_attributes()->attributes_extensible() || 
00342                 attr->attribute_is_readonly_sync(key))
00343             {
00344                 // ReadOnly
00345                 SAGA_THROW_VERBATIM(
00346                     this_.template get_target_object<base_type>(),
00347                     "attribute '" + key + "' is readonly", saga::PermissionDenied);
00348             }
00349             if (!attr->attribute_is_extended_sync(key))    // !is_removable
00350             {
00351                 // ReadOnly
00352                 SAGA_THROW_VERBATIM(
00353                     this_.template get_target_object<base_type>(),
00354                     "attribute '" + key + "' is readonly", saga::PermissionDenied);
00355             }
00356             return attr->remove_attribute(key, sync);
00357         }
00358     };
00359 
00360     template <typename Derived, typename Tag>
00361     inline task
00362     attribute_priv<Derived, Tag>::remove_attributepriv (Derived& this_,
00363         std::string const& key) 
00364     {
00365         return dispatch_priv<Tag>::
00366             template call<remove_attribute_priv>(this_, key);
00367     }
00368 
00370     template <typename Derived>
00371     inline void
00372     attribute_sync<Derived>::remove_attribute(
00373         Derived& this_, std::string const& key) 
00374     {
00375         typedef typename Derived::implementation_base_type base_type;
00376 
00377         impl::attribute_interface* attr = this_.get_attr();
00378         if (!attr->attribute_exists_sync(key))
00379         {
00380             // DoesNotExist
00381             SAGA_THROW_VERBATIM(
00382                 this_.template get_target_object<base_type>(), 
00383                 "attribute '" + key + "' does not exist", 
00384                 saga::DoesNotExist);
00385         }
00386         if (!this_.template get_target_object<base_type>()->get_attributes()->attributes_extensible() || 
00387             attr->attribute_is_readonly_sync(key))
00388         {
00389             // ReadOnly
00390             SAGA_THROW_VERBATIM(
00391                 this_.template get_target_object<base_type>(),
00392                 "attribute '" + key + "' is readonly", saga::PermissionDenied);
00393         }
00394         if (!attr->attribute_is_extended_sync(key))    // !is_removable
00395         {
00396             // ReadOnly
00397             SAGA_THROW_VERBATIM(
00398                 this_.template get_target_object<base_type>(),
00399                 "attribute '" + key + "' is readonly", saga::PermissionDenied);
00400         }
00401         attr->remove_attribute_sync(key);
00402     }
00403 
00405     /* inspection */
00406     struct list_attributes_priv
00407     {
00408         template <typename Derived>
00409         static task
00410         call (Derived& this_, bool sync) 
00411         {
00412             return this_.get_attr()->list_attributes(sync);
00413         }
00414     };
00415 
00416     template <typename Derived, typename Tag>
00417     inline task
00418     attribute_priv<Derived, Tag>::list_attributespriv (Derived const& this_) 
00419     {
00420         return dispatch_priv<Tag>::template call<list_attributes_priv>(this_);
00421     }
00422 
00424     template <typename Derived>
00425     inline void
00426     attribute_sync<Derived>::list_attributes(
00427         Derived const& this_, strvec_type& retval) 
00428     {
00429         this_.get_attr()->list_attributes_sync(retval);
00430     }
00431 
00433     struct find_attributes_priv
00434     {
00435         template <typename Derived>
00436         static task
00437         call (Derived& this_, std::string const& pattern, bool sync) 
00438         {
00439             return this_.get_attr()->find_attributes(pattern, sync);
00440         }
00441     };
00442 
00443     template <typename Derived, typename Tag>
00444     inline task
00445     attribute_priv<Derived, Tag>::find_attributespriv (
00446         Derived const& this_, std::string const& pattern) 
00447     {
00448         return dispatch_priv<Tag>::
00449             template call<find_attributes_priv>(this_, pattern);
00450     }
00451 
00453     template <typename Derived>
00454     inline void
00455     attribute_sync<Derived>::find_attributes(
00456         Derived const& this_, std::string const& pattern, strvec_type& retval) 
00457     {
00458         this_.get_attr()->find_attributes_sync(pattern, retval);
00459     }
00460 
00462     struct attribute_exists_priv
00463     {
00464         template <typename Derived>
00465         static task
00466         call (Derived& this_, std::string const& key, bool sync) 
00467         {
00468             return this_.get_attr()->attribute_exists(key, sync);
00469         }
00470     };
00471 
00472     template <typename Derived, typename Tag>
00473     inline task
00474     attribute_priv<Derived, Tag>::attribute_existspriv (
00475         Derived const& this_, std::string const& key) 
00476     {
00477         return dispatch_priv<Tag>::
00478             template call<attribute_exists_priv>(this_, key);
00479     }
00480 
00482     template <typename Derived>
00483     inline bool
00484     attribute_sync<Derived>::attribute_exists(
00485         Derived const& this_, std::string const& key) 
00486     {
00487         return this_.get_attr()->attribute_exists_sync(key);
00488     }
00489 
00491     struct attribute_is_readonly_priv
00492     {
00493         template <typename Derived>
00494         static task
00495         call (Derived& this_, std::string const& key, bool sync) 
00496         {
00497             impl::attribute_interface* attr = this_.get_attr();
00498             if (!attr->attribute_exists_sync(key))
00499             {
00500                 // DoesNotExist
00501                 typedef typename Derived::implementation_base_type base_type;
00502                 SAGA_THROW_VERBATIM(
00503                     this_.template get_target_object<base_type>(),
00504                     "attribute '" + key + "' does not exist", 
00505                     saga::DoesNotExist);
00506             }
00507             return attr->attribute_is_readonly(key, sync);
00508         }
00509     };
00510 
00511     template <typename Derived, typename Tag>
00512     inline task
00513     attribute_priv<Derived, Tag>::attribute_is_readonlypriv (
00514         Derived const& this_, std::string const& key) 
00515     {
00516         return dispatch_priv<Tag>::
00517             template call<attribute_is_readonly_priv>(this_, key);
00518     }
00519 
00521     template <typename Derived>
00522     inline bool
00523     attribute_sync<Derived>::attribute_is_readonly(
00524         Derived const& this_, std::string const& key) 
00525     {
00526         impl::attribute_interface* attr = this_.get_attr();
00527         if (!attr->attribute_exists_sync(key))
00528         {
00529             // DoesNotExist
00530             typedef typename Derived::implementation_base_type base_type;
00531             SAGA_THROW_VERBATIM(
00532                 this_.template get_target_object<base_type>(),
00533                 "attribute '" + key + "' does not exist", 
00534                 saga::DoesNotExist);
00535         }
00536         return attr->attribute_is_readonly_sync(key);
00537     }
00538 
00540     struct attribute_is_writable_priv
00541     {
00542         template <typename Derived>
00543         static task
00544         call (Derived& this_, std::string const& key, bool sync) 
00545         {
00546             impl::attribute_interface* attr = this_.get_attr();
00547             if (!attr->attribute_exists_sync(key))
00548             {
00549                 // DoesNotExist
00550                 typedef typename Derived::implementation_base_type base_type;
00551                 SAGA_THROW_VERBATIM(
00552                     this_.template get_target_object<base_type>(),
00553                     "attribute '" + key + "' does not exist", 
00554                     saga::DoesNotExist);
00555             }
00556             return attr->attribute_is_writable (key, sync);
00557         }
00558     };
00559 
00560     template <typename Derived, typename Tag>
00561     inline task
00562     attribute_priv<Derived, Tag>::attribute_is_writablepriv (
00563         Derived const& this_, std::string const& key) 
00564     {
00565         return dispatch_priv<Tag>::
00566             template call<attribute_is_writable_priv>(this_, key);
00567     }
00568 
00570     template <typename Derived>
00571     inline bool
00572     attribute_sync<Derived>::attribute_is_writable(
00573         Derived const& this_, std::string const& key) 
00574     {
00575         impl::attribute_interface* attr = this_.get_attr();
00576         if (!attr->attribute_exists_sync(key))
00577         {
00578             // DoesNotExist
00579             typedef typename Derived::implementation_base_type base_type;
00580             SAGA_THROW_VERBATIM(
00581                 this_.template get_target_object<base_type>(),
00582                 "attribute '" + key + "' does not exist", 
00583                 saga::DoesNotExist);
00584         }
00585         return attr->attribute_is_writable_sync(key);
00586     }
00587 
00589     struct attribute_is_vector_priv
00590     {
00591         template <typename Derived>
00592         static task
00593         call (Derived& this_, std::string const& key, bool sync) 
00594         {
00595             impl::attribute_interface* attr = this_.get_attr();
00596             if (!attr->attribute_exists_sync(key))
00597             {
00598                 // DoesNotExist
00599                 typedef typename Derived::implementation_base_type base_type;
00600                 SAGA_THROW_VERBATIM(
00601                     this_.template get_target_object<base_type>(),
00602                     "attribute '" + key + "' does not exist", 
00603                     saga::DoesNotExist);
00604             }
00605             return attr->attribute_is_vector(key, sync);
00606         }
00607     };
00608 
00609     template <typename Derived, typename Tag>
00610     inline task
00611     attribute_priv<Derived, Tag>::attribute_is_vectorpriv (
00612         Derived const& this_, std::string const& key) 
00613     {
00614         return dispatch_priv<Tag>::
00615             template call<attribute_is_vector_priv>(this_, key);
00616     }
00617 
00619     template <typename Derived>
00620     inline bool
00621     attribute_sync<Derived>::attribute_is_vector(
00622         Derived const& this_, std::string const& key) 
00623     {
00624         impl::attribute_interface* attr = this_.get_attr();
00625         if (!attr->attribute_exists_sync(key))
00626         {
00627             // DoesNotExist
00628             typedef typename Derived::implementation_base_type base_type;
00629             SAGA_THROW_VERBATIM(
00630                 this_.template get_target_object<base_type>(),
00631                 "attribute '" + key + "' does not exist", 
00632                 saga::DoesNotExist);
00633         }
00634         return attr->attribute_is_vector_sync(key);
00635     }
00636 
00638     struct attribute_is_removable_priv
00639     {
00640         template <typename Derived>
00641         static task
00642         call (Derived& this_, std::string const& key, bool sync) 
00643         {
00644             impl::attribute_interface* attr = this_.get_attr();
00645             if (!attr->attribute_exists_sync(key))
00646             {
00647                 // DoesNotExist
00648                 typedef typename Derived::implementation_base_type base_type;
00649                 SAGA_THROW_VERBATIM(
00650                     this_.template get_target_object<base_type>(),
00651                     "attribute '" + key + "' does not exist", 
00652                     saga::DoesNotExist);
00653             }
00654             return attr->attribute_is_extended(key, sync);
00655         }
00656     };
00657 
00658     template <typename Derived, typename Tag>
00659     inline task
00660     attribute_priv<Derived, Tag>::attribute_is_removablepriv (
00661         Derived const& this_, std::string const& key) 
00662     {
00663         return dispatch_priv<Tag>::
00664             template call<attribute_is_removable_priv>(this_, key);
00665     }
00666 
00668     template <typename Derived>
00669     inline bool
00670     attribute_sync<Derived>::attribute_is_removable(
00671         Derived const& this_, std::string const& key) 
00672     {
00673         impl::attribute_interface* attr = this_.get_attr();
00674         if (!attr->attribute_exists_sync(key))
00675         {
00676             // DoesNotExist
00677             typedef typename Derived::implementation_base_type base_type;
00678             SAGA_THROW_VERBATIM(
00679                 this_.template get_target_object<base_type>(),
00680                 "attribute '" + key + "' does not exist", 
00681                 saga::DoesNotExist);
00682         }
00683         return attr->attribute_is_extended_sync(key);
00684     }
00685 
00687 
00689 }}   // namespace saga::detail
00690 
00691 #endif // SAGA_SAGA_DETAIL_ATTRIBUTE_IMPL_HPP
00692 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines