#pragma clang system_header // Licensed to the Apache Software Foundation (ASF) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information // regarding copyright ownership. The ASF licenses this file // to you under the Apache License, Version 2.0 (the // "License"); you may not use this file except in compliance // with the License. You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, // software distributed under the License is distributed on an // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. #pragma once #include #include #include #include #include "contrib/libs/apache/arrow_next/cpp/src/arrow/type_traits.h" namespace arrow20 { namespace internal { template struct all_same : std::true_type {}; template struct all_same : std::true_type {}; template struct all_same : all_same {}; template struct all_same : std::false_type {}; template void ForEachTupleMemberImpl(const std::tuple& tup, Fn&& fn, std::index_sequence) { (..., fn(std::get(tup), I)); } template void ForEachTupleMember(const std::tuple& tup, Fn&& fn) { ForEachTupleMemberImpl(tup, fn, std::index_sequence_for()); } template struct DataMemberProperty { using Class = C; using Type = T; constexpr const Type& get(const Class& obj) const { return obj.*ptr_; } void set(Class* obj, Type value) const { (*obj).*ptr_ = std::move(value); } constexpr std::string_view name() const { return name_; } std::string_view name_; Type Class::*ptr_; }; template constexpr DataMemberProperty DataMember(std::string_view name, Type Class::*ptr) { return {name, ptr}; } template struct CoercedDataMemberProperty { using Class = C; using Type = T; constexpr Type get(const Class& obj) const { return (obj.*get_coerced_)(); } void set(Class* obj, Type value) const { (*obj).*ptr_for_set_ = std::move(value); } constexpr std::string_view name() const { return name_; } std::string_view name_; Type Class::*ptr_for_set_; Type (Class::*get_coerced_)() const; }; template constexpr CoercedDataMemberProperty CoercedDataMember(std::string_view name, Type Class::*ptr, Type (Class::*get)() const) { return {name, ptr, get}; } template struct PropertyTuple { template void ForEach(Fn&& fn) const { ForEachTupleMember(props_, fn); } static_assert(all_same::value, "All properties must be properties of the same class"); size_t size() const { return sizeof...(Properties); } std::tuple props_; }; template PropertyTuple MakeProperties(Properties... props) { return {std::make_tuple(props...)}; } template struct EnumTraits {}; template struct BasicEnumTraits { using CType = typename std::underlying_type::type; using Type = typename CTypeTraits::ArrowType; static std::array values() { return {Values...}; } }; template struct has_enum_traits : std::false_type {}; template struct has_enum_traits::Type>> : std::true_type {}; } // namespace internal } // namespace arrow20