sparrow-extensions 0.1.0
Extension types for the sparrow library
Loading...
Searching...
No Matches
bool8_array.hpp
Go to the documentation of this file.
1// Copyright 2024 Man Group Operations Limited
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include "sparrow/primitive_array.hpp"
18#include "sparrow/utils/extension.hpp"
19
21{
38 using bool8_array = sparrow::primitive_array<int8_t, sparrow::simple_extension<"arrow.bool8">, bool>;
39}
40
41#if defined(__cpp_lib_format)
42# include <format>
43
44// Formatter specialization for bool8_array
45template <>
46struct std::formatter<sparrow_extensions::bool8_array>
47{
48 constexpr auto parse(std::format_parse_context& ctx)
49 {
50 return ctx.begin();
51 }
52
53 auto format(const sparrow_extensions::bool8_array& ar, std::format_context& ctx) const
54 {
55 std::format_to(ctx.out(), "Bool8 array [{}]: [", ar.size());
56 for (std::size_t i = 0; i < ar.size(); ++i)
57 {
58 if (i > 0)
59 {
60 std::format_to(ctx.out(), ", ");
61 }
62 const auto elem = ar[i];
63 if (elem.has_value())
64 {
65 std::format_to(ctx.out(), "{}", static_cast<bool>(elem.value()) ? "true" : "false");
66 }
67 else
68 {
69 std::format_to(ctx.out(), "null");
70 }
71 }
72 return std::format_to(ctx.out(), "]");
73 }
74};
75
76namespace sparrow_extensions
77{
78 inline std::ostream& operator<<(std::ostream& os, const bool8_array& value)
79 {
80 os << std::format("{}", value);
81 return os;
82 }
83}
84
85#endif
sparrow::primitive_array< int8_t, sparrow::simple_extension<"arrow.bool8">, bool > bool8_array
Bool8 array using 8-bit storage for boolean values.