Vince's CSV Parser
Loading...
Searching...
No Matches
quote_arena.hpp
Go to the documentation of this file.
1
5#pragma once
6
7#include <algorithm>
8#include <cassert>
9
10#include "../common.hpp"
11#include "block_arena.hpp"
12
13namespace csv {
14 namespace internals {
15 namespace memory {
17 public:
18 RawCSVQuoteArena() : arena_(internals::PAGE_SIZE) {}
19
20 CSVChunkIndex append(csv::string_view bytes) {
21 if (bytes.empty()) {
22 return this->checked_offset(this->arena_.size());
23 }
24
25 auto allocation = this->arena_.allocate_contiguous(bytes.size());
26 std::copy(bytes.begin(), bytes.end(), allocation.data);
27 return allocation.offset;
28 }
29
30 RawCSVBlockArena<char>::Allocation allocate_contiguous(size_t length) {
31 return this->arena_.allocate_contiguous(length);
32 }
33
34 csv::string_view view(size_t start, size_t length) const {
35 return this->arena_.view(start, length);
36 }
37
38 void reserve_for_source_size(size_t source_size) {
39 const size_t block_capacity = (source_size + internals::PAGE_SIZE - 1) / internals::PAGE_SIZE;
40 this->arena_.reserve_blocks(block_capacity + 1);
41 }
42
43 private:
45
46 CSVChunkIndex checked_offset(size_t value) const noexcept {
47 assert(value <= CSV_CHUNK_INDEX_MAX);
48 return static_cast<CSVChunkIndex>(value);
49 }
50 };
51 }
52 }
53}
Stable append-only arenas used by parser backing storage.
Borrow a row and error state for synchronous, single-pass field access.
std::uint32_t CSVChunkIndex
Type used to represent the location of a CSV byte within a larger chunk.
Definition common.hpp:419
The all encompassing namespace.
std::string_view string_view
The string_view class used by this library.
Definition common.hpp:182