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(IAny::Ptr(new ArrayAny<T>));
32 }
33 auto access = p.GetUnlockedAccess();
34 access.SetDefaultValue(BASE_NS::move(value));
35 SetObjectFlags(p.GetProperty(), flags, true);
36 return p;
37 }
38
39 template<typename T>
40 ArrayProperty<T> ConstructArrayProperty(BASE_NS::string_view name, BASE_NS::array_view<const T> value = {},
41 ObjectFlagBitsValue flags = ObjectFlagBits::SERIALIZE)
42 {
43 return ConstructArrayProperty(GetObjectRegistry(), name, BASE_NS::move(value), flags);
44 }
45
46 META_END_NAMESPACE()
47
48 #endif
49