29#include "iceberg/result.h"
32#include "iceberg/util/visitor_generate.h"
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)...);
62template <
typename VISITOR,
typename... ARGS>
64 switch (type.type_id()) {
65 ICEBERG_GENERATE_FOR_ALL_TYPES(TYPE_VISIT_INLINE);
69 return NotImplemented(
"Type not implemented");
72#undef TYPE_VISIT_INLINE
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)...);
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);
101#undef TYPE_VISIT_INLINE
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)...); \
115template <
typename VISITOR,
typename... ARGS>
118 ICEBERG_GENERATE_FOR_ALL_TYPES(TYPE_ID_VISIT_INLINE);
122 return NotImplemented(
"Type not implemented");
125#undef TYPE_ID_VISIT_INLINE
151template <
typename VISITOR,
typename... 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)...);
158 switch (type.type_id()) {
159 ICEBERG_TYPE_SWITCH_WITH_PRIMITIVE_DEFAULT(SCHEMA_VISIT_ACTION)
162#undef SCHEMA_VISIT_ACTION
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