00001
00002
00003
00004
00005
00006 #ifndef SAGA_SAGA_DETAIL_ATTRIBUTE_HPP
00007 #define SAGA_SAGA_DETAIL_ATTRIBUTE_HPP
00008
00009
00010 #include <map>
00011 #include <vector>
00012 #include <string>
00013
00014
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
00021 #include <saga/saga-defs.hpp>
00022
00023
00024 #if defined(BOOST_MSVC)
00025 #pragma warning(push)
00026 #pragma warning(disable : 4251 4231 4660)
00027 #endif
00028
00030
00031 #if !defined (SAGA_CREATE_PREPROCESSED_FILES)
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
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 };
00079
00102 template <typename Derived>
00103 struct SAGA_EXPORT_ATTRIBUTE attribute
00104 {
00105 public:
00109 typedef std::vector <std::string> strvec_type;
00110
00114 typedef std::map <std::string, std::string> strmap_type;
00115
00116 private:
00117 template <typename Tag>
00118 saga::task get_attributepriv (std::string const& p, Tag) const
00119 { return attribute_priv<Derived, Tag>::get_attributepriv(derived(), p); }
00120
00121 template <typename Tag>
00122 saga::task set_attributepriv (std::string const& p1, std::string const& p2, Tag)
00123 { return attribute_priv<Derived, Tag>::set_attributepriv(derived(), p1, p2); }
00124
00125 template <typename Tag>
00126 saga::task get_vector_attributepriv(std::string const& p, Tag) const
00127 { return attribute_priv<Derived, Tag>::get_vector_attributepriv(derived(), p); }
00128
00129 template <typename Tag>
00130 saga::task set_vector_attributepriv(std::string const& p1, strvec_type const& p2, Tag)
00131 { return attribute_priv<Derived, Tag>::set_vector_attributepriv(derived(), p1, p2); }
00132
00133 template <typename Tag>
00134 saga::task remove_attributepriv(std::string const& p, Tag)
00135 { return attribute_priv<Derived, Tag>::remove_attributepriv(derived(), p); }
00136
00137 template <typename Tag>
00138 saga::task list_attributespriv(Tag) const
00139 { return attribute_priv<Derived, Tag>::list_attributespriv(derived()); }
00140
00141 template <typename Tag>
00142 saga::task find_attributespriv(std::string const& p1, Tag) const
00143 { return attribute_priv<Derived, Tag>::find_attributespriv(derived(), p1); }
00144
00145 template <typename Tag>
00146 saga::task attribute_existspriv(std::string const& p, Tag) const
00147 { return attribute_priv<Derived, Tag>::attribute_existspriv(derived(), p); }
00148
00149 template <typename Tag>
00150 saga::task attribute_is_readonlypriv(std::string const& p, Tag) const
00151 { return attribute_priv<Derived, Tag>::attribute_is_readonlypriv(derived(), p); }
00152
00153 template <typename Tag>
00154 saga::task attribute_is_writablepriv(std::string const& p, Tag) const
00155 { return attribute_priv<Derived, Tag>::attribute_is_writablepriv(derived(), p); }
00156
00157 template <typename Tag>
00158 saga::task attribute_is_vectorpriv(std::string const& p, Tag) const
00159 { return attribute_priv<Derived, Tag>::attribute_is_vectorpriv(derived(), p); }
00160
00161 template <typename Tag>
00162 saga::task attribute_is_removablepriv(std::string const& p, Tag) const
00163 { return attribute_priv<Derived, Tag>::attribute_is_removablepriv(derived(), p); }
00164
00165 public:
00167 impl::attribute_interface* get_attr (void);
00168 impl::attribute_interface* get_attr (void) const;
00169
00170 impl::object *get_target_object() const;
00172
00173 protected:
00175 Derived& derived()
00176 { return static_cast<Derived&>(*this); }
00177 Derived const& derived() const
00178 { return static_cast<Derived const&>(*this); }
00179
00180 void init (strmap_type const& scalar_ro = strmap_type (),
00181 strmap_type const& scalar_rw = strmap_type (),
00182 strmap_type const& vector_ro = strmap_type (),
00183 strmap_type const& vector_rw = strmap_type ());
00184 void init (bool extensible, bool cache_only = false);
00185
00186 void init_keynames(strvec_type const& keynames);
00188
00189 public:
00195 SAGA_SYMBOL_INTERNAL
00196 std::string get_attribute(std::string key) const
00197 {
00198 saga::task t = get_attributepriv(key, saga::task_base::Sync());
00199 return t.get_result<std::string>();
00200 }
00201
00202 SAGA_CALL_CONST_PUB_1_DEF_0(get_attribute, std::string)
00203
00204
00209 SAGA_SYMBOL_INTERNAL
00210 void set_attribute(std::string key, std::string value)
00211 {
00212 set_attributepriv(key, value, saga::task_base::Sync());
00213 }
00214
00215 SAGA_CALL_PUB_2_DEF_0(set_attribute, std::string, std::string)
00216
00217
00222 SAGA_SYMBOL_INTERNAL
00223 strvec_type get_vector_attribute(std::string key) const
00224 {
00225 saga::task t = get_vector_attributepriv(key,
00226 saga::task_base::Sync());
00227 return t.get_result<strvec_type>();
00228 }
00229
00230 SAGA_CALL_CONST_PUB_1_DEF_0(get_vector_attribute, std::string)
00231
00232
00237 SAGA_SYMBOL_INTERNAL
00238 void set_vector_attribute(std::string key, strvec_type value)
00239 {
00240 set_vector_attributepriv(key, value, saga::task_base::Sync());
00241 }
00242
00243 SAGA_CALL_PUB_2_DEF_0(set_vector_attribute, std::string, strvec_type)
00244
00245
00249 SAGA_SYMBOL_INTERNAL
00250 void remove_attribute(std::string key)
00251 {
00252 remove_attributepriv(key, saga::task_base::Sync());
00253 }
00254
00255 SAGA_CALL_PUB_1_DEF_0(remove_attribute, std::string)
00256
00257
00261 SAGA_SYMBOL_INTERNAL
00262 strvec_type list_attributes() const
00263 {
00264 saga::task t = list_attributespriv(saga::task_base::Sync());
00265 return t.get_result<strvec_type>();
00266 }
00267
00268 SAGA_CALL_CONST_PUB_0_DEF_0(list_attributes)
00269
00270
00276 SAGA_SYMBOL_INTERNAL
00277 strvec_type find_attributes(std::string pattern) const
00278 {
00279 saga::task t = find_attributespriv(pattern,
00280 saga::task_base::Sync());
00281 return t.get_result<strvec_type>();
00282 }
00283
00284 SAGA_CALL_CONST_PUB_1_DEF_0(find_attributes, std::string)
00285
00286
00291 SAGA_SYMBOL_INTERNAL
00292 bool attribute_exists(std::string key) const
00293 {
00294 saga::task t = attribute_existspriv(key,
00295 saga::task_base::Sync());
00296 return t.get_result<bool>();
00297 }
00298
00299 SAGA_CALL_CONST_PUB_1_DEF_0(attribute_exists, std::string)
00300
00301
00306 SAGA_SYMBOL_INTERNAL
00307 bool attribute_is_readonly(std::string key) const
00308 {
00309 saga::task t = attribute_is_readonlypriv(key,
00310 saga::task_base::Sync());
00311 return t.get_result<bool>();
00312 }
00313
00314 SAGA_CALL_CONST_PUB_1_DEF_0(attribute_is_readonly, std::string)
00315
00316
00321 SAGA_SYMBOL_INTERNAL
00322 bool attribute_is_writable(std::string key) const
00323 {
00324 saga::task t = attribute_is_writablepriv(key,
00325 saga::task_base::Sync());
00326 return t.get_result<bool>();
00327 }
00328
00329 SAGA_CALL_CONST_PUB_1_DEF_0(attribute_is_writable, std::string)
00330
00331
00336 SAGA_SYMBOL_INTERNAL
00337 bool attribute_is_vector(std::string key) const
00338 {
00339 saga::task t = attribute_is_vectorpriv(key,
00340 saga::task_base::Sync());
00341 return t.get_result<bool>();
00342 }
00343
00344 SAGA_CALL_CONST_PUB_1_DEF_0(attribute_is_vector, std::string)
00345
00346
00351 SAGA_SYMBOL_INTERNAL
00352 bool attribute_is_removable(std::string key) const
00353 {
00354 saga::task t = attribute_is_removablepriv(key,
00355 saga::task_base::Sync());
00356 return t.get_result<bool>();
00357 }
00358
00359 SAGA_CALL_CONST_PUB_1_DEF_0(attribute_is_removable, std::string)
00360 };
00361
00363 }}
00364
00365 #if defined(BOOST_MSVC)
00366 #pragma warning(pop)
00367 #endif
00368
00369 #endif // SAGA_SAGA_DETAIL_ATTRIBUTE_HPP
00370