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_CONRETE_BASE_OBJECT_H
17 #define META_EXT_CONRETE_BASE_OBJECT_H
18
19 #include <base/util/uid_util.h>
20
21 #include <meta/base/interface_macros.h>
22 #include <meta/ext/implementation_macros.h>
23 #include <meta/ext/metadata_helpers.h>
24 #include <meta/ext/object_factory.h>
25
META_BEGIN_NAMESPACE()26 META_BEGIN_NAMESPACE()
27
28 /**
29 * @brief The ConcreteBaseMetaObjectFwd class is a helper for creating a class which directly inherits a MetaObject
30 * class defined in the same plugin.
31 */
32 template<class FinalClass, class ConcreteBaseClass, const META_NS::ClassInfo& ClassInfo, class... Interfaces>
33 class ConcreteBaseMetaObjectFwd : public META_NS::IntroduceInterfaces<Interfaces...>, public ConcreteBaseClass {
34 protected:
35 using IntroducedInterfaces = META_NS::IntroduceInterfaces<Interfaces...>;
36 using ConcreteBase = ConcreteBaseClass;
37
38 STATIC_METADATA_WITH_CONCRETE_BASE(IntroducedInterfaces, ConcreteBaseClass)
39 STATIC_INTERFACES_WITH_CONCRETE_BASE(IntroducedInterfaces, ConcreteBaseClass)
40 META_DEFINE_OBJECT_TYPE_INFO(FinalClass, ClassInfo)
41
42 protected: // IObject
43 ObjectId GetClassId() const override
44 {
45 return ClassInfo.Id();
46 }
47 BASE_NS::string_view GetClassName() const override
48 {
49 return ClassInfo.Name();
50 }
51 BASE_NS::vector<BASE_NS::Uid> GetInterfaces() const override
52 {
53 return GetStaticInterfaces();
54 }
55
56 public: // CORE_NS::IInterface
57 const CORE_NS::IInterface* GetInterface(const BASE_NS::Uid& uid) const override
58 {
59 auto* me = const_cast<ConcreteBaseMetaObjectFwd*>(this);
60 return me->ConcreteBaseMetaObjectFwd::GetInterface(uid);
61 }
62 CORE_NS::IInterface* GetInterface(const BASE_NS::Uid& uid) override
63 {
64 CORE_NS::IInterface* ret = ConcreteBase::GetInterface(uid);
65 if (!ret) {
66 ret = IntroducedInterfaces::GetInterface(uid);
67 }
68 return ret;
69 }
70
71 protected:
72 void Ref() override
73 {
74 ConcreteBase::Ref();
75 }
76 void Unref() override
77 {
78 ConcreteBase::Unref();
79 }
80 };
81
82 META_END_NAMESPACE()
83
84 #endif // META_EXT_CONRETE_BASE_OBJECT_H
85