csv-parser 1.1.0
Csv::Parser (csv-parser)
Loading...
Searching...
No Matches
csv_policies.h
Go to the documentation of this file.
1/**************************************************************************
2Copyright: (C) 2025 Alexander Shaduri
3License: Zlib
4***************************************************************************/
5
6#ifndef CSV_POLICIES_H
7#define CSV_POLICIES_H
8
9#include "csv_cell.h" // CellTypeHint
10
11#include <optional>
12#include <string_view>
13#include <type_traits>
14#include <limits>
15
16
24namespace Csv {
25
26
32
35 [[nodiscard]] static constexpr bool useEmptyCellType() noexcept
36 {
37 return true;
38 }
39
40
43 template<typename Number>
44 static std::optional<Number> readNumber(std::string_view cell)
45 {
47 }
48
49
52 template<typename CellT>
53 static constexpr CellT create(std::string_view cell, CellTypeHint hint)
54 {
55 // The types here are the same as in readNumber()
56 if constexpr(std::is_arithmetic_v<CellT>) {
57 // quiet_NaN() returns 0 for integral types
59 .value_or(std::numeric_limits<CellT>::quiet_NaN());
60 } else {
61 // Cell* classes
63 }
64 }
65};
66
67
68
75
78 [[nodiscard]] static constexpr bool useEmptyCellType() noexcept
79 {
80 return true;
81 }
82
83
86 template<typename Number>
87 static constexpr std::optional<Number> readNumber(std::string_view cell)
88 {
90 }
91
92
95 template<typename CellT>
96 static constexpr CellT create(std::string_view cell, CellTypeHint hint)
97 {
98 // The types here are the same as in readNumber()
99 if constexpr(std::is_arithmetic_v<CellT>) {
100 // quiet_NaN() returns 0 for integral types
102 .value_or(std::numeric_limits<CellT>::quiet_NaN());
103 } else {
104 // Cell* classes
106 }
107 }
108};
109
110
111
112} // end ns
113
114
115
116#endif
Various Cell-related classes.
CellTypeHint
Type hint associated with the cell to determine the type of the cell value.
Definition csv_cell.h:32
This policy controls the behavior of the parser.
Definition csv_policies.h:31
static std::optional< Number > readNumber(std::string_view cell)
Try to read a numeric value from string data.
Definition csv_policies.h:44
static constexpr bool useEmptyCellType() noexcept
If true, empty cell type is a separate type from (empty) string.
Definition csv_policies.h:35
static constexpr CellT create(std::string_view cell, CellTypeHint hint)
Create an object of type CellT from cell contents represented as string_view.
Definition csv_policies.h:53
This policy controls the behavior of the parser.
Definition csv_policies.h:74
static constexpr std::optional< Number > readNumber(std::string_view cell)
Try to read a numeric value from string data.
Definition csv_policies.h:87
static constexpr CellT create(std::string_view cell, CellTypeHint hint)
Create an object of type CellT from cell contents represented as string_view.
Definition csv_policies.h:96
static constexpr bool useEmptyCellType() noexcept
If true, empty cell type is a separate type from (empty) string.
Definition csv_policies.h:78