From 93494768f72c44414b861ba3ae9ff570f677027a Mon Sep 17 00:00:00 2001 From: wqking Date: Sat, 8 Dec 2018 08:49:55 +0800 Subject: [PATCH 01/38] Added class HeterEventDispatcher --- include/eventpp/hetereventdispatcher.h | 221 ++++++++++++++++++ tests/unittest/CMakeLists.txt | 1 + tests/unittest/test_heterdispatcher_basic.cpp | 43 ++++ 3 files changed, 265 insertions(+) create mode 100644 include/eventpp/hetereventdispatcher.h create mode 100644 tests/unittest/test_heterdispatcher_basic.cpp diff --git a/include/eventpp/hetereventdispatcher.h b/include/eventpp/hetereventdispatcher.h new file mode 100644 index 0000000..d7be967 --- /dev/null +++ b/include/eventpp/hetereventdispatcher.h @@ -0,0 +1,221 @@ +// eventpp library +// Copyright (C) 2018 Wang Qi (wqking) +// Github: https://github.com/wqking/eventpp +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef HETEREVENTDISPATCHER_H_127766658555 +#define HETEREVENTDISPATCHER_H_127766658555 + +#include "eventdispatcher.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace eventpp { + +template +struct PrototypeList +{ + enum { size = sizeof...(Types) }; +}; + +template +struct CanConvert +{ + enum { value = false }; +}; + +template +struct CanConvert , std::tuple > +{ + enum { value = std::is_convertible::value && CanConvert, std::tuple >::value }; +}; + +template <> +struct CanConvert , std::tuple<> > +{ + enum { value = true }; +}; + +template +struct FindCallablePrototypeHelper +{ + using Prototype = void; + enum {index = -1 }; +}; + +template +struct FindCallablePrototypeHelper , InArgs...> +{ + using Prototype = typename std::conditional< + CanConvert, std::tuple >::value, + RT (Args...), + typename FindCallablePrototypeHelper, InArgs...>::Prototype + >::type; + enum { + index = CanConvert, std::tuple >::value + ? N + : FindCallablePrototypeHelper, InArgs...>::index + }; +}; + +template +struct FindCallablePrototype : public FindCallablePrototypeHelper <0, PrototypeList_, InArgs...> +{ +}; + + + +namespace internal_ { + +template < + typename EventType, + typename PrototypeList_, + typename PoliciesType, + typename MixinRoot_ +> +class HeterEventDispatcherBase +{ +private: + template + class CallableInvoker + { + }; + + template + class CallableInvoker : public EventDispatcher + { + public: + private: + }; + +protected: + using ThisType = HeterEventDispatcherBase< + EventType, + PrototypeList_, + PoliciesType, + MixinRoot_ + >; + + using Policies = PoliciesType; + using Threading = typename SelectThreading::value>::Type; + + enum { prototypeCount = PrototypeList_::size }; + +public: + using Event = EventType; + using Mutex = typename Threading::Mutex; + +public: + HeterEventDispatcherBase() + { + } + + HeterEventDispatcherBase(const HeterEventDispatcherBase & other) + { + } + + HeterEventDispatcherBase(HeterEventDispatcherBase && other) noexcept + { + } + + HeterEventDispatcherBase & operator = (const HeterEventDispatcherBase & other) + { + } + + HeterEventDispatcherBase & operator = (HeterEventDispatcherBase && other) noexcept + { + } + + void swap(HeterEventDispatcherBase & other) noexcept { + using std::swap; + + //swap(eventCallbackListMap, other.eventCallbackListMap); + } + + friend void swap(HeterEventDispatcherBase & first, HeterEventDispatcherBase & second) noexcept { + first.swap(second); + } + + template