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_SIMPLE_EVENT_H 17 #define META_INTERFACE_SIMPLE_EVENT_H 18 19 #include <meta/base/meta_types.h> 20 #include <meta/interface/intf_event.h> 21 22 META_BEGIN_NAMESPACE() 23 24 /** 25 * @brief Helper class to define event types easily. 26 * Example: 27 * struct IOnEventInfo { 28 * constexpr static BASE_NS::Uid UID { "uid..." }; 29 * }; 30 * using IOnEvent = META_NS::SimpleEvent<IOnEventInfo, void(int myparameter)>; 31 * IOnEvent is event type that can be used with META(_IMPLEMENT)_EVENT macros. 32 */ 33 template<typename MyEvent, typename Signature = void()> 34 class SimpleEvent; 35 36 template<typename MyEvent, typename... Args> 37 class SimpleEvent<MyEvent, void(Args...)> : public IEventCallable<MyEvent, void, Args...> { 38 public: 39 constexpr static char const *NAME { MyEvent::NAME }; 40 }; 41 42 // NOLINTBEGIN(readability-identifier-naming) 43 /** 44 * @brief Check if type is an event. 45 */ 46 template<typename Type> 47 constexpr bool IsEvent_v = BASE_NS::is_convertible_v<const Type*, const IEvent*>; 48 // NOLINTEND(readability-identifier-naming) 49 50 META_END_NAMESPACE() 51 52 #endif 53