• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_COMPONENT_FWD_H
17 #define SCENE_EXT_COMPONENT_FWD_H
18 
19 #include <scene/base/namespace.h>
20 #include <scene/ext/ecs_lazy_property_fwd.h>
21 #include <scene/ext/intf_component.h>
22 #include <scene/ext/scene_property.h>
23 
SCENE_BEGIN_NAMESPACE()24 SCENE_BEGIN_NAMESPACE()
25 
26 class ComponentFwd : public META_NS::IntroduceInterfaces<EcsLazyPropertyFwd, IComponent> {
27 public:
28     bool PopulateAllProperties() override
29     {
30         return this->object_->AddAllEngineProperties(this->template GetSelf<META_NS::IMetadata>(), this->GetName())
31             .GetResult();
32     }
33 };
34 
GetComponentProperty(const META_NS::IAttach * obj,BASE_NS::string_view component,BASE_NS::string_view name)35 inline META_NS::IProperty::ConstPtr GetComponentProperty(
36     const META_NS::IAttach* obj, BASE_NS::string_view component, BASE_NS::string_view name)
37 {
38     if (auto c = obj->GetAttachmentContainer(true)->FindByName(component)) {
39         if (auto m = interface_cast<META_NS::IMetadata>(c)) {
40             return m->GetProperty(name);
41         }
42     }
43     return nullptr;
44 }
45 
GetComponentProperty(META_NS::IAttach * obj,BASE_NS::string_view component,BASE_NS::string_view name)46 inline META_NS::IProperty::Ptr GetComponentProperty(
47     META_NS::IAttach* obj, BASE_NS::string_view component, BASE_NS::string_view name)
48 {
49     if (auto c = obj->GetAttachmentContainer(true)->FindByName(component)) {
50         if (auto m = interface_cast<META_NS::IMetadata>(c)) {
51             return m->GetProperty(name);
52         }
53     }
54     return nullptr;
55 }
56 
57 #define SCENE_USE_READONLY_COMPONENT_PROPERTY(type, name, component)        \
58     ::META_NS::IProperty::ConstPtr Property##name() const noexcept override \
59     {                                                                       \
60         return GetComponentProperty(this, component, #name);                \
61     }
62 
63 #define SCENE_USE_COMPONENT_PROPERTY(type, name, component)      \
64     SCENE_USE_READONLY_COMPONENT_PROPERTY(type, name, component) \
65     ::META_NS::IProperty::Ptr Property##name() noexcept override \
66     {                                                            \
67         return GetComponentProperty(this, component, #name);     \
68     }
69 
70 // the type is not used, so just forward for now
71 #define SCENE_USE_ARRAY_COMPONENT_PROPERTY(type, name, component) SCENE_USE_COMPONENT_PROPERTY(type, name, component)
72 
73 #define SCENE_USE_READONLY_ARRAY_COMPONENT_PROPERTY(type, name, component) \
74     SCENE_USE_READONLY_COMPONENT_PROPERTY(type, name, component)
75 
76 SCENE_END_NAMESPACE()
77 
78 #endif