Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<class T>
- class proxy
- {
- public:
- proxy(T &obj)
- m_obj(obj)
- {
- }
- template<typename fn, typename rt, typename ...arg_types>
- rt do_sync(arg_types ...args)
- {
- rt return_var;
- obj->*fn(std::forward<arg_types>(args)..., [this, return_var]
- (cb_arg)
- {
- return_var = cb_arg;
- m_cv.notify();
- });
- m_cv.wait();
- return return_var;
- }
- private:
- T &m_obj;
- std::condition_variable m_cv;
- };
- // Usage example
- class gameserver
- {
- public:
- game::map_list get_map_list(int offset, int count)
- {
- proxy<gameserver> gs_proxy(*this);
- return gs_proxy.do_sync<gameserver::get_map_list_async>(offset, count);
- }
- void get_map_list_async(int offset, int count, void(cb*)(const game::map_list &map_list))
- {
- // Impl
- }
- private:
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement