• 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 META_EXT_OBJECT_CONTAINER_H
17 #define META_EXT_OBJECT_CONTAINER_H
18 
19 #include <meta/ext/object_fwd.h>
20 #include <meta/interface/interface_macros.h>
21 #include <meta/interface/intf_container.h>
22 #include <meta/interface/intf_required_interfaces.h>
23 
META_BEGIN_NAMESPACE()24 META_BEGIN_NAMESPACE()
25 
26 /**
27  * @brief A helper template class for implementing classes which implement the IContainer interface by
28  *        using ClassId::ObjectContainer as their base class.
29  */
30 
31 class CommonObjectContainerFwd : public IntroduceInterfaces<ObjectFwd, IContainer, IContainerProxyParent,
32                                      IRequiredInterfaces, ILockable, IIterable> {
33     META_OBJECT_NO_CLASSINFO(CommonObjectContainerFwd, IntroduceInterfaces, ClassId::ObjectContainer)
34 
35 protected:
36     void SetSuperInstance(const META_NS::IObject::Ptr& aggr, const META_NS::IObject::Ptr& super) override
37     {
38         Super::SetSuperInstance(aggr, super);
39         container_ = interface_cast<IContainer>(super);
40         CORE_ASSERT(container_);
41     }
42 
43 protected: // IContainer
44     BASE_NS::vector<IObject::Ptr> GetAll() const override
45     {
46         return container_->GetAll();
47     }
48     IContainer::SizeType GetSize() const override
49     {
50         return container_->GetSize();
51     }
52     BASE_NS::vector<IObject::Ptr> FindAll(const IContainer::FindOptions& options) const override
53     {
54         return container_->FindAll(options);
55     }
56     IObject::Ptr FindAny(const IContainer::FindOptions& options) const override
57     {
58         return container_->FindAny(options);
59     }
60     IObject::Ptr FindByName(BASE_NS::string_view name) const override
61     {
62         return container_->FindByName(name);
63     }
64     bool Add(const IObject::Ptr& object) override
65     {
66         return container_->Add(object);
67     }
68     bool Insert(IContainer::SizeType index, const IObject::Ptr& object) override
69     {
70         return container_->Insert(index, object);
71     }
72     using IContainer::GetAt;
73     IObject::Ptr GetAt(IContainer::SizeType index) const override
74     {
75         return container_->GetAt(index);
76     }
77     bool Remove(IContainer::SizeType index) override
78     {
79         return container_->Remove(index);
80     }
81     bool Remove(const IObject::Ptr& child) override
82     {
83         return container_->Remove(child);
84     }
85     bool Replace(const IObject::Ptr& child, const IObject::Ptr& replaceWith, bool addAlways) override
86     {
87         return container_->Replace(child, replaceWith, addAlways);
88     }
89     bool Move(IContainer::SizeType fromIndex, IContainer::SizeType toIndex) override
90     {
91         return container_->Move(fromIndex, toIndex);
92     }
93     bool Move(const IObject::Ptr& child, IContainer::SizeType toIndex) override
94     {
95         return container_->Move(child, toIndex);
96     }
97     void RemoveAll() override
98     {
99         container_->RemoveAll();
100     }
101     META_FORWARD_EVENT(IOnChildChanged, OnContainerChanged, container_->EventOnContainerChanged)
102 
103     bool IsAncestorOf(const IObject::ConstPtr& object) const override
104     {
105         return container_->IsAncestorOf(object);
106     }
107 
108 protected: // IRequiredInterfaces
109     bool SetRequiredInterfaces(const BASE_NS::vector<TypeId>& interfaces) override
110     {
111         return META_EXT_CALL_BASE(IRequiredInterfaces, SetRequiredInterfaces(interfaces));
112     }
113     BASE_NS::vector<TypeId> GetRequiredInterfaces() const override
114     {
115         return META_EXT_CALL_BASE(IRequiredInterfaces, GetRequiredInterfaces());
116     }
117 
118 protected: // IContainerProxyParent
119     bool SetProxyParent(const IContainer::Ptr& parent) override
120     {
121         return META_EXT_CALL_BASE(IContainerProxyParent, SetProxyParent(parent));
122     }
123 
124 protected: // ILockable
125     void LockShared() const override
126     {
127         META_EXT_CALL_BASE(ILockable, LockShared());
128     }
129     void UnlockShared() const override
130     {
131         META_EXT_CALL_BASE(ILockable, UnlockShared());
132     }
133     void Lock() const override
134     {
135         META_EXT_CALL_BASE(ILockable, Lock());
136     }
137     void Unlock() const override
138     {
139         META_EXT_CALL_BASE(ILockable, Unlock());
140     }
141 
142 protected: // IIterable
143     IterationResult Iterate(const IterationParameters& params) override
144     {
145         return META_EXT_CALL_BASE(IIterable, Iterate(params));
146     }
147     IterationResult Iterate(const IterationParameters& params) const override
148     {
149         return META_EXT_CALL_BASE(IIterable, Iterate(params));
150     }
151 
152 private:
153     IContainer* container_ {};
154 };
155 
156 META_END_NAMESPACE()
157 
158 #endif
159