iceberg-cpp
Loading...
Searching...
No Matches
visit_type.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
26
27#include <utility>
28
29#include "iceberg/result.h"
30#include "iceberg/type.h"
32#include "iceberg/util/visitor_generate.h"
33
34namespace iceberg {
35
36#define TYPE_VISIT_INLINE(TYPE_CLASS) \
37 case TYPE_CLASS##Type::kTypeId: \
38 return visitor->Visit( \
39 iceberg::internal::checked_cast<const TYPE_CLASS##Type&>(type), \
40 std::forward<ARGS>(args)...);
41
61
62template <typename VISITOR, typename... ARGS>
63inline Status VisitTypeInline(const Type& type, VISITOR* visitor, ARGS&&... args) {
64 switch (type.type_id()) {
65 ICEBERG_GENERATE_FOR_ALL_TYPES(TYPE_VISIT_INLINE);
66 default:
67 break;
68 }
69 return NotImplemented("Type not implemented");
70}
71
72#undef TYPE_VISIT_INLINE
73
74#define TYPE_VISIT_INLINE(TYPE_CLASS) \
75 case TYPE_CLASS##Type::kTypeId: \
76 return std::forward<VISITOR>(visitor)( \
77 internal::checked_cast<const TYPE_CLASS##Type&>(type), \
78 std::forward<ARGS>(args)...);
79
91template <typename VISITOR, typename... ARGS>
92inline auto VisitType(const Type& type, VISITOR&& visitor, ARGS&&... args)
93 -> decltype(std::forward<VISITOR>(visitor)(type, args...)) {
94 switch (type.type_id()) {
95 ICEBERG_GENERATE_FOR_ALL_TYPES(TYPE_VISIT_INLINE);
96 default:
97 std::unreachable();
98 }
99}
100
101#undef TYPE_VISIT_INLINE
102
103#define TYPE_ID_VISIT_INLINE(TYPE_CLASS) \
104 case TYPE_CLASS##Type::kTypeId: { \
105 const TYPE_CLASS##Type* concrete_ptr = nullptr; \
106 return visitor->Visit(concrete_ptr, std::forward<ARGS>(args)...); \
107 }
108
115template <typename VISITOR, typename... ARGS>
116inline Status VisitTypeIdInline(TypeId id, VISITOR* visitor, ARGS&&... args) {
117 switch (id) {
118 ICEBERG_GENERATE_FOR_ALL_TYPES(TYPE_ID_VISIT_INLINE);
119 default:
120 break;
121 }
122 return NotImplemented("Type not implemented");
123}
124
125#undef TYPE_ID_VISIT_INLINE
126
151template <typename VISITOR, typename... ARGS>
152inline auto VisitTypeCategory(const Type& type, VISITOR* visitor, ARGS&&... args) {
153#define SCHEMA_VISIT_ACTION(TYPE_CLASS) \
154 return visitor->Visit##TYPE_CLASS( \
155 internal::checked_cast<const TYPE_CLASS##Type&>(type), \
156 std::forward<ARGS>(args)...);
157
158 switch (type.type_id()) {
159 ICEBERG_TYPE_SWITCH_WITH_PRIMITIVE_DEFAULT(SCHEMA_VISIT_ACTION)
160 }
161
162#undef SCHEMA_VISIT_ACTION
163}
164
165} // namespace iceberg
Checked cast functions for dynamic_cast and static_cast. Adapted from Apache Arrow https://github....
Interface for a data type for a field.
Definition type.h:44
TypeId
A data type.
Definition type_fwd.h:35
auto VisitTypeCategory(const Type &type, VISITOR *visitor, ARGS &&... args)
Visit a type using a categorical visitor pattern.
Definition visit_type.h:152
Status VisitTypeIdInline(TypeId id, VISITOR *visitor, ARGS &&... args)
Calls visitor with a nullptr of the corresponding concrete type class.
Definition visit_type.h:116
auto VisitType(const Type &type, VISITOR &&visitor, ARGS &&... args) -> decltype(std::forward< VISITOR >(visitor)(type, args...))
Call visitor with the corresponding concrete type class.
Definition visit_type.h:92
Status VisitTypeInline(const Type &type, VISITOR *visitor, ARGS &&... args)
Calls visitor with the corresponding concrete type class.
Definition visit_type.h:63