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 #include <meta/interface/intf_static_metadata.h> 27 META_BEGIN_NAMESPACE()28META_BEGIN_NAMESPACE() 29 30 /// Simple object implementation that implements minimal set of interfaces for object 31 class MinimalObject : public IntroduceInterfaces<IObject, IObjectFlags, IStaticMetadata> { 32 public: 33 MinimalObject() : flags_(ObjectFlagBits::DEFAULT_FLAGS) {} 34 MinimalObject(const ObjectFlagBitsValue& value) : flags_(value) {} 35 36 BASE_NS::string GetName() const override 37 { 38 return GetClassId().ToString(); 39 } 40 41 ObjectFlagBitsValue GetObjectFlags() const override 42 { 43 return flags_; 44 } 45 46 void SetObjectFlags(const ObjectFlagBitsValue& value) override 47 { 48 flags_ = value; 49 } 50 51 ObjectFlagBitsValue GetObjectDefaultFlags() const override 52 { 53 return ObjectFlagBits::DEFAULT_FLAGS; 54 } 55 56 // this allows to use the same macros for minimal objects too 57 inline static const nullptr_t STATIC_METADATA {}; 58 static const StaticObjectMetadata* StaticMetadata() 59 { 60 return nullptr; 61 } 62 const StaticObjectMetadata* GetStaticMetadata() const override 63 { 64 return StaticMetadata(); 65 } 66 67 private: 68 ObjectFlagBitsValue flags_ {}; 69 }; 70 71 META_END_NAMESPACE() 72 73 #endif 74