Vince's CSV Parser
Loading...
Searching...
No Matches
col_names.hpp
1#pragma once
2#include <memory>
3#include <stdexcept>
4#include <unordered_map>
5#include <string>
6#include <vector>
7
8#include "common.hpp"
9
10namespace csv {
11 namespace internals {
12 struct ColNames;
13 using ColNamesPtr = std::shared_ptr<ColNames>;
14
22 struct ColNames {
23 public:
24 ColNames() = default;
25 ColNames(const std::vector<std::string>& names) {
26 set_col_names(names);
27 }
28
29 std::vector<std::string> get_col_names() const;
30 void set_col_names(const std::vector<std::string>&);
31 int index_of(csv::string_view) const;
32
33 bool empty() const noexcept { return this->col_names.empty(); }
34 size_t size() const noexcept;
35
37 const std::string& operator[](size_t i) const;
38
39 private:
40 std::vector<std::string> col_names;
41 std::unordered_map<std::string, size_t> col_pos;
42 };
43 }
44}
A standalone header file containing shared code.
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.
nonstd::string_view string_view
The string_view class used by this library.
Definition common.hpp:99
A data structure for handling column name information.
Definition col_names.hpp:22
const std::string & operator[](size_t i) const
Retrieve column name by index.
Definition col_names.cpp:29