Vince's CSV Parser
Loading...
Searching...
No Matches
col_names.cpp
1#include "col_names.hpp"
2
3namespace csv {
4 namespace internals {
5 CSV_INLINE std::vector<std::string> ColNames::get_col_names() const {
6 return this->col_names;
7 }
8
9 CSV_INLINE void ColNames::set_col_names(const std::vector<std::string>& cnames) {
10 this->col_names = cnames;
11
12 for (size_t i = 0; i < cnames.size(); i++) {
13 this->col_pos[cnames[i]] = i;
14 }
15 }
16
17 CSV_INLINE int ColNames::index_of(csv::string_view col_name) const {
18 auto pos = this->col_pos.find(col_name.data());
19 if (pos != this->col_pos.end())
20 return (int)pos->second;
21
22 return CSV_NOT_FOUND;
23 }
24
25 CSV_INLINE size_t ColNames::size() const noexcept {
26 return this->col_names.size();
27 }
28
29 CSV_INLINE const std::string& ColNames::operator[](size_t i) const {
30 if (i >= this->col_names.size())
31 throw std::out_of_range("Column index out of bounds.");
32
33 return this->col_names[i];
34 }
35 }
36}
#define CSV_INLINE
Helper macro which should be #defined as "inline" in the single header version.
Definition common.hpp:26
CSV_CONST CONSTEXPR_17 OutArray arrayToDefault(T &&value)
Helper constexpr function to initialize an array with all the elements set to value.
The all encompassing namespace.
constexpr int CSV_NOT_FOUND
Integer indicating a requested column wasn't found.
Definition common.hpp:246
nonstd::string_view string_view
The string_view class used by this library.
Definition common.hpp:99
const std::string & operator[](size_t i) const
Retrieve column name by index.
Definition col_names.cpp:29