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_CONTENT_OBJECT_H
17 #define META_EXT_CONTENT_OBJECT_H
18
19 #include <meta/interface/intf_content.h>
20 #include <meta/interface/intf_iterable.h>
21 #include <meta/interface/intf_required_interfaces.h>
22
23 #include "object.h"
24
META_BEGIN_NAMESPACE()25 META_BEGIN_NAMESPACE()
26
27 /**
28 * @brief A helper class which can be inherited by custom ContentObject implementations to prevent re-implementing these
29 * forwarders.
30 *
31 * This forwarder always uses ClassId::ContentObject as the base instance, and also always specifies that the
32 * class implements interfaces from ObjectFwd and IContent.
33 */
34 template<class FinalClass, const ClassInfo& ClassInfo, class... Interfaces>
35 class ContentObjectFwd : public ObjectFwd<FinalClass, ClassInfo, ClassId::ContentObject, IContent, IRequiredInterfaces,
36 IIterable, Interfaces...> {
37 using Super = ObjectFwd<FinalClass, ClassInfo, ClassId::ContentObject, IContent, IRequiredInterfaces, IIterable,
38 Interfaces...>;
39
40 protected:
41 META_FORWARD_READONLY_PROPERTY(IObject::Ptr, Content, content_->PropertyContent())
42 META_FORWARD_PROPERTY(bool, ContentSearchable, content_->PropertyContentSearchable())
43 META_FORWARD_PROPERTY(IContentLoader::Ptr, ContentLoader, content_->PropertyContentLoader())
44
45 void SetSuperInstance(const IObject::Ptr& aggr, const IObject::Ptr& super) override
46 {
47 Super::SetSuperInstance(aggr, super);
48 content_ = interface_cast<IContent>(super);
49 assert(content_);
50 iterable_ = interface_cast<IIterable>(super);
51 assert(iterable_);
52 }
53 bool SetRequiredInterfaces(const BASE_NS::vector<TypeId>& interfaces) override
54 {
55 const auto req = interface_cast<IRequiredInterfaces>(GetSelf());
56 return req ? req->SetRequiredInterfaces(interfaces) : false;
57 }
58 BASE_NS::vector<TypeId> GetRequiredInterfaces() const override
59 {
60 const auto req = interface_cast<IRequiredInterfaces>(GetSelf());
61 return req ? req->GetRequiredInterfaces() : nullptr;
62 }
63 IterationResult Iterate(const IterationParameters& params) override
64 {
65 return iterable_->Iterate(params);
66 }
67 IterationResult Iterate(const IterationParameters& params) const override
68 {
69 return iterable_->Iterate(params);
70 }
71
72 IContent* content_ {};
73 IIterable* iterable_ {};
74 };
75
76 META_END_NAMESPACE()
77
78 #endif
79