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#include "csv_format.hpp"
10
11namespace csv {
12 namespace internals {
13 struct ColNames;
14 using ColNamesPtr = std::shared_ptr<ColNames>;
15 using ConstColNamesPtr = std::shared_ptr<const ColNames>;
16
24 struct ColNames {
25 public:
26 ColNames() = default;
27 ColNames(const std::vector<std::string>& names) {
28 set_col_names(names);
29 }
30
31 const std::vector<std::string>& get_col_names() const noexcept;
32 void set_col_names(const std::vector<std::string>&);
33 int index_of(csv::string_view) const;
34
39 csv::ColumnNamePolicy get_policy() const noexcept;
40
41 bool empty() const noexcept { return this->col_names.empty(); }
42 size_t size() const noexcept;
43
45 const std::string& operator[](size_t i) const;
46
47 private:
48 std::vector<std::string> col_names;
49 std::unordered_map<std::string, size_t> col_pos;
51 };
52 }
53}
A standalone header file containing shared code.
Defines an object used to store CSV format settings.
The all encompassing namespace.
ColumnNamePolicy
Determines how column name lookups are performed.
@ EXACT
Case-sensitive match (default)
std::string_view string_view
The string_view class used by this library.
Definition common.hpp:176
A data structure for handling column name information.
Definition col_names.hpp:24
const std::string & operator[](size_t i) const
Retrieve column name by index.
Definition col_names.cpp:55
void set_policy(csv::ColumnNamePolicy policy)
Sets the column name lookup policy.
Definition col_names.cpp:43