SAGA Adaptor CPI v.1.0
|
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_ADAPTORS_ATTRIBUTE_CPI_WRAPPER_HPP 00007 #define SAGA_SAGA_ADAPTORS_ATTRIBUTE_CPI_WRAPPER_HPP 00008 00009 #include <string> 00010 #include <vector> 00011 00012 #include <saga/saga/adaptors/attribute_cpi.hpp> 00013 #include <saga/impl/engine/attribute_interface.hpp> 00014 00016 namespace saga { namespace adaptors 00017 { 00019 // This wrapper is used in conjunction with the saga::attribute and 00020 // saga::adaptors::attribute classes when these are used from within a cpi 00021 // instance to access the very own attributes of this cpi instance 00022 class const_attribute_cpi_wrapper 00023 : public saga::impl::attribute_interface 00024 { 00025 typedef std::vector <std::string> strvec_type; 00026 00027 public: 00028 // we const_cast here while guaranteeing to fail all attempts to write 00029 // access to this instance 00030 const_attribute_cpi_wrapper(saga::impl::v1_0::attribute_cpi const* cpi_instance) 00031 : attributes_(const_cast<saga::impl::v1_0::attribute_cpi*>(cpi_instance)) 00032 { 00033 } 00034 00035 saga::task 00036 get_attribute(std::string key, bool is_sync) 00037 { 00038 if (is_sync) { 00039 saga::task t(saga::task::Done); 00040 attributes_-> 00041 sync_get_attribute(t.get_result<std::string>(), key); 00042 return t; 00043 } 00044 return attributes_->async_get_attribute(key); 00045 } 00046 saga::task 00047 set_attribute(std::string key, std::string val, bool is_sync) 00048 { 00049 SAGA_THROW("const_attribute_cpi_wrapper::set_vector" 00050 " is not implemented (and rightly so!)", 00051 saga::NotImplemented); 00052 return saga::task(); 00053 } 00054 saga::task 00055 get_vector_attribute(std::string key, bool is_sync) 00056 { 00057 if (is_sync) { 00058 saga::task t(saga::task::Done); 00059 attributes_-> 00060 sync_get_vector_attribute(t.get_result<strvec_type>(), key); 00061 return t; 00062 } 00063 return attributes_->async_get_vector_attribute(key); 00064 } 00065 saga::task 00066 set_vector_attribute(std::string key, strvec_type val, bool is_sync) 00067 { 00068 SAGA_THROW("const_attribute_cpi_wrapper::set_vector_attribute" 00069 " is not implemented (and rightly so!)", 00070 saga::NotImplemented); 00071 return saga::task(); 00072 } 00073 saga::task 00074 remove_attribute(std::string key, bool is_sync) 00075 { 00076 SAGA_THROW("const_attribute_cpi_wrapper::remove_attribute" 00077 " is not implemented (and rightly so!)", 00078 saga::NotImplemented); 00079 return saga::task(); 00080 } 00081 saga::task 00082 list_attributes(bool is_sync) 00083 { 00084 if (is_sync) { 00085 saga::task t(saga::task::Done); 00086 attributes_->sync_list_attributes( 00087 t.get_result<strvec_type>()); 00088 return t; 00089 } 00090 return attributes_->async_list_attributes(); 00091 } 00092 saga::task 00093 find_attributes(std::string pattern, bool is_sync) 00094 { 00095 if (is_sync) { 00096 saga::task t(saga::task::Done); 00097 attributes_->sync_find_attributes( 00098 t.get_result<strvec_type>(), pattern); 00099 return t; 00100 } 00101 return attributes_->async_find_attributes(pattern); 00102 } 00103 saga::task 00104 attribute_exists(std::string key, bool is_sync) 00105 { 00106 if (is_sync) { 00107 saga::task t(saga::task::Done); 00108 attributes_->sync_attribute_exists( 00109 t.get_result<bool>(), key); 00110 return t; 00111 } 00112 return attributes_->async_attribute_exists(key); 00113 } 00114 saga::task 00115 attribute_is_readonly(std::string key, bool is_sync) 00116 { 00117 if (is_sync) { 00118 saga::task t(saga::task::Done); 00119 attributes_->sync_attribute_is_readonly( 00120 t.get_result<bool>(), key); 00121 return t; 00122 } 00123 return attributes_->async_attribute_is_readonly(key); 00124 } 00125 saga::task 00126 attribute_is_writable(std::string key, bool is_sync) 00127 { 00128 if (is_sync) { 00129 saga::task t(saga::task::Done); 00130 attributes_->sync_attribute_is_writable( 00131 t.get_result<bool>(), key); 00132 return t; 00133 } 00134 return attributes_->async_attribute_is_writable(key); 00135 } 00136 saga::task 00137 attribute_is_vector(std::string key, bool is_sync) 00138 { 00139 if (is_sync) { 00140 saga::task t(saga::task::Done); 00141 attributes_->sync_attribute_is_vector( 00142 t.get_result<bool>(), key); 00143 return t; 00144 } 00145 return attributes_->async_attribute_is_vector(key); 00146 } 00147 saga::task 00148 attribute_is_extended(std::string key, bool is_sync) 00149 { 00150 if (is_sync) { 00151 saga::task t(saga::task::Done); 00152 attributes_->sync_attribute_is_extended( 00153 t.get_result<bool>(), key); 00154 return t; 00155 } 00156 return attributes_->async_attribute_is_extended(key); 00157 } 00158 00159 private: 00160 saga::impl::v1_0::attribute_cpi* attributes_; 00161 }; 00162 00164 // same as above, but allowing to change attributes 00165 class attribute_cpi_wrapper 00166 : public saga::impl::attribute_interface 00167 { 00168 typedef std::vector <std::string> strvec_type; 00169 00170 public: 00171 attribute_cpi_wrapper(saga::impl::v1_0::attribute_cpi* cpi_instance) 00172 : attributes_(cpi_instance) 00173 { 00174 } 00175 00176 saga::task 00177 get_attribute(std::string key, bool is_sync) 00178 { 00179 if (is_sync) { 00180 saga::task t(saga::task::Done); 00181 attributes_-> 00182 sync_get_attribute(t.get_result<std::string>(), key); 00183 return t; 00184 } 00185 return attributes_->async_get_attribute(key); 00186 } 00187 saga::task 00188 set_attribute(std::string key, std::string val, bool is_sync) 00189 { 00190 if (is_sync) { 00191 saga::task t(saga::task::Done); 00192 saga::impl::void_t void_result; 00193 attributes_->sync_set_attribute(void_result, key, val); 00194 return t; 00195 } 00196 return attributes_->async_set_attribute(key, val); 00197 } 00198 saga::task 00199 get_vector_attribute(std::string key, bool is_sync) 00200 { 00201 if (is_sync) { 00202 saga::task t(saga::task::Done); 00203 attributes_-> 00204 sync_get_vector_attribute(t.get_result<strvec_type>(), key); 00205 return t; 00206 } 00207 return attributes_->async_get_vector_attribute(key); 00208 } 00209 saga::task 00210 set_vector_attribute(std::string key, strvec_type val, bool is_sync) 00211 { 00212 if (is_sync) { 00213 saga::task t(saga::task::Done); 00214 saga::impl::void_t void_result; 00215 attributes_->sync_set_vector_attribute(void_result, key, val); 00216 return t; 00217 } 00218 return attributes_->async_set_vector_attribute(key, val); 00219 } 00220 saga::task 00221 remove_attribute(std::string key, bool is_sync) 00222 { 00223 if (is_sync) { 00224 saga::task t(saga::task::Done); 00225 saga::impl::void_t void_result; 00226 attributes_->sync_remove_attribute(void_result, key); 00227 return t; 00228 } 00229 return attributes_->async_remove_attribute(key); 00230 } 00231 saga::task 00232 list_attributes(bool is_sync) 00233 { 00234 if (is_sync) { 00235 saga::task t(saga::task::Done); 00236 attributes_->sync_list_attributes( 00237 t.get_result<strvec_type>()); 00238 return t; 00239 } 00240 return attributes_->async_list_attributes(); 00241 } 00242 saga::task 00243 find_attributes(std::string pattern, bool is_sync) 00244 { 00245 if (is_sync) { 00246 saga::task t(saga::task::Done); 00247 attributes_->sync_find_attributes( 00248 t.get_result<strvec_type>(), pattern); 00249 return t; 00250 } 00251 return attributes_->async_find_attributes(pattern); 00252 } 00253 saga::task 00254 attribute_exists(std::string key, bool is_sync) 00255 { 00256 if (is_sync) { 00257 saga::task t(saga::task::Done); 00258 attributes_->sync_attribute_exists( 00259 t.get_result<bool>(), key); 00260 return t; 00261 } 00262 return attributes_->async_attribute_exists(key); 00263 } 00264 saga::task 00265 attribute_is_readonly(std::string key, bool is_sync) 00266 { 00267 if (is_sync) { 00268 saga::task t(saga::task::Done); 00269 attributes_->sync_attribute_is_readonly( 00270 t.get_result<bool>(), key); 00271 return t; 00272 } 00273 return attributes_->async_attribute_is_readonly(key); 00274 } 00275 saga::task 00276 attribute_is_writable(std::string key, bool is_sync) 00277 { 00278 if (is_sync) { 00279 saga::task t(saga::task::Done); 00280 attributes_->sync_attribute_is_writable( 00281 t.get_result<bool>(), key); 00282 return t; 00283 } 00284 return attributes_->async_attribute_is_writable(key); 00285 } 00286 saga::task 00287 attribute_is_vector(std::string key, bool is_sync) 00288 { 00289 if (is_sync) { 00290 saga::task t(saga::task::Done); 00291 attributes_->sync_attribute_is_vector( 00292 t.get_result<bool>(), key); 00293 return t; 00294 } 00295 return attributes_->async_attribute_is_vector(key); 00296 } 00297 saga::task 00298 attribute_is_extended(std::string key, bool is_sync) 00299 { 00300 if (is_sync) { 00301 saga::task t(saga::task::Done); 00302 attributes_->sync_attribute_is_extended( 00303 t.get_result<bool>(), key); 00304 return t; 00305 } 00306 return attributes_->async_attribute_is_extended(key); 00307 } 00308 00309 private: 00310 saga::impl::v1_0::attribute_cpi* attributes_; 00311 }; 00312 00314 }} // namespace saga::adaptors 00315 00316 #endif // !SAGA_SAGA_ADAPTORS_ATTRIBUTE_CPI_WRAPPER_HPP 00317 00318