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 // include spec sections 00007 #include <boost/assign/list_of.hpp> 00008 #include <boost/assign/list_inserter.hpp> // boost::assign::insert() 00009 #include <boost/assign/std/vector.hpp> 00010 00011 #include <saga/saga/adaptors/metric.hpp> 00012 #include <saga/impl/engine/metric.hpp> 00013 #include <saga/impl/engine/context_base.hpp> 00014 00015 #include <saga/saga/detail/attribute_impl.hpp> 00016 00018 namespace saga { namespace adaptors 00019 { 00020 // delegate all action to the implementation 00021 metric::metric() 00022 : saga::object (new saga::impl::metric ()) 00023 { 00024 } 00025 00026 metric::~metric () 00027 { 00028 } 00029 00031 metric::metric (saga::object const& o) 00032 : saga::object (o) 00033 { 00034 if (this->get_type() != saga::object::Metric) 00035 { 00036 SAGA_THROW("Bad type conversion.", saga::BadParameter); 00037 } 00038 } 00039 00040 metric &metric::operator= (saga::object const& o) 00041 { 00042 saga::object::operator=(o); 00043 if (this->get_type() != saga::object::Metric) 00044 { 00045 SAGA_THROW("Bad type conversion.", saga::BadParameter); 00046 } 00047 return *this; 00048 } 00049 00051 metric::metric (saga::metric const& m) 00052 : saga::object (m) 00053 { 00054 } 00055 00056 metric &metric::operator= (saga::metric const& m) 00057 { 00058 saga::object::operator=(m); 00059 return *this; 00060 } 00061 00063 saga::impl::metric* metric::get_impl (void) const 00064 { 00065 typedef saga::object base_type; 00066 return static_cast<saga::impl::metric*>(this->base_type::get_impl()); 00067 } 00068 00069 TR1::shared_ptr<saga::impl::metric> metric::get_impl_sp (void) const 00070 { 00071 typedef saga::object base_type; 00072 return TR1::static_pointer_cast<saga::impl::metric>( 00073 this->base_type::get_impl_sp()); 00074 } 00075 00076 saga::impl::attribute_interface* metric::get_attr() const 00077 { 00078 return get_impl()->get_attributes(); 00079 } 00080 00082 bool operator== (metric const& lhs, metric const& rhs) 00083 { 00084 return (lhs.get_impl() == rhs.get_impl()); 00085 } 00086 00087 metric::metric_cookie 00088 metric::add_callback(saga::callback f) 00089 { 00090 return get_impl()->add_callback(f); 00091 } 00092 00093 void metric::remove_callback(metric_cookie cookie) 00094 { 00095 get_impl()->remove_callback(cookie); 00096 } 00097 00098 void metric::fire (saga::context ctx) 00099 { 00100 get_impl()->fire (ctx); 00101 } 00102 00104 struct set_attribute_priv 00105 { 00106 template <typename Derived> 00107 static saga::task 00108 call (Derived& this_, 00109 std::string const& key, std::string const& val, bool sync) 00110 { 00111 return this_.get_attr()->set_attribute (key, val, sync); 00112 } 00113 }; 00114 00115 template <typename Tag> 00116 inline saga::task 00117 metric::set_attributepriv (std::string const& key, 00118 std::string const& val, Tag) 00119 { 00120 return detail::dispatch_priv<Tag>:: 00121 template call<set_attribute_priv>(derived(), key, val); 00122 } 00123 00124 template saga::task 00125 metric::set_attributepriv<saga::task_base::Sync>( 00126 std::string const& key, std::string const& val, saga::task_base::Sync); 00127 template saga::task 00128 metric::set_attributepriv<saga::task_base::Async>( 00129 std::string const& key, std::string const& val, saga::task_base::Async); 00130 template saga::task 00131 metric::set_attributepriv<saga::task_base::Task>( 00132 std::string const& key, std::string const& val, saga::task_base::Task); 00133 00135 struct set_vector_attribute_priv 00136 { 00137 template <typename Derived> 00138 static saga::task 00139 call (Derived& this_, std::string const& key, 00140 typename metric::strvec_type const& val, bool sync) 00141 { 00142 return this_.get_attr()->set_vector_attribute (key, val, sync); 00143 } 00144 }; 00145 00146 template <typename Tag> 00147 inline saga::task 00148 metric::set_vector_attributepriv ( 00149 std::string const& key, strvec_type const& val, Tag) 00150 { 00151 return detail::dispatch_priv<Tag>:: 00152 template call<set_vector_attribute_priv>(derived(), key, val); 00153 } 00154 00155 template saga::task 00156 metric::set_vector_attributepriv<saga::task_base::Sync>( 00157 std::string const& key, strvec_type const& val, saga::task_base::Sync); 00158 template saga::task 00159 metric::set_vector_attributepriv<saga::task_base::Async>( 00160 std::string const& key, strvec_type const& val, saga::task_base::Async); 00161 template saga::task 00162 metric::set_vector_attributepriv<saga::task_base::Task>( 00163 std::string const& key, strvec_type const& val, saga::task_base::Task); 00164 00166 struct remove_attribute_priv 00167 { 00168 template <typename Derived> 00169 static saga::task 00170 call (Derived& this_, std::string const& key, bool sync) 00171 { 00172 if (!this_.attribute_exists(key)) 00173 { 00174 // DoesNotExist 00175 typedef typename Derived::implementation_base_type base_type; 00176 SAGA_THROW_VERBATIM(this_.template get_target_object<base_type>(), 00177 "attribute '" + key + "' does not exist", 00178 saga::DoesNotExist); 00179 } 00180 return this_.get_attr()->remove_attribute(key, sync); 00181 } 00182 }; 00183 00184 template <typename Tag> 00185 inline saga::task 00186 metric::remove_attributepriv (std::string const& key, Tag) 00187 { 00188 return detail::dispatch_priv<Tag>:: 00189 template call<remove_attribute_priv>(derived(), key); 00190 } 00191 00192 template saga::task 00193 metric::remove_attributepriv<saga::task_base::Sync>( 00194 std::string const& key, saga::task_base::Sync); 00195 template saga::task 00196 metric::remove_attributepriv<saga::task_base::Async>( 00197 std::string const& key, saga::task_base::Async); 00198 template saga::task 00199 metric::remove_attributepriv<saga::task_base::Task>( 00200 std::string const& key, saga::task_base::Task); 00201 00202 } // namespace adaptors 00203 00205 // implement the attribute functions (we need to explicitly specialize 00206 // the template because the functions are not implemented inline) 00207 template struct SAGA_EXPORT_REPEAT saga::detail::attribute<adaptors::metric>; 00208 00209 template struct SAGA_EXPORT saga::detail::attribute_priv<adaptors::metric, saga::task_base::Sync>; 00210 template struct SAGA_EXPORT saga::detail::attribute_priv<adaptors::metric, saga::task_base::Async>; 00211 template struct SAGA_EXPORT saga::detail::attribute_priv<adaptors::metric, saga::task_base::Task>; 00212 00213 template struct SAGA_EXPORT saga::detail::attribute_sync<adaptors::metric>; 00214 00216 } // namespace saga 00217