• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_INTERFACE_PROPERTY_CONSTRUCT_ARRAY_PROPERTY_H
17 #define META_INTERFACE_PROPERTY_CONSTRUCT_ARRAY_PROPERTY_H
18 
19 #include <meta/interface/intf_object_flags.h>
20 #include <meta/interface/intf_object_registry.h>
21 #include <meta/interface/property/array_property.h>
22 
META_BEGIN_NAMESPACE()23 META_BEGIN_NAMESPACE()
24 
25 template<typename T>
26 ArrayProperty<T> ConstructArrayProperty(IObjectRegistry& obr, BASE_NS::string_view name,
27     BASE_NS::array_view<const T> value = {}, ObjectFlagBitsValue flags = ObjectFlagBits::SERIALIZE)
28 {
29     ArrayProperty<T> p(NOCHECK, obr.GetPropertyRegister().Create(ClassId::StackProperty, name));
30     if (auto i = interface_cast<IPropertyInternalAny>(p.GetProperty())) {
31         i->SetInternalAny(ConstructArrayAny<T>(BASE_NS::move(value)));
32     }
33     SetObjectFlags(p.GetProperty(), flags, true);
34     return p;
35 }
36 
37 template<typename T>
38 ArrayProperty<T> ConstructArrayProperty(BASE_NS::string_view name, BASE_NS::array_view<const T> value = {},
39     ObjectFlagBitsValue flags = ObjectFlagBits::SERIALIZE)
40 {
41     return ConstructArrayProperty(GetObjectRegistry(), name, BASE_NS::move(value), flags);
42 }
43 
44 template<typename T>
45 ArrayProperty<T> ConstructArrayPropertyAny(
46     BASE_NS::string_view name, const IAny& value, ObjectFlagBitsValue flags = ObjectFlagBits::SERIALIZE)
47 {
48     auto p = ConstructArrayProperty<T>(name, {}, flags);
49     if (p) {
50         p.GetUnlockedAccess().SetDefaultValueAny(value);
51     }
52     return p;
53 }
54 
55 // helpers to handle default values with Value Ptr stuff
56 template<typename T>
ConstructArrayAnyHelper(BASE_NS::vector<T> value)57 IAny::Ptr ConstructArrayAnyHelper(BASE_NS::vector<T> value)
58 {
59     return ConstructArrayAny(BASE_NS::move(value));
60 }
61 template<typename T, typename Param = typename T::TypePtr, typename = typename T::TypePtr>
ConstructArrayAnyHelper(BASE_NS::vector<Param> value)62 IAny::Ptr ConstructArrayAnyHelper(BASE_NS::vector<Param> value)
63 {
64     return ConstructArrayAny(BASE_NS::move(value));
65 }
66 
67 META_END_NAMESPACE()
68 
69 #endif
70