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_ANY_BUILDER_H 17 #define META_EXT_ANY_BUILDER_H 18 19 #include <meta/base/meta_types.h> 20 #include <meta/interface/detail/any.h> 21 #include <meta/interface/intf_object_registry.h> 22 #include <meta/interface/property/intf_property_register.h> 23 META_BEGIN_NAMESPACE()24META_BEGIN_NAMESPACE() 25 26 template<typename AnyType> 27 class DefaultAnyBuilder : public AnyBuilder { 28 public: 29 IAny::Ptr Construct() override 30 { 31 return IAny::Ptr(new AnyType); 32 } 33 ObjectId GetObjectId() const override 34 { 35 return AnyType::StaticGetClassId(); 36 } 37 }; 38 39 template<typename AnyType> RegisterUserAny()40void RegisterUserAny() 41 { 42 GetObjectRegistry().GetPropertyRegister().RegisterAny(CreateShared<DefaultAnyBuilder<AnyType>>()); 43 } 44 45 template<typename Type> RegisterTypeForBuiltinAny()46void RegisterTypeForBuiltinAny() 47 { 48 GetObjectRegistry().GetPropertyRegister().RegisterAny(CreateShared<DefaultAnyBuilder<Any<Type>>>()); 49 } 50 51 template<typename Type> RegisterTypeForBuiltinArrayAny()52void RegisterTypeForBuiltinArrayAny() 53 { 54 GetObjectRegistry().GetPropertyRegister().RegisterAny(CreateShared<DefaultAnyBuilder<ArrayAny<Type>>>()); 55 } 56 57 template<typename Type> UnregisterUserAny()58void UnregisterUserAny() 59 { 60 GetObjectRegistry().GetPropertyRegister().UnregisterAny(Type::StaticGetClassId()); 61 } 62 63 template<typename Type> UnregisterTypeForBuiltinAny()64void UnregisterTypeForBuiltinAny() 65 { 66 GetObjectRegistry().GetPropertyRegister().UnregisterAny(Any<Type>::StaticGetClassId()); 67 } 68 69 template<typename Type> UnregisterTypeForBuiltinArrayAny()70void UnregisterTypeForBuiltinArrayAny() 71 { 72 GetObjectRegistry().GetPropertyRegister().UnregisterAny(ArrayAny<Type>::StaticGetClassId()); 73 } 74 75 META_END_NAMESPACE() 76 77 #endif 78