SAGA Adaptor CPI v.1.0
attribute_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_IMPL_ENGINE_ATTRIBUTE_CPI_HPP
00007 #define SAGA_IMPL_ENGINE_ATTRIBUTE_CPI_HPP
00008 
00009 #include <string>
00010 
00011 #include <saga/saga/util.hpp>
00012 #include <saga/saga/types.hpp>
00013 #include <saga/saga/exception.hpp>
00014 
00015 #include <saga/impl/call.hpp>
00016 #include <saga/impl/config.hpp>
00017 #include <saga/impl/engine/cpi.hpp>
00018 #include <saga/impl/engine/register_members.hpp>
00019 
00021 namespace saga { namespace impl { namespace v1_0 {
00022 
00024     class attribute_cpi 
00025         : public cpi
00026     {
00027     public:
00028         typedef std::vector <std::string> strvec_type;
00029 
00030         attribute_cpi(proxy* p, cpi_info const& info, 
00031                 TR1::shared_ptr<saga::adaptor> adaptor, cpi::flags flags) 
00032             : cpi (p, info, adaptor, flags) 
00033         { 
00034         }
00035          
00036         ~attribute_cpi(void) 
00037         {
00038         }
00039 
00040         SAGA_CALL_CPI_DECL_VIRT_1(attribute_cpi, std::string, get_attribute, std::string)
00041         SAGA_CALL_CPI_DECL_VIRT_2(attribute_cpi, saga::impl::void_t, set_attribute, std::string, std::string)
00042         SAGA_CALL_CPI_DECL_VIRT_1(attribute_cpi, strvec_type, get_vector_attribute, std::string)
00043         SAGA_CALL_CPI_DECL_VIRT_2(attribute_cpi, saga::impl::void_t, set_vector_attribute, std::string, strvec_type)
00044         SAGA_CALL_CPI_DECL_VIRT_1(attribute_cpi, saga::impl::void_t, remove_attribute, std::string)
00045 
00046         // inspection
00047         SAGA_CALL_CPI_DECL_VIRT_0(attribute_cpi, strvec_type, list_attributes)
00048         SAGA_CALL_CPI_DECL_VIRT_1(attribute_cpi, strvec_type, find_attributes, std::string)
00049 
00050         SAGA_CALL_CPI_DECL_VIRT_1(attribute_cpi, bool, attribute_exists, std::string)
00051         SAGA_CALL_CPI_DECL_VIRT_1(attribute_cpi, bool, attribute_is_readonly, std::string)
00052         SAGA_CALL_CPI_DECL_VIRT_1(attribute_cpi, bool, attribute_is_writable, std::string)
00053         SAGA_CALL_CPI_DECL_VIRT_1(attribute_cpi, bool, attribute_is_vector, std::string)
00054         SAGA_CALL_CPI_DECL_VIRT_1(attribute_cpi, bool, attribute_is_extended, std::string)
00055 
00056     }; // class attribute_cpi
00057 
00059 }}} // namespace saga::impl::v1_0
00060 
00062 namespace saga { namespace adaptors { namespace v1_0 {
00063 
00065 // register attribute CPI functions
00066     template <typename Derived>
00067     inline bool
00068     register_attribute_functions(
00069         std::vector<saga::impl::v1_0::cpi_info>& infos, 
00070         saga::impl::v1_0::cpi::maker_type maker, 
00071         saga::impl::v1_0::preference_type const& prefs, 
00072         saga::uuid const& cpi_uuid, saga::uuid const& adaptor_uuid, 
00073         std::string const& cpi_name)
00074     {
00075         bool retval = false;
00076         saga::impl::v1_0::cpi_info info(saga::adaptors::attribute_cpi,
00077             cpi_name, maker, prefs, cpi_uuid, adaptor_uuid);
00078           
00079         SAGA_LOG(SAGA_VERBOSE_LEVEL_BLURB)
00080             << "begin register_attribute_functions: " 
00081             << adaptor_uuid.string() << ":";
00082 
00083         typedef saga::impl::v1_0::attribute_cpi base_cpi;
00084         
00085         SAGA_REGISTER_MEMBER(retval, info, base_cpi, Derived, get_attribute, prefs);
00086         SAGA_REGISTER_MEMBER(retval, info, base_cpi, Derived, set_attribute, prefs);
00087         SAGA_REGISTER_MEMBER(retval, info, base_cpi, Derived, get_vector_attribute, prefs);
00088         SAGA_REGISTER_MEMBER(retval, info, base_cpi, Derived, set_vector_attribute, prefs);
00089         SAGA_REGISTER_MEMBER(retval, info, base_cpi, Derived, remove_attribute, prefs);
00090         SAGA_REGISTER_MEMBER(retval, info, base_cpi, Derived, list_attributes, prefs);
00091         SAGA_REGISTER_MEMBER(retval, info, base_cpi, Derived, find_attributes, prefs);
00092         SAGA_REGISTER_MEMBER(retval, info, base_cpi, Derived, attribute_exists, prefs);
00093         SAGA_REGISTER_MEMBER(retval, info, base_cpi, Derived, attribute_is_readonly, prefs);
00094         SAGA_REGISTER_MEMBER(retval, info, base_cpi, Derived, attribute_is_writable, prefs);
00095         SAGA_REGISTER_MEMBER(retval, info, base_cpi, Derived, attribute_is_vector, prefs);
00096         SAGA_REGISTER_MEMBER(retval, info, base_cpi, Derived, attribute_is_extended, prefs);
00097       
00098         infos.push_back(info);
00099 
00100         SAGA_LOG(SAGA_VERBOSE_LEVEL_BLURB)
00101             "end register_attribute_functions";
00102 
00103         return retval;    // is true if at least one function got registered
00104     }
00105 
00107     template <typename Derived, typename Mutex = boost::recursive_mutex>
00108     class attribute_cpi 
00109         : public saga::impl::v1_0::attribute_cpi
00110     {
00111     protected:
00112         typedef saga::impl::v1_0::attribute_cpi base_type;
00113         typedef saga::impl::proxy proxy;
00114         typedef saga::impl::v1_0::cpi cpi;
00115         typedef saga::impl::v1_0::cpi_info cpi_info;
00116         typedef saga::impl::v1_0::preference_type preference_type;
00117         typedef Mutex mutex_type;
00118         
00119     public:
00120         attribute_cpi (proxy* p, cpi_info const& info, 
00121               TR1::shared_ptr<saga::adaptor> adaptor, cpi::flags flags) 
00122             : saga::impl::v1_0::attribute_cpi(p, info, adaptor, flags) 
00123         { 
00124         }
00125          
00126         ~attribute_cpi (void) 
00127         {
00128         }
00129 
00131         // generic factory function
00132         static cpi* cpi_maker (proxy* p, cpi_info const& info,
00133             saga::ini::ini const& glob_ini, saga::ini::ini const& adap_ini,
00134             TR1::shared_ptr<saga::adaptor> adaptor)
00135         {
00136             return new Derived (p, info, glob_ini, adap_ini, adaptor);
00137         }
00138 
00140         // register implemented functions
00141         static void 
00142         register_cpi(std::vector<cpi_info>& infos, preference_type prefs, 
00143             saga::uuid adaptor_uuid)
00144         {
00145             // register attribute CPI functions
00146             saga::uuid cpi_uuid;
00147             register_attribute_functions<Derived>(infos, 
00148                 &saga::adaptors::v1_0::attribute_cpi<Derived>::cpi_maker, 
00149                 prefs, cpi_uuid, adaptor_uuid, saga::adaptors::attribute_cpi);
00150         }
00151 
00153         // generic up-cast of the impl pointer       
00154         TR1::shared_ptr<Derived> shared_from_this()
00155         {
00156             return TR1::static_pointer_cast<Derived>(
00157                 this->base_type::shared_from_this());
00158         }
00159 
00160     }; // class attribute_cpi
00161 
00163 }}} // namespace saga::adaptors::v1_0
00164 
00165 #endif // SAGA_IMPL_ENGINE_ATTRIBUTE_CPI_HPP
00166 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines