SAGA Adaptor CPI v.1.0
|
00001 // Copyright (c) 2005-2009 Hartmut Kaiser 00002 // Copyright (c) 2007 Ole Weidner (oweidner@cct.lsu.edu) 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 #ifndef SAGA_ADAPTORS_METRIC_HPP 00008 #define SAGA_ADAPTORS_METRIC_HPP 00009 00010 // include stl 00011 #include <vector> 00012 #include <string> 00013 00014 // include dependent spec sections 00015 #include <saga/saga/util.hpp> 00016 #include <saga/saga/base.hpp> 00017 #include <saga/saga/metric.hpp> 00018 00019 // suppress warnings about dependent classes not being exported from the dll 00020 #if defined(BOOST_MSVC) 00021 #pragma warning(push) 00022 #pragma warning(disable : 4251 4231 4660) 00023 #endif 00024 00026 namespace saga { namespace adaptors { 00027 00029 // this is the same as the saga::metric class, except it is possible to 00030 // set read only metric values 00031 class SAGA_EXPORT metric 00032 : public saga::object, 00033 public saga::detail::attribute<metric> 00034 { 00035 protected: 00036 saga::impl::metric* get_impl (void) const; 00037 TR1::shared_ptr <saga::impl::metric> get_impl_sp (void) const; 00038 00039 friend struct saga::detail::attribute<metric>; // needs to access get_impl() 00040 friend class saga::impl::metric; 00041 00042 explicit metric(saga::impl::metric *impl); 00043 00044 public: 00045 typedef saga::metric::frequency frequency; 00046 typedef saga::monitorable::cookie_handle metric_cookie; 00047 00048 // ctor/dtor 00049 metric (); 00050 explicit metric (saga::object const& o); 00051 metric (saga::metric const& m); 00052 ~metric (); 00053 00054 // default operator=() and copy ctor are ok 00055 metric &operator= (saga::object const& o); 00056 metric &operator= (saga::metric const& m); 00057 00058 friend SAGA_EXPORT 00059 bool operator== (metric const& lhs, metric const& rhs); 00060 00061 // read-write metrics can update their values, read only metrics can't. 00062 // Updating means: setting new values via the attribute interface, and 00063 // calling 'fire' to push the current state to the implementation. 00064 void fire (saga::context ctx = saga::context()); 00065 00066 // on changes, a metric can be notified. 00067 metric_cookie add_callback (saga::callback f); 00068 void remove_callback (metric_cookie cookie); 00069 00070 public: 00071 // just defined for brevity 00072 typedef std::vector <std::string> strvec_type; 00073 typedef std::map <std::string, std::string> strmap_type; 00074 00075 private: 00076 friend struct saga::detail::attribute<attribute>; // needs to access get_impl() 00077 00078 template <typename Tag> 00079 saga::task set_attributepriv (std::string const&, std::string const&, Tag); 00080 template <typename Tag> 00081 saga::task set_vector_attributepriv(std::string const&, strvec_type const&, Tag); 00082 template <typename Tag> 00083 saga::task remove_attributepriv(std::string const&, Tag); 00084 00085 public: 00086 saga::impl::attribute_interface* get_attr() const; 00087 00092 void set_attribute(std::string key, std::string value) 00093 { 00094 set_attributepriv(key, value, saga::task_base::Sync()); 00095 } 00096 SAGA_CALL_PUB_2_DEF_0(set_attribute, std::string, std::string) 00097 00098 00102 void set_vector_attribute(std::string key, strvec_type value) 00103 { 00104 set_vector_attributepriv(key, value, saga::task_base::Sync()); 00105 } 00106 SAGA_CALL_PUB_2_DEF_0(set_vector_attribute, std::string, strvec_type) 00107 00108 00112 void remove_attribute(std::string key) 00113 { 00114 remove_attributepriv(key, saga::task_base::Sync()); 00115 } 00116 SAGA_CALL_PUB_1_DEF_0(remove_attribute, std::string) 00117 00118 }; 00119 00121 }} // namespace saga::adaptors 00122 00123 #if defined(BOOST_MSVC) 00124 #pragma warning(pop) 00125 #endif 00126 00127 #endif // SAGA_ADAPTORS_METRIC_HPP 00128