SAGA C++ API 1.6
attribute.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_HPP
00007 #define SAGA_SAGA_DETAIL_ATTRIBUTE_HPP
00008 
00009 // include stl
00010 #include <map>
00011 #include <vector>
00012 #include <string>
00013 
00014 // include dependent spec sections
00015 #include <saga/saga/util.hpp>
00016 #include <saga/saga/base.hpp>
00017 #include <saga/saga/call.hpp>
00018 #include <saga/saga/task.hpp>
00019 
00020 // For symbol import/export macros
00021 #include <saga/saga-defs.hpp>
00022 
00023 // suppress warnings about dependent classes not being exported from the dll
00024 #if defined(BOOST_MSVC)
00025 #pragma warning(push)
00026 #pragma warning(disable : 4251 4231 4660)
00027 #endif
00028 
00030 // for modules not belonging to the engine attributes should not be exported
00031 #if !defined (SAGA_CREATE_PREPROCESSED_FILES) && !defined(SAGA_EXPORT_ATTRIBUTE)
00032 
00033 # if defined(SAGA_ENGINE_EXPORTS) || defined(SAGA_ATTRIBUTE_EXPORTS)
00034 #   define SAGA_EXPORT_ATTRIBUTE SAGA_SYMBOL_EXPORT
00035 # elif !defined (SAGA_NO_IMPORT_ATTRIBUTE) && !defined(BUILD_SAGA_LITE)
00036 #   define SAGA_EXPORT_ATTRIBUTE SAGA_SYMBOL_IMPORT
00037 # else
00038 #   define SAGA_EXPORT_ATTRIBUTE /* empty */
00039 # endif
00040 
00041 #endif // !SAGA_CREATE_PREPROCESSED_FILES
00042 
00044 namespace saga { namespace detail
00045 {
00047     template <typename Derived, typename Tag>
00048     struct SAGA_EXPORT_ATTRIBUTE attribute_priv
00049     {
00050         typedef std::vector<std::string> strvec_type;
00051 
00052         static saga::task get_attributepriv (Derived const& this_, 
00053             std::string const&);
00054         static saga::task set_attributepriv (Derived& this_, 
00055             std::string const&, std::string const&);
00056 
00057         static saga::task get_vector_attributepriv(Derived const& this_, 
00058             std::string const&);
00059         static saga::task set_vector_attributepriv(Derived& this_, 
00060             std::string const&, strvec_type const&);
00061         static saga::task remove_attributepriv(Derived& this_, 
00062             std::string const&);
00063 
00064         static saga::task list_attributespriv(Derived const& this_);
00065         static saga::task find_attributespriv(Derived const& this_, 
00066             std::string const&);
00067         static saga::task attribute_existspriv(Derived const& this_, 
00068             std::string const&);
00069         static saga::task attribute_is_readonlypriv(Derived const& this_, 
00070             std::string const&);
00071         static saga::task attribute_is_writablepriv(Derived const& this_, 
00072             std::string const&);
00073         static saga::task attribute_is_vectorpriv(Derived const& this_, 
00074             std::string const&);
00075         static saga::task attribute_is_removablepriv(Derived const& this_, 
00076             std::string const&);
00077     };
00078 
00079     template <typename Derived>
00080     struct SAGA_EXPORT_ATTRIBUTE attribute_sync
00081       : attribute_priv<Derived, saga::task_base::Sync>
00082     {
00083         typedef std::vector<std::string> strvec_type;
00084 
00085         static std::string get_attribute(Derived const& this_, 
00086             std::string const&);
00087         static void set_attribute(Derived& this_, 
00088             std::string const&, std::string const&);
00089 
00090         static void get_vector_attribute(Derived const& this_, 
00091             std::string const&, strvec_type&);
00092         static void set_vector_attribute(Derived& this_, 
00093             std::string const&, strvec_type const&);
00094         static void remove_attribute(Derived& this_, 
00095             std::string const&);
00096 
00097         static void list_attributes(Derived const& this_,
00098             strvec_type&);
00099         static void find_attributes(Derived const& this_, 
00100             std::string const&, strvec_type&);
00101 
00102         static bool attribute_exists(Derived const& this_, 
00103             std::string const&);
00104         static bool attribute_is_readonly(Derived const& this_, 
00105             std::string const&);
00106         static bool attribute_is_writable(Derived const& this_, 
00107             std::string const&);
00108         static bool attribute_is_vector(Derived const& this_, 
00109             std::string const&);
00110         static bool attribute_is_removable(Derived const& this_, 
00111             std::string const&);
00112     };
00114 
00137     template <typename Derived>
00138     struct SAGA_EXPORT_ATTRIBUTE attribute 
00139     {
00140     public:
00144         typedef std::vector <std::string>              strvec_type;
00145 
00149         typedef std::map <std::string, std::string> strmap_type;
00150 
00151     private:
00152         template <typename Tag>
00153         saga::task get_attributepriv (std::string const& p, Tag) const
00154         { return attribute_priv<Derived, Tag>::get_attributepriv(derived(), p); }
00155 
00156         template <typename Tag>
00157         saga::task set_attributepriv (std::string const& p1, std::string const& p2, Tag)
00158         { return attribute_priv<Derived, Tag>::set_attributepriv(derived(), p1, p2); }
00159 
00160         template <typename Tag>
00161         saga::task get_vector_attributepriv(std::string const& p, Tag) const
00162         { return attribute_priv<Derived, Tag>::get_vector_attributepriv(derived(), p); }
00163 
00164         template <typename Tag>
00165         saga::task set_vector_attributepriv(std::string const& p1, strvec_type const& p2, Tag)
00166         { return attribute_priv<Derived, Tag>::set_vector_attributepriv(derived(), p1, p2); }
00167 
00168         template <typename Tag>
00169         saga::task remove_attributepriv(std::string const& p, Tag)
00170         { return attribute_priv<Derived, Tag>::remove_attributepriv(derived(), p); }
00171 
00172         template <typename Tag>
00173         saga::task list_attributespriv(Tag) const
00174         { return attribute_priv<Derived, Tag>::list_attributespriv(derived()); }
00175 
00176         template <typename Tag>
00177         saga::task find_attributespriv(std::string const& p1, Tag) const
00178         { return attribute_priv<Derived, Tag>::find_attributespriv(derived(), p1); }
00179 
00180         template <typename Tag>
00181         saga::task attribute_existspriv(std::string const& p, Tag) const
00182         { return attribute_priv<Derived, Tag>::attribute_existspriv(derived(), p); }
00183 
00184         template <typename Tag>
00185         saga::task attribute_is_readonlypriv(std::string const& p, Tag) const
00186         { return attribute_priv<Derived, Tag>::attribute_is_readonlypriv(derived(), p); }
00187 
00188         template <typename Tag>
00189         saga::task attribute_is_writablepriv(std::string const& p, Tag) const
00190         { return attribute_priv<Derived, Tag>::attribute_is_writablepriv(derived(), p); }
00191 
00192         template <typename Tag>
00193         saga::task attribute_is_vectorpriv(std::string const& p, Tag) const
00194         { return attribute_priv<Derived, Tag>::attribute_is_vectorpriv(derived(), p); }
00195 
00196         template <typename Tag>
00197         saga::task attribute_is_removablepriv(std::string const& p, Tag) const
00198         { return attribute_priv<Derived, Tag>::attribute_is_removablepriv(derived(), p); }
00199 
00200     public:
00202         impl::attribute_interface* get_attr (void);
00203         impl::attribute_interface* get_attr (void) const;
00204 
00205         template <typename ImplType>
00206         ImplType *get_target_object() const;
00208 
00209     protected:
00211         Derived& derived() 
00212             { return static_cast<Derived&>(*this); }
00213         Derived const& derived() const 
00214             { return static_cast<Derived const&>(*this); }
00215 
00216         void init (strmap_type const& scalar_ro  = strmap_type (),
00217                    strmap_type const& scalar_rw  = strmap_type (),
00218                    strmap_type const& vector_ro  = strmap_type (),
00219                    strmap_type const& vector_rw  = strmap_type ());
00220         void init (char const* const* scalar_ro, char const* const* scalar_rw,
00221                    char const* const* vector_ro, char const* const* vector_rw);
00222         void init (bool extensible, bool cache_only = false);
00223 
00224         void init_keynames(strvec_type const& keynames);
00225         void init_keynames(char const* const* keynames);
00227 
00228     public:
00234         SAGA_SYMBOL_INTERNAL
00235         std::string get_attribute(std::string const& key) const
00236         {
00237             return attribute_sync<Derived>::
00238                 get_attribute(derived(), key);
00239         }
00240 
00241         SAGA_CALL_CONST_PUB_1_DEF_0(get_attribute, std::string)
00242 
00243         
00248         SAGA_SYMBOL_INTERNAL
00249         void set_attribute(std::string const& key, std::string const& value)
00250         {
00251             attribute_sync<Derived>::set_attribute(derived(), key, value);
00252         }
00253 
00254         SAGA_CALL_PUB_2_DEF_0(set_attribute, std::string, std::string)
00255 
00256         
00261         SAGA_SYMBOL_INTERNAL
00262         strvec_type get_vector_attribute(std::string const& key) const
00263         {
00264             strvec_type retval;
00265             attribute_sync<Derived>::get_vector_attribute(derived(), key, retval);
00266             return retval;
00267         }
00268 
00269         SAGA_CALL_CONST_PUB_1_DEF_0(get_vector_attribute, std::string)
00270 
00271         
00276         SAGA_SYMBOL_INTERNAL
00277         void set_vector_attribute(std::string const& key, strvec_type const& value)
00278         {
00279             attribute_sync<Derived>::set_vector_attribute(derived(), key, value);
00280         }
00281 
00282         SAGA_CALL_PUB_2_DEF_0(set_vector_attribute, std::string, strvec_type)
00283 
00284         
00288         SAGA_SYMBOL_INTERNAL
00289         void remove_attribute(std::string const& key)
00290         {
00291             attribute_sync<Derived>::remove_attribute(derived(), key);
00292         }
00293 
00294         SAGA_CALL_PUB_1_DEF_0(remove_attribute, std::string)
00295 
00296         
00300         SAGA_SYMBOL_INTERNAL
00301         strvec_type list_attributes() const
00302         {
00303             strvec_type retval;
00304             attribute_sync<Derived>::list_attributes(derived(), retval);
00305             return retval;
00306         }
00307 
00308         SAGA_CALL_CONST_PUB_0_DEF_0(list_attributes)
00309 
00310         
00316         SAGA_SYMBOL_INTERNAL
00317         strvec_type find_attributes(std::string const& pattern) const
00318         {
00319             strvec_type retval;
00320             attribute_sync<Derived>::find_attributes(derived(), pattern, retval);
00321             return retval;
00322         }
00323 
00324         SAGA_CALL_CONST_PUB_1_DEF_0(find_attributes, std::string)
00325 
00326         
00331         SAGA_SYMBOL_INTERNAL
00332         bool attribute_exists(std::string const& key) const
00333         {
00334             return attribute_sync<Derived>::attribute_exists(derived(), key);
00335         }
00336 
00337         SAGA_CALL_CONST_PUB_1_DEF_0(attribute_exists, std::string)
00338 
00339         
00344         SAGA_SYMBOL_INTERNAL
00345         bool attribute_is_readonly(std::string const& key) const
00346         {
00347             return attribute_sync<Derived>::attribute_is_readonly(derived(), key);
00348         }
00349 
00350         SAGA_CALL_CONST_PUB_1_DEF_0(attribute_is_readonly, std::string)
00351 
00352         
00357         SAGA_SYMBOL_INTERNAL
00358         bool attribute_is_writable(std::string const& key) const
00359         {
00360             return attribute_sync<Derived>::attribute_is_writable(derived(), key);
00361         }
00362 
00363         SAGA_CALL_CONST_PUB_1_DEF_0(attribute_is_writable, std::string)
00364 
00365         
00370         SAGA_SYMBOL_INTERNAL
00371         bool attribute_is_vector(std::string const& key) const
00372         {
00373             return attribute_sync<Derived>::attribute_is_vector(derived(), key);
00374         }
00375 
00376         SAGA_CALL_CONST_PUB_1_DEF_0(attribute_is_vector, std::string)
00377         
00378         
00383         SAGA_SYMBOL_INTERNAL
00384         bool attribute_is_removable(std::string const& key) const
00385         {
00386             return attribute_sync<Derived>::attribute_is_removable(derived(), key);
00387         }
00388 
00389         SAGA_CALL_CONST_PUB_1_DEF_0(attribute_is_removable, std::string)
00390     };
00391 
00393 }}   // namespace saga::detail
00394 
00395 #if defined(BOOST_MSVC)
00396 #pragma warning(pop)
00397 #endif
00398 
00399 #endif // SAGA_SAGA_DETAIL_ATTRIBUTE_HPP
00400 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines