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