SAGA Adaptor CPI v.1.0
attribute.hpp
Go to the documentation of this file.
00001 //  Copyright (c) 2005-2009 Hartmut Kaiser
00002 //  Copyright (c) 2005-2007 Andre Merzky (andre@merzky.net)
00003 //  Copyright (c) 2007 Ole Weidner (oweidner@cct.lsu.edu)
00004 // 
00005 //  Distributed under the Boost Software License, Version 1.0. (See accompanying 
00006 //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
00007 
00008 #ifndef SAGA_ADAPTORS_ATTRIBUTE_HPP
00009 #define SAGA_ADAPTORS_ATTRIBUTE_HPP
00010 
00011 // include stl
00012 #include <vector>
00013 #include <string>
00014 
00015 // include dependent spec sections
00016 #include <saga/saga/util.hpp>
00017 #include <saga/saga/base.hpp>
00018 #include <saga/saga/attribute.hpp>
00019 #include <saga/saga/adaptors/attribute_cpi.hpp>
00020 
00021 // suppress warnings about dependent classes not being exported from the dll
00022 #if defined(BOOST_MSVC)
00023 #pragma warning(push)
00024 #pragma warning(disable : 4251 4231 4660)
00025 #endif
00026 
00028 namespace saga { namespace adaptors {
00029 
00031   //  this is the same as the saga::adaptor class, except it is possible to set
00032   //  read only attributes
00033   class SAGA_EXPORT attribute 
00034   :   public saga::detail::attribute<attribute>
00035   {
00036     public:
00037       typedef saga::impl::object implementation_base_type;
00038 
00039       // just defined for brevity
00040       typedef std::vector <std::string>              strvec_type;
00041       typedef std::map    <std::string, std::string> strmap_type;
00042 
00043     private:
00044       friend struct saga::detail::attribute<attribute>;  // needs to access get_impl()
00045 
00046       // This members get initialized differently depending on the constructor 
00047       // used:
00048       //  - if this object got constructed from a saga::object, then the impl_ 
00049       //    member gets initialized directly with the corresponding 
00050       //    implementation object (saga::impl::object), and the attr_ member
00051       //    is initialized from the saga::impl::attribute corresponding to the
00052       //    given impl_.
00053       //  - if this object got constructed from a saga::impl::v1_0::cpi*,
00054       //    we assume a cpi instance wants to get access to _its_own_
00055       //    attributes. We initialize the impl_ from the corresponding proxy,
00056       //    and the attr_ from the (default) attribute_cache_cpi implementation 
00057       //    our cpi type has been derived from.
00058       saga::impl::object* impl_;
00059       saga::impl::attribute_interface* attr_;
00060       bool must_delete;
00061 
00062       template <typename Tag> 
00063         saga::task set_attributepriv (std::string const&, std::string const&, Tag);
00064       template <typename Tag> 
00065         saga::task set_vector_attributepriv(std::string const&, strvec_type const&, Tag);
00066       template <typename Tag> 
00067         saga::task remove_attributepriv(std::string const&, Tag);
00068 
00069       void set_attribute_sync(std::string const&, std::string const&);
00070       void set_vector_attribute_sync(std::string const&, strvec_type const&);
00071       void remove_attribute_sync(std::string const&);
00072 
00073     protected:
00074       bool is_impl_valid() const { return impl_ ? true : false; }
00075 
00076     public:
00077       saga::impl::object* get_impl() const { return impl_; }
00078       saga::impl::attribute_interface* get_attr() const { return attr_; }
00079 
00080       // ctor/dtor
00081       explicit attribute (saga::impl::v1_0::attribute_cpi *impl);           // adaptor interface
00082       explicit attribute (saga::impl::v1_0::attribute_cpi const* impl);     // adaptor interface
00083       attribute (saga::object rhs);
00084       attribute (saga::impl::object const* rhs);
00085       ~attribute (void);
00086 
00091       void set_attribute(std::string const& key, std::string const& value) 
00092       {
00093           set_attribute_sync(key, value);
00094       }
00095       SAGA_CALL_PUB_2_DEF_0(set_attribute, std::string, std::string)
00096 
00097       
00101       void set_vector_attribute(std::string key, strvec_type value) 
00102       {
00103           set_vector_attributepriv(key, value, saga::task_base::Sync());
00104       }
00105       SAGA_CALL_PUB_2_DEF_0(set_vector_attribute, std::string, strvec_type)
00106 
00107       
00111       void remove_attribute(std::string key) 
00112       {
00113           remove_attributepriv(key, saga::task_base::Sync());
00114       }
00115       SAGA_CALL_PUB_1_DEF_0(remove_attribute, std::string)
00116   };
00117 
00119 }} // namespace saga::adaptors
00120 
00121 #if defined(BOOST_MSVC)
00122 #pragma warning(pop)
00123 #endif
00124 
00125 #endif // SAGA_ADAPTORS_ATTRIBUTE_HPP
00126 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines