• 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 #ifndef META_INTERFACE_DETAIL_ANY_H
16 #define META_INTERFACE_DETAIL_ANY_H
17 
18 #include <meta/interface/detail/base_any.h>
19 #include <meta/interface/detail/enum.h>
20 
21 META_BEGIN_NAMESPACE()
22 
23 template<typename Type, typename = EnableSpecialisationType>
24 struct MapAnyType {
25     using AnyType = Any<Type>;
26     using ArrayAnyType = ArrayAny<Type>;
27 };
28 
29 /*
30     Use something like this for partial specialising:
31     template<typename Type>
32     struct MapAnyType<Type, EnableSpecialisation<is_enum_v<Type>> {};
33 */
34 template<typename Type>
35 struct MapAnyType<Type, EnableSpecialisation<is_enum_v<Type>>> {
36     using AnyType = EnumBase<Type>;
37     using ArrayAnyType = ArrayEnumBase<Type>;
38 };
39 
40 template<typename Type>
41 using AnyType = typename MapAnyType<Type>::AnyType;
42 
43 template<typename Type>
44 using ArrayAnyType = typename MapAnyType<Type>::ArrayAnyType;
45 
46 template<typename Type>
47 static IAny::Ptr ConstructAny(Type v = {})
48 {
49     return IAny::Ptr { new AnyType<Type>(BASE_NS::move(v)) };
50 }
51 
52 template<typename Type>
53 static IAny::Ptr ConstructAny(BASE_NS::vector<Type> v)
54 {
55     return IAny::Ptr { new ArrayAnyType<Type>(BASE_NS::move(v)) };
56 }
57 
58 template<typename Type>
59 static IArrayAny::Ptr ConstructArrayAny(BASE_NS::vector<Type> v = {})
60 {
61     return IArrayAny::Ptr { new ArrayAnyType<Type>(BASE_NS::move(v)) };
62 }
63 
64 template<typename Type>
65 static IArrayAny::Ptr ConstructArrayAny(BASE_NS::array_view<const Type> v)
66 {
67     return IArrayAny::Ptr { new ArrayAnyType<Type>(v) };
68 }
69 
70 #ifdef BASE_VECTOR_HAS_INITIALIZE_LIST
71 template<typename Type>
72 static IArrayAny::Ptr ConstructArrayAny(std::initializer_list<Type> l)
73 {
74     return IArrayAny::Ptr { new ArrayAnyType<Type>(l) };
75 }
76 #endif
77 
78 META_END_NAMESPACE()
79 
80 #endif
81