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