Vince's CSV Parser
col_names.cpp
1 #include "col_names.hpp"
2 
3 namespace 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  }
30 }
#define CSV_INLINE
Helper macro which should be #defined as "inline" in the single header version.
Definition: common.hpp:26
The all encompassing namespace.
constexpr int CSV_NOT_FOUND
Integer indicating a requested column wasn't found.
Definition: common.hpp:207
nonstd::string_view string_view
The string_view class used by this library.
Definition: common.hpp:75