![]() |
|
|||
File indexing completed on 2025-08-27 08:47:24
0001 // Licensed to the Apache Software Foundation (ASF) under one 0002 // or more contributor license agreements. See the NOTICE file 0003 // distributed with this work for additional information 0004 // regarding copyright ownership. The ASF licenses this file 0005 // to you under the Apache License, Version 2.0 (the 0006 // "License"); you may not use this file except in compliance 0007 // with the License. You may obtain a copy of the License at 0008 // 0009 // http://www.apache.org/licenses/LICENSE-2.0 0010 // 0011 // Unless required by applicable law or agreed to in writing, 0012 // software distributed under the License is distributed on an 0013 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 0014 // KIND, either express or implied. See the License for the 0015 // specific language governing permissions and limitations 0016 // under the License. 0017 0018 #pragma once 0019 0020 #include "arrow/extension_type.h" 0021 #include "arrow/type.h" 0022 #include "arrow/util/macros.h" 0023 #include "arrow/visitor_generate.h" 0024 0025 namespace arrow { 0026 0027 #define TYPE_VISIT_INLINE(TYPE_CLASS) \ 0028 case TYPE_CLASS##Type::type_id: \ 0029 return visitor->Visit(internal::checked_cast<const TYPE_CLASS##Type&>(type), \ 0030 std::forward<ARGS>(args)...); 0031 0032 /// \brief Calls `visitor` with the corresponding concrete type class 0033 /// 0034 /// \tparam VISITOR Visitor type that implements Visit() for all Arrow types. 0035 /// \tparam ARGS Additional arguments, if any, will be passed to the Visit function after 0036 /// the `type` argument 0037 /// \return Status 0038 /// 0039 /// A visitor is a type that implements specialized logic for each Arrow type. 0040 /// Example usage: 0041 /// 0042 /// ``` 0043 /// class ExampleVisitor { 0044 /// arrow::Status Visit(const arrow::Int32Type& type) { ... } 0045 /// arrow::Status Visit(const arrow::Int64Type& type) { ... } 0046 /// ... 0047 /// } 0048 /// ExampleVisitor visitor; 0049 /// VisitTypeInline(some_type, &visitor); 0050 /// ``` 0051 template <typename VISITOR, typename... ARGS> 0052 inline Status VisitTypeInline(const DataType& type, VISITOR* visitor, ARGS&&... args) { 0053 switch (type.id()) { 0054 ARROW_GENERATE_FOR_ALL_TYPES(TYPE_VISIT_INLINE); 0055 default: 0056 break; 0057 } 0058 return Status::NotImplemented("Type not implemented"); 0059 } 0060 0061 #undef TYPE_VISIT_INLINE 0062 0063 #define TYPE_VISIT_INLINE(TYPE_CLASS) \ 0064 case TYPE_CLASS##Type::type_id: \ 0065 return std::forward<VISITOR>(visitor)( \ 0066 internal::checked_cast<const TYPE_CLASS##Type&>(type), \ 0067 std::forward<ARGS>(args)...); 0068 0069 /// \brief Call `visitor` with the corresponding concrete type class 0070 /// \tparam ARGS Additional arguments, if any, will be passed to the Visit function after 0071 /// the `type` argument 0072 /// 0073 /// Unlike VisitTypeInline which calls `visitor.Visit`, here `visitor` 0074 /// itself is called. 0075 /// `visitor` must support a `const DataType&` argument as a fallback, 0076 /// in addition to concrete type classes. 0077 /// 0078 /// The intent is for this to be called on a generic lambda 0079 /// that may internally use `if constexpr` or similar constructs. 0080 template <typename VISITOR, typename... ARGS> 0081 inline auto VisitType(const DataType& type, VISITOR&& visitor, ARGS&&... args) 0082 -> decltype(std::forward<VISITOR>(visitor)(type, args...)) { 0083 switch (type.id()) { 0084 ARROW_GENERATE_FOR_ALL_TYPES(TYPE_VISIT_INLINE); 0085 default: 0086 break; 0087 } 0088 return std::forward<VISITOR>(visitor)(type, std::forward<ARGS>(args)...); 0089 } 0090 0091 #undef TYPE_VISIT_INLINE 0092 0093 #define TYPE_ID_VISIT_INLINE(TYPE_CLASS) \ 0094 case TYPE_CLASS##Type::type_id: { \ 0095 const TYPE_CLASS##Type* concrete_ptr = NULLPTR; \ 0096 return visitor->Visit(concrete_ptr, std::forward<ARGS>(args)...); \ 0097 } 0098 0099 /// \brief Calls `visitor` with a nullptr of the corresponding concrete type class 0100 /// 0101 /// \tparam VISITOR Visitor type that implements Visit() for all Arrow types. 0102 /// \tparam ARGS Additional arguments, if any, will be passed to the Visit function after 0103 /// the `type` argument 0104 /// \return Status 0105 template <typename VISITOR, typename... ARGS> 0106 inline Status VisitTypeIdInline(Type::type id, VISITOR* visitor, ARGS&&... args) { 0107 switch (id) { 0108 ARROW_GENERATE_FOR_ALL_TYPES(TYPE_ID_VISIT_INLINE); 0109 default: 0110 break; 0111 } 0112 return Status::NotImplemented("Type not implemented"); 0113 } 0114 0115 #undef TYPE_ID_VISIT_INLINE 0116 0117 } // namespace arrow
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |