34 auto & col_names = this->data->col_names;
35 auto col_pos = col_names->index_of(col_name);
40 throw std::runtime_error(
"Can't find a column named " + col_name);
43 CSV_INLINE CSVRow::operator std::vector<std::string>()
const {
44 std::vector<std::string> ret;
45 for (
size_t i = 0; i < size(); i++)
46 ret.push_back(std::string(this->get_field(i)));
53 std::unordered_map<std::string, std::string> row_map;
54 row_map.reserve(this->
size());
56 for (
size_t i = 0; i < this->
size(); i++) {
57 auto col_name = (*this->data->col_names)[i];
70 const std::vector<std::string>& subset
72 std::unordered_map<std::string, std::string> row_map;
73 row_map.reserve(subset.size());
75 for (
const auto& col_name : subset)
76 row_map[col_name] = this->
operator[](col_name).get<std::string>();
83 return this->get_field_impl(index, this->data);
88 return this->get_field_impl(index, _data);
113#pragma region CSVRow Iterator
130 return std::reverse_iterator<CSVRow::iterator>(this->
end());
134 return std::reverse_iterator<CSVRow::iterator>(this->
begin());
138 CSVRow::iterator::iterator(const CSVRow* _reader,
int _i)
139 : daddy(_reader), data(_reader->data), i(_i) {
140 if (_i < (
int)this->daddy->size())
141 this->field = std::make_shared<CSVField>(
142 CSVField(this->daddy->get_field_safe(_i, this->data)));
144 this->field =
nullptr;
147 CSV_INLINE CSVRow::iterator::reference CSVRow::iterator::operator*()
const {
148 return *(this->field.get());
151 CSV_INLINE CSVRow::iterator::pointer CSVRow::iterator::operator->()
const {
155 CSV_INLINE CSVRow::iterator& CSVRow::iterator::operator++() {
158 if (this->i < (
int)this->daddy->size())
159 this->field = std::make_shared<CSVField>(
160 CSVField(this->daddy->get_field_safe(i, this->data)));
162 this->field =
nullptr;
166 CSV_INLINE CSVRow::iterator CSVRow::iterator::operator++(
int) {
173 CSV_INLINE CSVRow::iterator& CSVRow::iterator::operator--() {
176 this->field = std::make_shared<CSVField>(
177 CSVField(this->daddy->get_field_safe(this->i, this->data)));
181 CSV_INLINE CSVRow::iterator CSVRow::iterator::operator--(
int) {
188 CSV_INLINE CSVRow::iterator CSVRow::iterator::operator+(difference_type n)
const {
190 return CSVRow::iterator(this->daddy, i + (
int)n);
193 CSV_INLINE CSVRow::iterator CSVRow::iterator::operator-(difference_type n)
const {
195 return CSVRow::iterator::operator+(-n);
198#pragma endregion CSVRow Iterator
Data type representing individual CSV values.
bool try_parse_decimal(long double &dVal, const char decimalSymbol='.')
Attempts to parse a decimal (or integer) value using the given symbol, returning true if the value is...
T get()
Returns the value casted to the requested type, performing type checking before.
A random access iterator over the contents of a CSV row.
iterator end() const noexcept
Return an iterator pointing to just after the end of the CSVRow.
std::reverse_iterator< iterator > reverse_iterator
A reverse iterator over the contents of a CSVRow.
std::unordered_map< std::string, std::string > to_unordered_map() const
Convert this CSVRow into an unordered map.
CONSTEXPR size_t size() const noexcept
Return the number of fields in this row.
CSVField operator[](size_t n) const
Return a CSVField object corrsponding to the nth value in the row.
iterator begin() const
Return an iterator pointing to the first field.
#define CSV_INLINE
Helper macro which should be #defined as "inline" in the single header version.
Defines the data type used for storing information about a CSV row.
CONSTEXPR_14 DataType data_type(csv::string_view in, long double *const out, const char decimalSymbol)
Distinguishes numeric from other text values.
The all encompassing namespace.
@ CSV_DOUBLE
Floating point value.
@ CSV_STRING
Non-numeric string.
nonstd::string_view string_view
The string_view class used by this library.