Skip to content

Commit 4171dfd

Browse files
committed
Add MATLAB_PROXY_TRAITS_DEF macro
1 parent 91d2e07 commit 4171dfd

File tree

1 file changed

+28
-114
lines changed
  • matlab/src/cpp/arrow/matlab/proxy

1 file changed

+28
-114
lines changed

matlab/src/cpp/arrow/matlab/proxy/wrap.cc

Lines changed: 28 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -39,119 +39,34 @@ namespace arrow::matlab::proxy {
3939
template <typename T>
4040
struct ProxyTraits {};
4141

42-
template <>
43-
struct ProxyTraits<arrow::BooleanType> {
44-
using ArrayProxy = arrow::matlab::array::proxy::BooleanArray;
45-
using TypeProxy = arrow::matlab::type::proxy::PrimitiveCType<bool>;
46-
};
47-
48-
template <>
49-
struct ProxyTraits<arrow::Int8Type> {
50-
using ArrayProxy = arrow::matlab::array::proxy::NumericArray<arrow::Int8Type>;
51-
using TypeProxy = arrow::matlab::type::proxy::PrimitiveCType<int8_t>;
52-
};
53-
54-
template <>
55-
struct ProxyTraits<arrow::Int16Type> {
56-
using ArrayProxy = arrow::matlab::array::proxy::NumericArray<arrow::Int16Type>;
57-
using TypeProxy = arrow::matlab::type::proxy::PrimitiveCType<int16_t>;
58-
};
59-
60-
template <>
61-
struct ProxyTraits<arrow::Int32Type> {
62-
using ArrayProxy = arrow::matlab::array::proxy::NumericArray<arrow::Int32Type>;
63-
using TypeProxy = arrow::matlab::type::proxy::PrimitiveCType<int32_t>;
64-
};
65-
66-
template <>
67-
struct ProxyTraits<arrow::Int64Type> {
68-
using ArrayProxy = arrow::matlab::array::proxy::NumericArray<arrow::Int64Type>;
69-
using TypeProxy = arrow::matlab::type::proxy::PrimitiveCType<int64_t>;
70-
};
71-
72-
template <>
73-
struct ProxyTraits<arrow::UInt8Type> {
74-
using ArrayProxy = arrow::matlab::array::proxy::NumericArray<arrow::UInt8Type>;
75-
using TypeProxy = arrow::matlab::type::proxy::PrimitiveCType<uint8_t>;
76-
};
77-
78-
template <>
79-
struct ProxyTraits<arrow::UInt16Type> {
80-
using ArrayProxy = arrow::matlab::array::proxy::NumericArray<arrow::UInt16Type>;
81-
using TypeProxy = arrow::matlab::type::proxy::PrimitiveCType<uint16_t>;
82-
};
83-
84-
template <>
85-
struct ProxyTraits<arrow::UInt32Type> {
86-
using ArrayProxy = arrow::matlab::array::proxy::NumericArray<arrow::UInt32Type>;
87-
using TypeProxy = arrow::matlab::type::proxy::PrimitiveCType<uint32_t>;
88-
};
89-
90-
template <>
91-
struct ProxyTraits<arrow::UInt64Type> {
92-
using ArrayProxy = arrow::matlab::array::proxy::NumericArray<arrow::UInt64Type>;
93-
using TypeProxy = arrow::matlab::type::proxy::PrimitiveCType<uint64_t>;
94-
};
95-
96-
template <>
97-
struct ProxyTraits<arrow::FloatType> {
98-
using ArrayProxy = arrow::matlab::array::proxy::NumericArray<arrow::FloatType>;
99-
using TypeProxy = arrow::matlab::type::proxy::PrimitiveCType<float>;
100-
};
101-
102-
template <>
103-
struct ProxyTraits<arrow::DoubleType> {
104-
using ArrayProxy = arrow::matlab::array::proxy::NumericArray<arrow::DoubleType>;
105-
using TypeProxy = arrow::matlab::type::proxy::PrimitiveCType<double>;
106-
};
107-
108-
template <>
109-
struct ProxyTraits<arrow::Time32Type> {
110-
using ArrayProxy = arrow::matlab::array::proxy::NumericArray<arrow::Time32Type>;
111-
using TypeProxy = arrow::matlab::type::proxy::Time32Type;
112-
};
113-
114-
template <>
115-
struct ProxyTraits<arrow::Time64Type> {
116-
using ArrayProxy = arrow::matlab::array::proxy::NumericArray<arrow::Time64Type>;
117-
using TypeProxy = arrow::matlab::type::proxy::Time64Type;
118-
};
119-
120-
template <>
121-
struct ProxyTraits<arrow::Date32Type> {
122-
using ArrayProxy = arrow::matlab::array::proxy::NumericArray<arrow::Date32Type>;
123-
using TypeProxy = arrow::matlab::type::proxy::Date32Type;
124-
};
125-
126-
template <>
127-
struct ProxyTraits<arrow::Date64Type> {
128-
using ArrayProxy = arrow::matlab::array::proxy::NumericArray<arrow::Date64Type>;
129-
using TypeProxy = arrow::matlab::type::proxy::Date64Type;
130-
};
131-
132-
template <>
133-
struct ProxyTraits<arrow::TimestampType> {
134-
using ArrayProxy = arrow::matlab::array::proxy::NumericArray<arrow::TimestampType>;
135-
using TypeProxy = arrow::matlab::type::proxy::TimestampType;
136-
};
137-
138-
template <>
139-
struct ProxyTraits<arrow::StringType> {
140-
using ArrayProxy = arrow::matlab::array::proxy::StringArray;
141-
using TypeProxy = arrow::matlab::type::proxy::StringType;
142-
};
143-
144-
template <>
145-
struct ProxyTraits<arrow::ListType> {
146-
using ArrayProxy = arrow::matlab::array::proxy::ListArray;
147-
using TypeProxy = arrow::matlab::type::proxy::ListType;
148-
};
149-
150-
template <>
151-
struct ProxyTraits<arrow::StructType> {
152-
using ArrayProxy = arrow::matlab::array::proxy::StructArray;
153-
using TypeProxy = arrow::matlab::type::proxy::StructType;
154-
};
42+
#define MATLAB_PROXY_TRAITS_DEF(ArrowType_, ArrayProxyName_, TypeProxyName_) \
43+
template <> \
44+
struct ProxyTraits<ArrowType_> { \
45+
using ArrayProxy = arrow::matlab::array::proxy::ArrayProxyName_; \
46+
using TypeProxy = arrow::matlab::type::proxy::TypeProxyName_; \
47+
};
48+
49+
MATLAB_PROXY_TRAITS_DEF(arrow::BooleanType, BooleanArray, PrimitiveCType<bool>)
50+
MATLAB_PROXY_TRAITS_DEF(arrow::Int8Type, NumericArray<arrow::Int8Type>, PrimitiveCType<int8_t>)
51+
MATLAB_PROXY_TRAITS_DEF(arrow::Int16Type, NumericArray<arrow::Int16Type>, PrimitiveCType<int16_t>)
52+
MATLAB_PROXY_TRAITS_DEF(arrow::Int32Type, NumericArray<arrow::Int32Type>, PrimitiveCType<int32_t>)
53+
MATLAB_PROXY_TRAITS_DEF(arrow::Int64Type, NumericArray<arrow::Int64Type>, PrimitiveCType<int64_t>)
54+
MATLAB_PROXY_TRAITS_DEF(arrow::UInt8Type, NumericArray<arrow::UInt8Type>, PrimitiveCType<uint8_t>)
55+
MATLAB_PROXY_TRAITS_DEF(arrow::UInt16Type, NumericArray<arrow::UInt16Type>, PrimitiveCType<uint16_t>)
56+
MATLAB_PROXY_TRAITS_DEF(arrow::UInt32Type, NumericArray<arrow::UInt32Type>, PrimitiveCType<uint32_t>)
57+
MATLAB_PROXY_TRAITS_DEF(arrow::UInt64Type, NumericArray<arrow::UInt64Type>, PrimitiveCType<uint64_t>)
58+
MATLAB_PROXY_TRAITS_DEF(arrow::FloatType, NumericArray<arrow::FloatType>, PrimitiveCType<float>)
59+
MATLAB_PROXY_TRAITS_DEF(arrow::DoubleType, NumericArray<arrow::DoubleType>, PrimitiveCType<double>)
60+
MATLAB_PROXY_TRAITS_DEF(arrow::Time32Type, NumericArray<arrow::Time32Type>, Time32Type)
61+
MATLAB_PROXY_TRAITS_DEF(arrow::Time64Type, NumericArray<arrow::Time64Type>, Time64Type)
62+
MATLAB_PROXY_TRAITS_DEF(arrow::Date32Type, NumericArray<arrow::Date32Type>, Date32Type)
63+
MATLAB_PROXY_TRAITS_DEF(arrow::Date64Type, NumericArray<arrow::Date64Type>, Date64Type)
64+
MATLAB_PROXY_TRAITS_DEF(arrow::TimestampType, NumericArray<arrow::TimestampType>, TimestampType)
65+
MATLAB_PROXY_TRAITS_DEF(arrow::StringType, StringArray, StringType)
66+
MATLAB_PROXY_TRAITS_DEF(arrow::ListType, ListArray, ListType)
67+
MATLAB_PROXY_TRAITS_DEF(arrow::StructType, StructArray, StructType)
68+
69+
#undef MATLAB_PROXY_TRAITS_DEF
15570

15671
template <typename ArrowType>
15772
std::shared_ptr<typename ProxyTraits<ArrowType>::ArrayProxy> make_proxy(const std::shared_ptr<arrow::Array>& array) {
@@ -192,7 +107,6 @@ namespace arrow::matlab::proxy {
192107
}
193108
};
194109

195-
196110
struct WrapTypeFunctor {
197111
using InputType = arrow::DataType;
198112
using OutputType = arrow::matlab::type::proxy::Type;

0 commit comments

Comments
 (0)