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_INTERFACE_MACROS_H 17 #define META_INTERFACE_INTERFACE_MACROS_H 18 19 #include <meta/base/namespace.h> 20 #include <meta/base/shared_ptr.h> 21 #include <meta/interface/event.h> 22 #include <meta/interface/property/array_property.h> 23 #include <meta/interface/property/property.h> 24 25 #define META_READONLY_PROPERTY_TYPED_IMPL(type, name) \ 26 META_NS::ConstProperty<type> name() const noexcept \ 27 { \ 28 return META_NS::ConstProperty<type> { this->Property##name() }; \ 29 } 30 31 #define META_PROPERTY_TYPED_IMPL(type, name) \ 32 META_NS::Property<type> name() noexcept \ 33 { \ 34 return META_NS::Property<type> { this->Property##name() }; \ 35 } 36 37 #define META_EVENT_TYPED_IMPL(type, name) \ 38 ::META_NS::Event<type> name() const \ 39 { \ 40 return Event##name(); \ 41 } 42 43 /** 44 * @brief Define read-only property with given type and name. 45 * Creates only const version. 46 */ 47 #define META_READONLY_PROPERTY(type, name) \ 48 virtual BASE_NS::shared_ptr<const META_NS::IProperty> Property##name() const = 0; \ 49 META_READONLY_PROPERTY_TYPED_IMPL(type, name) 50 51 /** 52 * @brief Define property with given type and name. 53 * Creates overloads for const and non-const versions. 54 */ 55 #define META_PROPERTY(type, name) \ 56 META_READONLY_PROPERTY(type, name) \ 57 virtual BASE_NS::shared_ptr<META_NS::IProperty> Property##name() = 0; \ 58 META_PROPERTY_TYPED_IMPL(type, name) 59 60 #define META_READONLY_ARRAY_PROPERTY_TYPED_IMPL(type, name) \ 61 META_NS::ConstArrayProperty<type> name() const noexcept \ 62 { \ 63 return META_NS::ConstArrayProperty<type> { this->Property##name() }; \ 64 } 65 66 #define META_ARRAY_PROPERTY_TYPED_IMPL(type, name) \ 67 META_NS::ArrayProperty<type> name() noexcept \ 68 { \ 69 return META_NS::ArrayProperty<type> { this->Property##name() }; \ 70 } 71 72 /** 73 * @brief Define read-only property with given type and name. 74 * Creates only const version. 75 */ 76 #define META_READONLY_ARRAY_PROPERTY(type, name) \ 77 virtual BASE_NS::shared_ptr<const META_NS::IProperty> Property##name() const = 0; \ 78 META_READONLY_ARRAY_PROPERTY_TYPED_IMPL(type, name) 79 80 /** 81 * @brief Define property with given type and name. 82 * Creates overloads for const and non-const versions. 83 */ 84 #define META_ARRAY_PROPERTY(type, name) \ 85 META_READONLY_ARRAY_PROPERTY(type, name) \ 86 virtual BASE_NS::shared_ptr<META_NS::IProperty> Property##name() = 0; \ 87 META_ARRAY_PROPERTY_TYPED_IMPL(type, name) 88 89 /** 90 * @brief Define event with given type and name. 91 */ 92 #define META_EVENT(type, name) \ 93 virtual ::BASE_NS::shared_ptr<::META_NS::IEvent> Event##name() const = 0; \ 94 META_EVENT_TYPED_IMPL(type, name) 95 96 #endif 97