SAGA Adaptor CPI v.1.0
attribute_cache_cpi.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_ADAPTORS_ATTRIBUTE_CACHE_HPP
00007 #define SAGA_ADAPTORS_ATTRIBUTE_CACHE_HPP
00008 
00009 #include <vector>
00010 #include <string>
00011 
00012 #include <saga/saga/adaptors/task_declaration.hpp>
00013 #include <saga/saga/adaptors/attribute_cpi.hpp>
00014 
00015 #include <saga/impl/engine/proxy.hpp>
00016 #include <saga/impl/engine/cpi_info.hpp>
00017 #include <saga/impl/engine/attribute_cache.hpp>
00018 #include <saga/impl/engine/register_members.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 adaptors {
00028 
00029     //  This class provides a default implementation of the attribute_cpi 
00030     //  interface by redirecting the calls into the SAGA engine, utilizing the
00031     //  internal attribute cache.
00032     template <typename Derived, typename Base>
00033     class attribute_cache_cpi : public Base
00034     {
00035     private:
00036         typedef saga::impl::proxy proxy;
00037         typedef saga::impl::v1_0::cpi cpi;
00038         typedef saga::impl::v1_0::cpi_info cpi_info;
00039         typedef saga::impl::v1_0::preference_type preference_type;
00040         typedef std::vector<std::string> strvec_type;
00041 
00042         saga::impl::attribute_cache *get_cache() const
00043             { return this->get_proxy()->get_attributes()->get_cache(); }
00044         
00045     public:
00046         attribute_cache_cpi(proxy* p, cpi_info const& info, 
00047                 TR1::shared_ptr<saga::adaptor> adaptor, cpi::flags flags)
00048         :   Base(p, info, adaptor, flags)
00049         {}
00050         
00051         virtual ~attribute_cache_cpi (void) 
00052         {}
00053 
00054         // synchronous attribute_cpi interface redirect all calls to the
00055         // default cache implementation
00056         void sync_get_attribute(std::string& ret, std::string key)
00057             { ret = get_cache()->get_attribute(key); }
00058         void sync_set_attribute(saga::impl::void_t&, std::string key, std::string val)
00059             { get_cache()->set_attribute(key, val); }
00060         void sync_get_vector_attribute(strvec_type& ret, std::string key)
00061             { get_cache()->get_vector_attribute(key, ret); }
00062         void sync_set_vector_attribute(saga::impl::void_t&, std::string key, strvec_type val)
00063             { get_cache()->set_vector_attribute(key, val); }
00064         void sync_remove_attribute(saga::impl::void_t&, std::string key)
00065             { get_cache()->remove_attribute(key); }
00066         void sync_list_attributes(strvec_type& ret)
00067             { get_cache()->list_attributes(ret); }
00068         void sync_find_attributes(strvec_type& ret, std::string pattern)
00069             { get_cache()->find_attributes(pattern, ret); }
00070         void sync_attribute_exists(bool& ret, std::string key)
00071             { ret = get_cache()->attribute_exists(key); }
00072         void sync_attribute_is_readonly(bool& ret, std::string key)
00073             { ret = get_cache()->attribute_is_readonly(key); }
00074         void sync_attribute_is_writable(bool& ret, std::string key)
00075             { ret = get_cache()->attribute_is_writable(key); }
00076         void sync_attribute_is_vector(bool& ret, std::string key)
00077             { ret = get_cache()->attribute_is_vector(key); }
00078         void sync_attribute_is_extended(bool& ret, std::string key)
00079             { ret = get_cache()->attribute_is_extended(key); }
00080 
00081 #if !defined(SAGA_ATTRIBUTE_CPI_NO_ASYNCS)
00082         // asynchronous attribute_cpi interface simply wraps the synchronous 
00083         // calls implemented in the most derived class
00084         saga::task async_get_attribute(std::string key)
00085             { return saga::adaptors::task(
00086                   "attribute_cache_cpi::async_get_attribute",
00087                   this->shared_from_this(), &Derived::sync_get_attribute, key);
00088             }
00089         saga::task async_set_attribute(std::string key, std::string val)
00090             { return saga::adaptors::task(
00091                   "attribute_cache_cpi::async_set_attribute",
00092                   this->shared_from_this(), &Derived::sync_set_attribute, 
00093                   key, val);
00094             }
00095         saga::task async_get_vector_attribute(std::string key)
00096             { return saga::adaptors::task(
00097                   "attribute_cache_cpi::async_get_vector_attribute",
00098                   this->shared_from_this(), &Derived::sync_get_vector_attribute, 
00099                   key);
00100             }
00101         saga::task async_set_vector_attribute(std::string key, strvec_type val)
00102             { return saga::adaptors::task(
00103                   "attribute_cache_cpi::async_set_vector_attribute",
00104                   this->shared_from_this(), &Derived::sync_set_vector_attribute, 
00105                   key, val);
00106             }
00107         saga::task async_remove_attribute(std::string key)
00108             { return saga::adaptors::task(
00109                   "attribute_cache_cpi::async_remove_attribute",
00110                   this->shared_from_this(), &Derived::sync_remove_attribute, 
00111                   key);
00112             }
00113         saga::task async_list_attributes()
00114             { return saga::adaptors::task(
00115                   "attribute_cache_cpi::async_list_attributes",
00116                   this->shared_from_this(), &Derived::sync_list_attributes);
00117             }
00118         saga::task async_find_attributes(std::string pattern)
00119             { return saga::adaptors::task(
00120                   "attribute_cache_cpi::async_find_attributes",
00121                   this->shared_from_this(), &Derived::sync_find_attributes, 
00122                   pattern);
00123             }
00124         saga::task async_attribute_exists(std::string key)
00125             { return saga::adaptors::task(
00126                   "attribute_cache_cpi::async_attribute_exists",
00127                   this->shared_from_this(), &Derived::sync_attribute_exists, 
00128                   key);
00129             }
00130         saga::task async_attribute_is_readonly(std::string key)
00131             { return saga::adaptors::task(
00132                   "attribute_cache_cpi::async_attribute_is_readonly",
00133                   this->shared_from_this(), &Derived::sync_attribute_is_readonly, 
00134                   key);
00135             }
00136         saga::task async_attribute_is_writable(std::string key)
00137             { return saga::adaptors::task(
00138                   "attribute_cache_cpi::async_attribute_is_writable",
00139                   this->shared_from_this(), &Derived::sync_attribute_is_writable, 
00140                   key);
00141             }
00142         saga::task async_attribute_is_vector(std::string key)
00143             { return saga::adaptors::task(
00144                   "attribute_cache_cpi::async_attribute_is_vector",
00145                   this->shared_from_this(), &Derived::sync_attribute_is_vector, 
00146                   key);
00147             }
00148         saga::task async_attribute_is_extended(std::string key)
00149             { return saga::adaptors::task(
00150                   "attribute_cache_cpi::async_attribute_is_extended",
00151                   this->shared_from_this(), &Derived::sync_attribute_is_extended, 
00152                   key);
00153             }
00154 #endif // !SAGA_ATTRIBUTE_CPI_NO_ASYNCS
00155     };
00156     
00158 }} // namespace saga::adaptors
00159                                                                              
00160 #if defined(BOOST_MSVC)
00161 #pragma warning(pop)
00162 #endif
00163 
00164 #endif
00165 
00166 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines