/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * Licensed 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 namespace apache { namespace thrift { namespace op { namespace detail { using pa = ::apache::thrift::detail::st::private_access; template struct Get; template struct GetOrdinalImpl; template constexpr void for_each_ordinal_impl(F&& f, std::index_sequence); template using ord_result_t = decltype(std::declval()(type::detail::pos_to_ordinal{})); template ord_result_t find_by_ordinal_impl(F&& f, std::index_sequence); // TODO: support adapted field and smart pointers with custom allocators struct GetValueOrNull { template auto* operator()(field_ref field_ref) const { return &field_ref.value(); } template auto* operator()(required_field_ref field_ref) const { return &field_ref.value(); } template auto* operator()(optional_field_ref field_ref) const { return field_ref.has_value() ? &field_ref.value() : nullptr; } template auto* operator()(optional_boxed_field_ref field_ref) const { return field_ref.has_value() ? &field_ref.value() : nullptr; } template auto* operator()(terse_field_ref field_ref) const { return &field_ref.value(); } template auto* operator()(union_field_ref field_ref) const { return field_ref.has_value() ? &field_ref.value() : nullptr; } template auto* operator()(terse_intern_boxed_field_ref field_ref) const { return &field_ref.value(); } template auto* operator()(intern_boxed_field_ref field_ref) const { return &field_ref.value(); } template T* operator()(std::optional& opt) const { return bool(opt) ? &opt.value() : nullptr; } template const T* operator()(const std::optional& opt) const { return bool(opt) ? &opt.value() : nullptr; } template T* operator()(const std::unique_ptr&& ptr) const = delete; template T* operator()(const std::unique_ptr& ptr) const { return ptr ? ptr.get() : nullptr; } template T* operator()(const std::shared_ptr&& ptr) const = delete; template T* operator()(const std::shared_ptr& ptr) const { return ptr ? ptr.get() : nullptr; } }; } // namespace detail } // namespace op } // namespace thrift } // namespace apache