AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
writer.hpp
1/*
2 ANCH Framework: ANother C++ Hack is a C++ framework based on C++23 standard
3 Copyright (C) 2026 Vincent Lachenal
4
5 This file is part of ANCH Framework.
6
7 ANCH Framework is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 ANCH Framework is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with ANCH Framework. If not, see <https://www.gnu.org/licenses/>.
19*/
20#pragma once
21
22#include "anch-csv-export.hpp"
23
24#include <concepts>
25#include <cstddef>
26#include <initializer_list>
27#include <ostream>
28#include <span>
29#include <string_view>
30#include <type_traits>
31#include <vector>
32
33#include "csv/options.hpp"
34
35namespace anch::csv::detail {
36
41 class Text {
42 private:
44 std::string_view _view;
45
47 char _buffer[64];
48
50 std::size_t _length;
51
52 public:
58 template<typename V>
59 requires std::convertible_to<const V&, std::string_view>
60 Text(const V& value);
61
67 Text(char value);
68
74 Text(bool value);
75
81 template<typename V>
82 requires (std::is_arithmetic_v<V> && !std::same_as<V, bool> && !std::same_as<V, char>)
83 Text(V value);
84
86 Text(const Text&) = delete;
87
93 std::string_view value() const noexcept;
94 };
95
96}
97
98namespace anch::csv {
99
111 class ANCH_CSV_EXPORT Writer {
112
113 // Attributes +
114 private:
116 std::ostream& _output;
117
119 anch::csv::Options _options;
120
122 bool _start;
123 // Attributes -
124
125 // Constructors +
126 public:
135 Writer(std::ostream& output, const anch::csv::Options& options = anch::csv::Options());
136
138 Writer(const Writer&) = delete;
139 // Constructors -
140
141 // Methods +
142 public:
148 void write(std::span<const std::string_view> fields);
149
155 void write(std::initializer_list<std::string_view> fields);
156
162 template<typename... V>
163 void writeRow(const V&... values);
164
172 void write(std::span<const std::string_view> fields, const std::vector<bool>& quoted);
173 // Methods -
174
175 // Accessors +
176 public:
182 const anch::csv::Options& options() const noexcept;
183 // Accessors -
184
185 private:
192 void writeField(std::string_view field, bool quote);
193
194 };
195
196}
197
198#include "csv/impl/writer.hpp"
const anch::csv::Options & options() const noexcept
void write(std::span< const std::string_view > fields, const std::vector< bool > &quoted)
void write(std::span< const std::string_view > fields)
void write(std::initializer_list< std::string_view > fields)
Writer(std::ostream &output, const anch::csv::Options &options=anch::csv::Options())
Writer(const Writer &)=delete
void writeRow(const V &... values)
Definition options.hpp:35