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 SCENE_EXT_SCENE_PROPERTY_H
17 #define SCENE_EXT_SCENE_PROPERTY_H
18
19 #include <scene/base/namespace.h>
20 #include <scene/ext/intf_engine_property_init.h>
21
22 #include <meta/ext/implementation_macros.h>
23
SCENE_BEGIN_NAMESPACE()24 SCENE_BEGIN_NAMESPACE()
25
26 template<typename Type, bool IsDynamic>
27 META_NS::Internal::MetadataCtor* CreateScenePropertyCtor()
28 {
29 return [](const BASE_NS::shared_ptr<META_NS::IOwner>& owner, const META_NS::StaticMetadata& d) {
30 auto prop = META_NS::CreatePropertyImpl<Type>(d.name, d.runtimeValue,
31 META_NS::ObjectFlagBitsValue(META_NS::ObjectFlagBits::SERIALIZE | META_NS::ObjectFlagBits::NATIVE));
32 if (prop) {
33 if (auto engOwner = interface_cast<IEnginePropertyInit>(owner)) {
34 const char* component = static_cast<const char*>(d.data);
35 if constexpr (IsDynamic) {
36 if (!engOwner->InitDynamicProperty(prop, component)) {
37 CORE_LOG_E("Failed to attach to engine property %s [%s]", d.name, component);
38 }
39 } else {
40 if (!engOwner->AttachEngineProperty(prop, component)) {
41 CORE_LOG_E("Failed to attach to engine property %s [%s]", d.name, component);
42 }
43 }
44 }
45 }
46 return interface_pointer_cast<CORE_NS::IInterface>(prop);
47 };
48 }
49
50 //--- PROPERTY DATA
51 #define SCENE_IMPL_PROPERTY_DATA(intf, type, name, ppath, dynamic) \
52 { META_NS::MetadataType::PROPERTY, intf::INTERFACE_INFO, #name, \
53 SCENE_NS::CreateScenePropertyCtor<type, dynamic>(), [] { return META_NS::ConstructAnyHelper<type>({}); }, \
54 ppath, META_NS::GetPropertySMDFlags(&intf::Property##name, 0) },
55
56 #define SCENE_STATIC_PROPERTY_DATA(intf, type, name, ppath) SCENE_IMPL_PROPERTY_DATA(intf, type, name, ppath, false)
57 #define SCENE_STATIC_DYNINIT_PROPERTY_DATA(intf, type, name, ppath) \
58 SCENE_IMPL_PROPERTY_DATA(intf, type, name, ppath, true)
59 //---
60
61 //--- ARRAY PROPERTY DATA
62 #define SCENE_IMPL_ARRAY_PROPERTY_DATA(intf, type, name, ppath, dynamic) \
63 { META_NS::MetadataType::PROPERTY, intf::INTERFACE_INFO, #name, \
64 SCENE_NS::CreateScenePropertyCtor<type[], dynamic>(), \
65 [] { return META_NS::IAny::Ptr(META_NS::ConstructArrayAnyHelper<type>({})); }, ppath, \
66 META_NS::GetPropertySMDFlags(&intf::Property##name, 0) },
67
68 #define SCENE_STATIC_ARRAY_PROPERTY_DATA(intf, type, name, ppath) \
69 SCENE_IMPL_ARRAY_PROPERTY_DATA(intf, type, name, ppath, false)
70 #define SCENE_STATIC_DYNINIT_ARRAY_PROPERTY_DATA(intf, type, name, ppath) \
71 SCENE_IMPL_ARRAY_PROPERTY_DATA(intf, type, name, ppath, true)
72 //---
73
74 SCENE_END_NAMESPACE()
75
76 #endif