3 #include "executor.h"
\r
7 #include <boost/noncopyable.hpp>
\r
9 #include <functional>
\r
13 template<typename T>
\r
14 class com_context : public executor
\r
16 std::unique_ptr<T> instance_;
\r
18 com_context(const std::wstring& name) : executor(name)
\r
20 executor::begin_invoke([]
\r
22 ::CoInitialize(nullptr);
\r
28 executor::invoke([&]
\r
30 instance_.reset(nullptr);
\r
35 void reset(const std::function<T*()>& factory = nullptr)
\r
37 executor::invoke([&]
\r
41 instance_.reset(factory());
\r
45 T& operator*() const { return *instance_.get();} // noexcept
\r
47 T* operator->() const { return instance_.get();} // noexcept
\r
49 T* get() const { return instance_.get();} // noexcept
\r
51 operator bool() const {return get() != nullptr;}
\r