SAGA Adaptor CPI v.1.0
|
00001 // Copyright (c) 2005-2009 Hartmut Kaiser 00002 // Copyright (c) 2005-2007 Andre Merzky (andre@merzky.net) 00003 // 00004 // Distributed under the Boost Software License, Version 1.0. (See accompanying 00005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 00006 00007 #include <saga/saga/exception.hpp> 00008 #include <saga/saga/object.hpp> 00009 #include <saga/saga/task.hpp> 00010 #include <saga/saga/attribute.hpp> 00011 #include <saga/saga/context.hpp> 00012 #include <saga/saga/adaptors/attribute.hpp> 00013 #include <saga/saga/adaptors/attribute_cpi_wrapper.hpp> 00014 00015 #include <saga/impl/exception.hpp> 00016 #include <saga/impl/engine/object.hpp> 00017 #include <saga/impl/engine/attribute.hpp> 00018 #include <saga/impl/engine/metric.hpp> 00019 #include <saga/impl/engine/context_base.hpp> 00020 #include <saga/impl/engine/proxy.hpp> 00021 00022 #include <saga/saga/detail/attribute_impl.hpp> 00023 00025 namespace saga { namespace adaptors { 00026 00027 attribute::attribute (saga::object rhs) 00028 : impl_(rhs.get_impl()), 00029 attr_(rhs.get_impl()->get_attributes()), 00030 must_delete(false) 00031 { 00032 } 00033 00034 attribute::attribute (saga::impl::object const* rhs) 00035 : impl_(const_cast<saga::impl::object*>(rhs)), 00036 attr_(impl_->get_attributes()), 00037 must_delete(false) 00038 { 00039 } 00040 00041 attribute::attribute (saga::impl::v1_0::attribute_cpi *cpi_instance) 00042 : impl_(cpi_instance->get_proxy()), 00043 attr_(new attribute_cpi_wrapper(cpi_instance)), 00044 must_delete(true) 00045 { 00046 } 00047 00048 attribute::attribute (saga::impl::v1_0::attribute_cpi const* cpi_instance) 00049 : impl_(cpi_instance->get_proxy()), 00050 attr_(new const_attribute_cpi_wrapper(cpi_instance)), 00051 must_delete(true) 00052 { 00053 } 00054 00055 attribute::~attribute (void) 00056 { 00057 if (must_delete) 00058 delete attr_; 00059 } 00060 00062 struct set_attribute_priv 00063 { 00064 template <typename Derived> 00065 static saga::task 00066 call (Derived& this_, 00067 std::string const& key, std::string const& val, bool sync) 00068 { 00069 return this_.get_attr()->set_attribute (key, val, sync); 00070 } 00071 }; 00072 00073 template <typename Tag> 00074 inline saga::task 00075 attribute::set_attributepriv ( 00076 std::string const& key, std::string const& val, Tag) 00077 { 00078 return detail::dispatch_priv<Tag>:: 00079 template call<set_attribute_priv>(derived(), key, val); 00080 } 00081 00082 void attribute::set_attribute_sync(std::string const& key, 00083 std::string const& val) 00084 { 00085 derived().get_attr()->set_attribute_sync(key, val); 00086 } 00087 00088 template saga::task 00089 attribute::set_attributepriv<saga::task_base::Sync>( 00090 std::string const& key, std::string const& val, saga::task_base::Sync); 00091 template saga::task 00092 attribute::set_attributepriv<saga::task_base::Async>( 00093 std::string const& key, std::string const& val, saga::task_base::Async); 00094 template saga::task 00095 attribute::set_attributepriv<saga::task_base::Task>( 00096 std::string const& key, std::string const& val, saga::task_base::Task); 00097 00099 struct set_vector_attribute_priv 00100 { 00101 template <typename Derived> 00102 static saga::task 00103 call (Derived& this_, std::string const& key, 00104 typename attribute::strvec_type const& val, bool sync) 00105 { 00106 return this_.get_attr()->set_vector_attribute (key, val, sync); 00107 } 00108 }; 00109 00110 template <typename Tag> 00111 inline saga::task 00112 attribute::set_vector_attributepriv ( 00113 std::string const& key, strvec_type const& val, Tag) 00114 { 00115 return detail::dispatch_priv<Tag>:: 00116 template call<set_vector_attribute_priv>(derived(), key, val); 00117 } 00118 00119 void attribute::set_vector_attribute_sync(std::string const& key, 00120 strvec_type const& val) 00121 { 00122 derived().get_attr()->set_vector_attribute_sync(key, val); 00123 } 00124 00125 template saga::task 00126 attribute::set_vector_attributepriv<saga::task_base::Sync>( 00127 std::string const& key, strvec_type const& val, saga::task_base::Sync); 00128 template saga::task 00129 attribute::set_vector_attributepriv<saga::task_base::Async>( 00130 std::string const& key, strvec_type const& val, saga::task_base::Async); 00131 template saga::task 00132 attribute::set_vector_attributepriv<saga::task_base::Task>( 00133 std::string const& key, strvec_type const& val, saga::task_base::Task); 00134 00136 struct remove_attribute_priv 00137 { 00138 template <typename Derived> 00139 static saga::task 00140 call (Derived& this_, std::string const& key, bool sync) 00141 { 00142 if (!this_.attribute_exists(key)) 00143 { 00144 // DoesNotExist 00145 typedef typename Derived::implementation_base_type base_type; 00146 SAGA_THROW_VERBATIM(this_.template get_target_object<base_type>(), 00147 "attribute '" + key + "' does not exist", 00148 saga::DoesNotExist); 00149 } 00150 return this_.get_attr()->remove_attribute(key, sync); 00151 } 00152 }; 00153 00154 template <typename Tag> 00155 inline saga::task 00156 attribute::remove_attributepriv (std::string const& key, Tag) 00157 { 00158 return detail::dispatch_priv<Tag>:: 00159 template call<remove_attribute_priv>(derived(), key); 00160 } 00161 00162 void attribute::remove_attribute_sync(std::string const& key) 00163 { 00164 derived().get_attr()->remove_attribute_sync(key); 00165 } 00166 00167 template saga::task 00168 attribute::remove_attributepriv<saga::task_base::Sync>( 00169 std::string const& key, saga::task_base::Sync); 00170 template saga::task 00171 attribute::remove_attributepriv<saga::task_base::Async>( 00172 std::string const& key, saga::task_base::Async); 00173 template saga::task 00174 attribute::remove_attributepriv<saga::task_base::Task>( 00175 std::string const& key, saga::task_base::Task); 00176 00177 } // namespace adaptors 00178 00180 // implement the attribute functions (we need to explicitly specialize 00181 // the template because the functions are not implemented inline) 00182 template struct SAGA_EXPORT_REPEAT saga::detail::attribute <adaptors::attribute>; 00183 00184 template struct SAGA_EXPORT saga::detail::attribute_priv<adaptors::attribute, saga::task_base::Sync>; 00185 template struct SAGA_EXPORT saga::detail::attribute_priv<adaptors::attribute, saga::task_base::Async>; 00186 template struct SAGA_EXPORT saga::detail::attribute_priv<adaptors::attribute, saga::task_base::Task>; 00187 00188 template struct SAGA_EXPORT saga::detail::attribute_sync<adaptors::attribute>; 00189 00191 } // namespace saga 00192