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
30#include "iceberg/result.h"
31#include "iceberg/type.h"
34
35namespace iceberg {
36
37#define TYPE_VISIT_INLINE(TYPE_CLASS) \
38 case TYPE_CLASS##Type::kTypeId: \
39 return visitor->Visit( \
40 iceberg::internal::checked_cast<const TYPE_CLASS##Type&>(type), \
41 std::forward<ARGS>(args)...);
42
62
63template <typename VISITOR, typename... ARGS>
64inline Status VisitTypeInline(const Type& type, VISITOR* visitor, ARGS&&... args) {
65 switch (type.type_id()) {
66 ICEBERG_GENERATE_FOR_ALL_TYPES(TYPE_VISIT_INLINE);
67 default:
68 break;
69 }
70 return NotImplemented("Type not implemented");
71}
72
73#undef TYPE_VISIT_INLINE
74
75#define TYPE_VISIT_INLINE(TYPE_CLASS) \
76 case TYPE_CLASS##Type::kTypeId: \
77 return std::forward<VISITOR>(visitor)( \
78 internal::checked_cast<const TYPE_CLASS##Type&>(type), \
79 std::forward<ARGS>(args)...);
80
92template <typename VISITOR, typename... ARGS>
93inline auto VisitType(const Type& type, VISITOR&& visitor, ARGS&&... args)
94 -> decltype(std::forward<VISITOR>(visitor)(type, args...)) {
95 switch (type.type_id()) {
96 ICEBERG_GENERATE_FOR_ALL_TYPES(TYPE_VISIT_INLINE);
97 default:
99 }
100}
101
102#undef TYPE_VISIT_INLINE
103
104#define TYPE_ID_VISIT_INLINE(TYPE_CLASS) \
105 case TYPE_CLASS##Type::kTypeId: { \
106 const TYPE_CLASS##Type* concrete_ptr = nullptr; \
107 return visitor->Visit(concrete_ptr, std::forward<ARGS>(args)...); \
108 }
109
116template <typename VISITOR, typename... ARGS>
117inline Status VisitTypeIdInline(TypeId id, VISITOR* visitor, ARGS&&... args) {
118 switch (id) {
119 ICEBERG_GENERATE_FOR_ALL_TYPES(TYPE_ID_VISIT_INLINE);
120 default:
121 break;
122 }
123 return NotImplemented("Type not implemented");
124}
125
126#undef TYPE_ID_VISIT_INLINE
127
155template <typename VISITOR, typename... ARGS>
156inline auto VisitTypeCategory(const Type& type, VISITOR* visitor, ARGS&&... args) {
157#define SCHEMA_VISIT_ACTION(TYPE_CLASS) \
158 return visitor->Visit##TYPE_CLASS( \
159 internal::checked_cast<const TYPE_CLASS##Type&>(type), \
160 std::forward<ARGS>(args)...);
161
162 switch (type.type_id()) {
164 }
165
166#undef SCHEMA_VISIT_ACTION
167}
168
169} // 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
virtual TypeId type_id() const =0
Get the type ID.
Definition expected.h:1199
Core Apache Iceberg C++ APIs.
Definition arrow_io_util.h:34
auto VisitTypeCategory(const Type &type, VISITOR *visitor, ARGS &&... args)
Visit a type using a categorical visitor pattern.
Definition visit_type.h:156
void unreachable() noexcept
Marks a branch the program can never take.
Definition unreachable.h:35
Status VisitTypeIdInline(TypeId id, VISITOR *visitor, ARGS &&... args)
Calls visitor with a nullptr of the corresponding concrete type class.
Definition visit_type.h:117
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:93
Status VisitTypeInline(const Type &type, VISITOR *visitor, ARGS &&... args)
Calls visitor with the corresponding concrete type class.
Definition visit_type.h:64
TypeId
A data type.
Definition type_fwd.h:37
Define Result, Status, and error helpers.
Portable stand-in for std::unreachable.
Define macros for generating type visitors.
#define ICEBERG_TYPE_SWITCH_WITH_PRIMITIVE_DEFAULT(ACTION)
Generate switch-case for schema visitor pattern.
Definition visitor_generate.h:64