]> git.sesse.net Git - casparcg/blobdiff - core/monitor/monitor.h
set svn:eol-style native on .h and .cpp files
[casparcg] / core / monitor / monitor.h
index 6c9f54b197f9d5ac2d9868f34f7c7626ca819665..ba6d7af282b703fe494c5db07c12cdfd388c8a19 100644 (file)
-#pragma once\r
-\r
-#include <common/reactive.h>\r
-\r
-#include <functional>\r
-#include <memory>\r
-#include <ostream>\r
-#include <string>\r
-#include <type_traits>\r
-#include <vector>\r
-\r
-#include <boost/variant.hpp>\r
-#include <boost/lexical_cast.hpp>\r
-#include <boost/chrono.hpp>\r
-\r
-#include <tbb/cache_aligned_allocator.h>\r
-\r
-namespace boost {\r
-namespace detail { namespace variant {\r
-\r
-template <>\r
-struct has_nothrow_move<std::string>\r
-: mpl::true_\r
-{\r
-};\r
-  \r
-template <>\r
-struct has_nothrow_move<std::vector<int8_t>>\r
-: mpl::true_\r
-{\r
-};\r
-\r
-template <>\r
-struct has_nothrow_move<boost::chrono::duration<double, boost::ratio<1, 1>>>\r
-: mpl::true_\r
-{\r
-};\r
-\r
-}}}\r
-\r
-namespace caspar { namespace monitor {\r
-       \r
-// path\r
-\r
-class path sealed\r
-{\r
-public:        \r
-\r
-       // Static Members\r
-\r
-       // Constructors\r
-\r
-       path();         \r
-       path(const char* path);\r
-       path(std::string path);\r
-\r
-       path(const path& other);        \r
-       path(path&& other);\r
-               \r
-       // Methods\r
-\r
-       path& operator=(path other);\r
-       path& operator%=(path other);\r
-\r
-       template<typename T>\r
-       typename std::enable_if<!std::is_same<typename std::decay<T>::type, path>::value, path&>::type operator%=(T&& value)\r
-       {\r
-               auto str = boost::lexical_cast<std::string>(std::forward<T>(value));\r
-\r
-               if(!str.empty())\r
-                       str_ += (str.front() != '/' ? "/" : "") + std::move(str);\r
-\r
-               return *this;\r
-       }\r
-       \r
-       path& operator%=(const char* value)\r
-       {\r
-               return *this %= std::string(value);\r
-       }\r
-\r
-       void swap(path& other);\r
-\r
-       // Properties\r
-\r
-       const std::string& str() const; \r
-       bool empty() const;\r
-private:\r
-       std::string str_;\r
-};\r
-\r
-template<typename T>\r
-path operator%(path path, T&& value)\r
-{      \r
-       return std::move(path %= std::forward<T>(value));\r
-}\r
-\r
-std::ostream& operator<<(std::ostream& o, const path& p);\r
-\r
-// param\r
-\r
-typedef boost::chrono::duration<double, boost::ratio<1, 1>> duration;\r
-\r
-typedef boost::variant<bool, int32_t, int64_t, float, double, std::string, std::wstring, std::vector<int8_t>, duration> param;\r
-\r
-std::ostream& operator<<(std::ostream& o, const param& p);\r
-\r
-// event\r
-\r
-class event sealed\r
-{      \r
-public:        \r
-       \r
-       // Static Members\r
-\r
-       typedef std::vector<param, tbb::cache_aligned_allocator<param>> params_t;\r
-\r
-       // Constructors\r
-\r
-       event(path path);       \r
-       event(path path, params_t params);                                      \r
-       event(const event& other);\r
-       event(event&& other);\r
-\r
-       // Methods\r
-\r
-       event& operator=(event other);\r
-\r
-       void swap(event& other);\r
-               \r
-       template<typename T>\r
-       event& operator%(T&& value)\r
-       {\r
-               params_.push_back(std::forward<T>(value));\r
-               return *this;\r
-       }\r
-       \r
-       event propagate(path path) const;\r
-\r
-       // Properties\r
-\r
-       const path&             path() const;\r
-       const params_t& params() const;\r
-private:\r
-       monitor::path   path_;\r
-       params_t                params_;\r
-};\r
-\r
-std::ostream& operator<<(std::ostream& o, const event& e);\r
-\r
-// reactive\r
-\r
-typedef reactive::observable<monitor::event>   observable;\r
-typedef reactive::observer<monitor::event>             observer;\r
-typedef reactive::subject<monitor::event>              subject;\r
-       \r
-class basic_subject sealed : public reactive::subject<monitor::event>\r
-{          \r
-       basic_subject(const basic_subject&);\r
-       basic_subject& operator=(const basic_subject&);\r
-       \r
-       class impl : public observer\r
-       {\r
-       public:\r
-               impl(monitor::path path = monitor::path())\r
-                       : impl_()\r
-                       , path_(std::move(path))\r
-               {\r
-               }\r
-\r
-               impl(impl&& other)\r
-                       : impl_(std::move(other.impl_))\r
-                       , path_(std::move(other.path_))\r
-               {               \r
-               }\r
-\r
-               impl& operator=(impl&& other)\r
-               {\r
-                       impl_ = std::move(other.impl_);         \r
-                       path_ = std::move(other.path_);\r
-               }\r
-                                                       \r
-               void on_next(const monitor::event& e) override\r
-               {                               \r
-                       impl_.on_next(path_.empty() ? e : e.propagate(path_));\r
-               }\r
-\r
-               void subscribe(const observer_ptr& o)\r
-               {                               \r
-                       impl_.subscribe(o);\r
-               }\r
-\r
-               void unsubscribe(const observer_ptr& o)\r
-               {\r
-                       impl_.unsubscribe(o);\r
-               }\r
-                               \r
-       private:\r
-               reactive::basic_subject_impl<monitor::event>    impl_;          \r
-               monitor::path                                                                   path_;\r
-       };\r
-\r
-public:                \r
-\r
-       // Static Members\r
-\r
-       // Constructors\r
-\r
-       basic_subject(monitor::path path = monitor::path())\r
-               : impl_(std::make_shared<impl>(std::move(path)))\r
-\r
-       {\r
-       }\r
-               \r
-       basic_subject(basic_subject&& other)\r
-               : impl_(std::move(other.impl_))\r
-       {\r
-       }\r
-       \r
-       // Methods\r
-\r
-       basic_subject& operator=(basic_subject&& other)\r
-       {\r
-               impl_ = std::move(other.impl_);\r
-       }\r
-\r
-       operator std::weak_ptr<observer>()\r
-       {\r
-               return impl_;\r
-       }\r
-\r
-       // observable\r
-       \r
-       void subscribe(const observer_ptr& o) override\r
-       {                               \r
-               impl_->subscribe(o);\r
-       }\r
-\r
-       void unsubscribe(const observer_ptr& o) override\r
-       {\r
-               impl_->unsubscribe(o);\r
-       }\r
-\r
-       // observer\r
-                               \r
-       void on_next(const monitor::event& e) override\r
-       {                               \r
-               impl_->on_next(e);\r
-       }\r
-\r
-       // Properties\r
-\r
-private:\r
-       std::shared_ptr<impl> impl_;\r
-};\r
-\r
-inline subject& operator<<(subject& s, const event& e)\r
-{\r
-       s.on_next(e);\r
-       return s;\r
-}\r
-\r
+#pragma once
+
+#include <common/reactive.h>
+
+#include <functional>
+#include <memory>
+#include <ostream>
+#include <string>
+#include <type_traits>
+#include <vector>
+
+#include <boost/variant.hpp>
+#include <boost/lexical_cast.hpp>
+#include <boost/chrono.hpp>
+
+#include <tbb/cache_aligned_allocator.h>
+
+namespace boost {
+namespace detail { namespace variant {
+
+template <>
+struct has_nothrow_move<std::string>
+: mpl::true_
+{
+};
+  
+template <>
+struct has_nothrow_move<std::vector<int8_t>>
+: mpl::true_
+{
+};
+
+template <>
+struct has_nothrow_move<boost::chrono::duration<double, boost::ratio<1, 1>>>
+: mpl::true_
+{
+};
+
+}}}
+
+namespace caspar { namespace monitor {
+       
+// path
+
+class path sealed
+{
+public:        
+
+       // Static Members
+
+       // Constructors
+
+       path();         
+       path(const char* path);
+       path(std::string path);
+
+       path(const path& other);        
+       path(path&& other);
+               
+       // Methods
+
+       path& operator=(path other);
+       path& operator%=(path other);
+
+       template<typename T>
+       typename std::enable_if<!std::is_same<typename std::decay<T>::type, path>::value, path&>::type operator%=(T&& value)
+       {
+               auto str = boost::lexical_cast<std::string>(std::forward<T>(value));
+
+               if(!str.empty())
+                       str_ += (str.front() != '/' ? "/" : "") + std::move(str);
+
+               return *this;
+       }
+       
+       path& operator%=(const char* value)
+       {
+               return *this %= std::string(value);
+       }
+
+       void swap(path& other);
+
+       // Properties
+
+       const std::string& str() const; 
+       bool empty() const;
+private:
+       std::string str_;
+};
+
+template<typename T>
+path operator%(path path, T&& value)
+{      
+       return std::move(path %= std::forward<T>(value));
+}
+
+std::ostream& operator<<(std::ostream& o, const path& p);
+
+// param
+
+typedef boost::chrono::duration<double, boost::ratio<1, 1>> duration;
+
+typedef boost::variant<bool, int32_t, int64_t, float, double, std::string, std::wstring, std::vector<int8_t>, duration> param;
+
+std::ostream& operator<<(std::ostream& o, const param& p);
+
+// event
+
+class event sealed
+{      
+public:        
+       
+       // Static Members
+
+       typedef std::vector<param, tbb::cache_aligned_allocator<param>> params_t;
+
+       // Constructors
+
+       event(path path);       
+       event(path path, params_t params);                                      
+       event(const event& other);
+       event(event&& other);
+
+       // Methods
+
+       event& operator=(event other);
+
+       void swap(event& other);
+               
+       template<typename T>
+       event& operator%(T&& value)
+       {
+               params_.push_back(std::forward<T>(value));
+               return *this;
+       }
+       
+       event propagate(path path) const;
+
+       // Properties
+
+       const path&             path() const;
+       const params_t& params() const;
+private:
+       monitor::path   path_;
+       params_t                params_;
+};
+
+std::ostream& operator<<(std::ostream& o, const event& e);
+
+// reactive
+
+typedef reactive::observable<monitor::event>   observable;
+typedef reactive::observer<monitor::event>             observer;
+typedef reactive::subject<monitor::event>              subject;
+       
+class basic_subject sealed : public reactive::subject<monitor::event>
+{          
+       basic_subject(const basic_subject&);
+       basic_subject& operator=(const basic_subject&);
+       
+       class impl : public observer
+       {
+       public:
+               impl(monitor::path path = monitor::path())
+                       : impl_()
+                       , path_(std::move(path))
+               {
+               }
+
+               impl(impl&& other)
+                       : impl_(std::move(other.impl_))
+                       , path_(std::move(other.path_))
+               {               
+               }
+
+               impl& operator=(impl&& other)
+               {
+                       impl_ = std::move(other.impl_);         
+                       path_ = std::move(other.path_);
+               }
+                                                       
+               void on_next(const monitor::event& e) override
+               {                               
+                       impl_.on_next(path_.empty() ? e : e.propagate(path_));
+               }
+
+               void subscribe(const observer_ptr& o)
+               {                               
+                       impl_.subscribe(o);
+               }
+
+               void unsubscribe(const observer_ptr& o)
+               {
+                       impl_.unsubscribe(o);
+               }
+                               
+       private:
+               reactive::basic_subject_impl<monitor::event>    impl_;          
+               monitor::path                                                                   path_;
+       };
+
+public:                
+
+       // Static Members
+
+       // Constructors
+
+       basic_subject(monitor::path path = monitor::path())
+               : impl_(std::make_shared<impl>(std::move(path)))
+
+       {
+       }
+               
+       basic_subject(basic_subject&& other)
+               : impl_(std::move(other.impl_))
+       {
+       }
+       
+       // Methods
+
+       basic_subject& operator=(basic_subject&& other)
+       {
+               impl_ = std::move(other.impl_);
+       }
+
+       operator std::weak_ptr<observer>()
+       {
+               return impl_;
+       }
+
+       // observable
+       
+       void subscribe(const observer_ptr& o) override
+       {                               
+               impl_->subscribe(o);
+       }
+
+       void unsubscribe(const observer_ptr& o) override
+       {
+               impl_->unsubscribe(o);
+       }
+
+       // observer
+                               
+       void on_next(const monitor::event& e) override
+       {                               
+               impl_->on_next(e);
+       }
+
+       // Properties
+
+private:
+       std::shared_ptr<impl> impl_;
+};
+
+inline subject& operator<<(subject& s, const event& e)
+{
+       s.on_next(e);
+       return s;
+}
+
 }}
\ No newline at end of file