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_MINIMAL_OBJECT_H
17 #define META_EXT_MINIMAL_OBJECT_H
18
19 #include <base/util/uid_util.h>
20
21 #include <meta/base/namespace.h>
22 #include <meta/interface/interface_helpers.h>
23 #include <meta/interface/intf_lifecycle.h>
24 #include <meta/interface/intf_object.h>
25 #include <meta/interface/intf_object_flags.h>
26
META_BEGIN_NAMESPACE()27 META_BEGIN_NAMESPACE()
28
29 template<const META_NS::ClassInfo& ClassInfo, typename... Interfaces>
30 class MinimalObject : public IntroduceInterfaces<IObject, IObjectFlags, Interfaces...> {
31 public:
32 MinimalObject() : flags_(ObjectFlagBits::DEFAULT_FLAGS) {}
33 MinimalObject(const ObjectFlagBitsValue& value) : flags_(value) {}
34
35 ObjectId GetClassId() const override
36 {
37 return ClassInfo.Id();
38 }
39
40 BASE_NS::string_view GetClassName() const override
41 {
42 return ClassInfo.Name();
43 }
44
45 BASE_NS::string GetName() const override
46 {
47 return GetClassId().ToString();
48 }
49
50 BASE_NS::vector<BASE_NS::Uid> GetInterfaces() const override
51 {
52 return IntroduceInterfaces<IObject, IObjectFlags, Interfaces...>::GetInterfacesVector();
53 }
54
55 ObjectFlagBitsValue GetObjectFlags() const override
56 {
57 return flags_;
58 }
59
60 void SetObjectFlags(const ObjectFlagBitsValue& value) override
61 {
62 flags_ = value;
63 }
64
65 ObjectFlagBitsValue GetObjectDefaultFlags() const override
66 {
67 return ObjectFlagBits::DEFAULT_FLAGS;
68 }
69
70 private:
71 ObjectFlagBitsValue flags_ {};
72 };
73
74 META_END_NAMESPACE()
75
76 #endif
77