AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
reader.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 <cstddef>
25#include <istream>
26#include <optional>
27#include <span>
28#include <string>
29#include <string_view>
30#include <vector>
31
32#include "csv/csvError.hpp"
33#include "csv/options.hpp"
34
35namespace anch::csv {
36
50 class ANCH_CSV_EXPORT Reader {
51
52 // Attributes +
53 private:
55 std::streambuf* _input;
56
58 std::istream& _stream;
59
61 anch::csv::Options _options;
62
64 std::string _pending;
65
67 std::string _buffer;
68
70 std::vector<std::size_t> _ends;
71
73 std::vector<bool> _quoted;
74
76 std::vector<std::string_view> _fields;
77
79 std::vector<std::string> _header;
80
82 std::size_t _line;
83
85 std::size_t _recordLine;
86
88 std::size_t _recordSize;
89
91 std::size_t _size;
92
94 std::size_t _columns;
95 // Attributes -
96
97 // Constructors +
98 public:
108 Reader(std::istream& input, const anch::csv::Options& options = anch::csv::Options());
109
111 Reader(const Reader&) = delete;
112 // Constructors -
113
114 // Methods +
115 public:
123 bool next();
124
132 std::optional<std::size_t> column(std::string_view name) const noexcept;
133 // Methods -
134
135 // Accessors +
136 public:
142 std::span<const std::string_view> fields() const noexcept;
143
149 std::size_t size() const noexcept;
150
158 std::string_view operator[](std::size_t index) const;
159
168 bool quoted(std::size_t index) const;
169
175 std::size_t line() const noexcept;
176
182 const std::vector<std::string>& header() const noexcept;
183
189 const anch::csv::Options& options() const noexcept;
190 // Accessors -
191
192 private:
198 bool read();
199
205 int get();
206
214 bool accept(char expected);
215
222 [[noreturn]] void fail(anch::csv::ErrorCode code, const std::string& message) const;
223
224 };
225
226}
std::size_t line() const noexcept
bool quoted(std::size_t index) const
Reader(const Reader &)=delete
const std::vector< std::string > & header() const noexcept
std::optional< std::size_t > column(std::string_view name) const noexcept
std::size_t size() const noexcept
const anch::csv::Options & options() const noexcept
std::span< const std::string_view > fields() const noexcept
Reader(std::istream &input, const anch::csv::Options &options=anch::csv::Options())
AnCH CSV library namespace.
ErrorCode
Definition csvError.hpp:35
AnCH framework base namespace.
Definition app.hpp:30
Definition options.hpp:35