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) && !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
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 template <typename ImplType>
00171 ImplType *get_target_object() const;
00173
00174 protected:
00176 Derived& derived()
00177 { return static_cast<Derived&>(*this); }
00178 Derived const& derived() const
00179 { return static_cast<Derived const&>(*this); }
00180
00181 void init (strmap_type const& scalar_ro = strmap_type (),
00182 strmap_type const& scalar_rw = strmap_type (),
00183 strmap_type const& vector_ro = strmap_type (),
00184 strmap_type const& vector_rw = strmap_type ());
00185 void init (bool extensible, bool cache_only = false);
00186
00187 void init_keynames(strvec_type const& keynames);
00189
00190 public:
00196 SAGA_SYMBOL_INTERNAL
00197 std::string get_attribute(std::string key) const
00198 {
00199 saga::task t = get_attributepriv(key, saga::task_base::Sync());
00200 return t.get_result<std::string>();
00201 }
00202
00203 SAGA_CALL_CONST_PUB_1_DEF_0(get_attribute, std::string)
00204
00205
00210 SAGA_SYMBOL_INTERNAL
00211 void set_attribute(std::string key, std::string value)
00212 {
00213 set_attributepriv(key, value, saga::task_base::Sync());
00214 }
00215
00216 SAGA_CALL_PUB_2_DEF_0(set_attribute, std::string, std::string)
00217
00218
00223 SAGA_SYMBOL_INTERNAL
00224 strvec_type get_vector_attribute(std::string key) const
00225 {
00226 saga::task t = get_vector_attributepriv(key,
00227 saga::task_base::Sync());
00228 return t.get_result<strvec_type>();
00229 }
00230
00231 SAGA_CALL_CONST_PUB_1_DEF_0(get_vector_attribute, std::string)
00232
00233
00238 SAGA_SYMBOL_INTERNAL
00239 void set_vector_attribute(std::string key, strvec_type value)
00240 {
00241 set_vector_attributepriv(key, value, saga::task_base::Sync());
00242 }
00243
00244 SAGA_CALL_PUB_2_DEF_0(set_vector_attribute, std::string, strvec_type)
00245
00246
00250 SAGA_SYMBOL_INTERNAL
00251 void remove_attribute(std::string key)
00252 {
00253 remove_attributepriv(key, saga::task_base::Sync());
00254 }
00255
00256 SAGA_CALL_PUB_1_DEF_0(remove_attribute, std::string)
00257
00258
00262 SAGA_SYMBOL_INTERNAL
00263 strvec_type list_attributes() const
00264 {
00265 saga::task t = list_attributespriv(saga::task_base::Sync());
00266 return t.get_result<strvec_type>();
00267 }
00268
00269 SAGA_CALL_CONST_PUB_0_DEF_0(list_attributes)
00270
00271
00277 SAGA_SYMBOL_INTERNAL
00278 strvec_type find_attributes(std::string pattern) const
00279 {
00280 saga::task t = find_attributespriv(pattern,
00281 saga::task_base::Sync());
00282 return t.get_result<strvec_type>();
00283 }
00284
00285 SAGA_CALL_CONST_PUB_1_DEF_0(find_attributes, std::string)
00286
00287
00292 SAGA_SYMBOL_INTERNAL
00293 bool attribute_exists(std::string key) const
00294 {
00295 saga::task t = attribute_existspriv(key,
00296 saga::task_base::Sync());
00297 return t.get_result<bool>();
00298 }
00299
00300 SAGA_CALL_CONST_PUB_1_DEF_0(attribute_exists, std::string)
00301
00302
00307 SAGA_SYMBOL_INTERNAL
00308 bool attribute_is_readonly(std::string key) const
00309 {
00310 saga::task t = attribute_is_readonlypriv(key,
00311 saga::task_base::Sync());
00312 return t.get_result<bool>();
00313 }
00314
00315 SAGA_CALL_CONST_PUB_1_DEF_0(attribute_is_readonly, std::string)
00316
00317
00322 SAGA_SYMBOL_INTERNAL
00323 bool attribute_is_writable(std::string key) const
00324 {
00325 saga::task t = attribute_is_writablepriv(key,
00326 saga::task_base::Sync());
00327 return t.get_result<bool>();
00328 }
00329
00330 SAGA_CALL_CONST_PUB_1_DEF_0(attribute_is_writable, std::string)
00331
00332
00337 SAGA_SYMBOL_INTERNAL
00338 bool attribute_is_vector(std::string key) const
00339 {
00340 saga::task t = attribute_is_vectorpriv(key,
00341 saga::task_base::Sync());
00342 return t.get_result<bool>();
00343 }
00344
00345 SAGA_CALL_CONST_PUB_1_DEF_0(attribute_is_vector, std::string)
00346
00347
00352 SAGA_SYMBOL_INTERNAL
00353 bool attribute_is_removable(std::string key) const
00354 {
00355 saga::task t = attribute_is_removablepriv(key,
00356 saga::task_base::Sync());
00357 return t.get_result<bool>();
00358 }
00359
00360 SAGA_CALL_CONST_PUB_1_DEF_0(attribute_is_removable, std::string)
00361 };
00362
00364 }}
00365
00366 #if defined(BOOST_MSVC)
00367 #pragma warning(pop)
00368 #endif
00369
00370 #endif // SAGA_SAGA_DETAIL_ATTRIBUTE_HPP
00371