1 /*************************************************************************
3 * Copyright 2016 Realm Inc.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 **************************************************************************/
19 #ifndef REALM_COLUMN_TYPE_TRAITS_HPP
20 #define REALM_COLUMN_TYPE_TRAITS_HPP
22 #include <realm/column_fwd.hpp>
23 #include <realm/column_type.hpp>
24 #include <realm/data_type.hpp>
25 #include <realm/array.hpp>
37 struct ColumnTypeTraits;
40 struct ColumnTypeTraits<int64_t> {
41 using column_type = Column<int64_t>;
42 using leaf_type = ArrayInteger;
43 using sum_type = int64_t;
44 using minmax_type = int64_t;
45 static const DataType id = type_Int;
46 static const ColumnType column_id = col_type_Int;
47 static const ColumnType real_column_type = col_type_Int;
51 struct ColumnTypeTraits<util::Optional<int64_t>> {
52 using column_type = Column<util::Optional<int64_t>>;
53 using leaf_type = ArrayIntNull;
54 using sum_type = int64_t;
55 using minmax_type = int64_t;
56 static const DataType id = type_Int;
57 static const ColumnType column_id = col_type_Int;
58 static const ColumnType real_column_type = col_type_Int;
62 struct ColumnTypeTraits<bool> : ColumnTypeTraits<int64_t> {
63 static const DataType id = type_Bool;
64 static const ColumnType column_id = col_type_Bool;
68 struct ColumnTypeTraits<util::Optional<bool>> : ColumnTypeTraits<util::Optional<int64_t>> {
69 static const DataType id = type_Bool;
70 static const ColumnType column_id = col_type_Bool;
74 struct ColumnTypeTraits<float> {
75 using column_type = FloatColumn;
76 using leaf_type = BasicArray<float>;
77 using sum_type = double;
78 using minmax_type = float;
79 static const DataType id = type_Float;
80 static const ColumnType column_id = col_type_Float;
81 static const ColumnType real_column_type = col_type_Float;
85 struct ColumnTypeTraits<double> {
86 using column_type = DoubleColumn;
87 using leaf_type = BasicArray<double>;
88 using sum_type = double;
89 using minmax_type = double;
90 static const DataType id = type_Double;
91 static const ColumnType column_id = col_type_Double;
92 static const ColumnType real_column_type = col_type_Double;
96 struct ColumnTypeTraits<OldDateTime> : ColumnTypeTraits<int64_t> {
97 static const DataType id = type_OldDateTime;
98 static const ColumnType column_id = col_type_OldDateTime;
102 struct ColumnTypeTraits<util::Optional<OldDateTime>> : ColumnTypeTraits<util::Optional<int64_t>> {
103 static const DataType id = type_OldDateTime;
104 static const ColumnType column_id = col_type_OldDateTime;
108 struct ColumnTypeTraits<StringData> {
109 static const DataType id = type_String;
110 static const ColumnType column_id = col_type_String;
114 struct ColumnTypeTraits<BinaryData> {
115 using column_type = BinaryColumn;
116 using leaf_type = ArrayBinary;
117 static const DataType id = type_Binary;
118 static const ColumnType column_id = col_type_Binary;
119 static const ColumnType real_column_type = col_type_Binary;
122 template <DataType, bool Nullable>
123 struct GetColumnType;
125 struct GetColumnType<type_Int, false> {
126 using type = IntegerColumn;
129 struct GetColumnType<type_Int, true> {
130 using type = IntNullColumn;
133 struct GetColumnType<type_Float, N> {
134 // FIXME: Null definition
135 using type = FloatColumn;
138 struct GetColumnType<type_Double, N> {
139 // FIXME: Null definition
140 using type = DoubleColumn;
143 // Only purpose is to return 'double' if and only if source column (T) is float and you're doing a sum (A)
144 template <class T, Action A>
145 struct ColumnTypeTraitsSum {
150 struct ColumnTypeTraitsSum<float, act_Sum> {
151 typedef double sum_type;
155 struct ColumnTypeTraitsSum<util::Optional<int64_t>, A> {
156 using sum_type = int64_t;
160 #endif // REALM_COLUMN_TYPE_TRAITS_HPP