1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef META_INTERFACE_EVENT_H 17 #define META_INTERFACE_EVENT_H 18 19 #include <meta/base/namespace.h> 20 #include <meta/base/shared_ptr.h> 21 22 META_BEGIN_NAMESPACE() 23 class IEvent; 24 template<typename EventT> 25 class Event; 26 template<> 27 class Event<IEvent> { 28 public: 29 using EventType = IEvent; 30 Event(const BASE_NS::shared_ptr<IEvent> & ev)31 Event(const BASE_NS::shared_ptr<IEvent>& ev) : event_(ev) {} 32 33 BASE_NS::shared_ptr<IEvent> operator->() const 34 { 35 return event_; 36 } 37 IEvent& operator*() const 38 { 39 return *event_; 40 } shared_ptr()41 operator BASE_NS::shared_ptr<IEvent>() const 42 { 43 return event_; 44 } 45 46 private: 47 BASE_NS::shared_ptr<IEvent> event_; 48 }; 49 template<typename EventT> 50 class Event : public Event<IEvent> { 51 public: 52 using Event<IEvent>::Event; Event(const BASE_NS::shared_ptr<EventT> & ev)53 Event(const BASE_NS::shared_ptr<EventT>& ev) : Event<IEvent>(interface_pointer_cast<IEvent>(ev)) {} 54 }; 55 56 META_END_NAMESPACE() 57 58 #endif 59