AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
csv.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 <cstddef>
23#include <istream>
24#include <iterator>
25#include <ostream>
26#include <ranges>
27#include <vector>
28
29#include "csv/mapper.hpp"
30#include "csv/options.hpp"
31#include "csv/reader.hpp"
32#include "csv/writer.hpp"
33
34namespace anch::csv {
35
49 template<typename T>
50 class Records {
51
52 public:
54 class iterator {
55 private:
57 Records<T>* _records;
58
59 public:
61 using value_type = T;
63 using difference_type = std::ptrdiff_t;
64
66 iterator() noexcept;
67
73 explicit iterator(Records<T>* records) noexcept;
74
80 const T& operator*() const noexcept;
81
89 iterator& operator++();
90
96 void operator++(int);
97
103 bool operator==(std::default_sentinel_t) const noexcept;
104 };
105
106 // Attributes +
107 private:
109 anch::csv::Reader _reader;
110
112 anch::csv::ObjectReader<T> _objects;
113
115 T _value;
116
118 bool _done;
119 // Attributes -
120
121 // Constructors +
122 public:
131 Records(std::istream& input, const anch::csv::Options& options);
132
134 Records(const Records&) = delete;
135 // Constructors -
136
137 // Methods +
138 public:
147
153 std::default_sentinel_t end() const noexcept;
154 // Methods -
155
156 private:
158 void next();
159
160 };
161
177 template<typename T>
178 anch::csv::Records<T> records(std::istream& input, const anch::csv::Options& options = anch::csv::Options());
179
193 template<anch::Described T>
194 void deserialize(std::vector<T>& values, std::istream& input, const anch::csv::Options& options = anch::csv::Options());
195
209 template<std::ranges::input_range R>
210 requires anch::Described<std::remove_cvref_t<std::ranges::range_value_t<R>>>
211 void serialize(const R& values, std::ostream& out, const anch::csv::Options& options = anch::csv::Options());
212
213}
214
215#include "csv/impl/csv.hpp"
Objects reader: records of a Reader are read as T objects.
Definition mapper.hpp:391
Definition reader.hpp:50
Records iterator (input iterator).
Definition csv.hpp:54
T value_type
Definition csv.hpp:61
std::ptrdiff_t difference_type
Definition csv.hpp:63
Objects of a CSV input, read one by one (input range).
Definition csv.hpp:50
std::default_sentinel_t end() const noexcept
Records(std::istream &input, const anch::csv::Options &options)
Type described by an anch::Mapping specialization.
Definition mapping.hpp:66
AnCH CSV library namespace.
anch::csv::Records< T > records(std::istream &input, const anch::csv::Options &options=anch::csv::Options())
void serialize(const R &values, std::ostream &out, const anch::csv::Options &options=anch::csv::Options())
void deserialize(std::vector< T > &values, std::istream &input, const anch::csv::Options &options=anch::csv::Options())
AnCH framework base namespace.
Definition app.hpp:30
Definition options.hpp:35