aboutsummaryrefslogtreecommitdiff
path: root/parse_csv.h
blob: 771e8fec6f8b45408f7ef8ed4545859b5e34c384 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#ifndef PARSE_CSV__H
#define  PARSE_CSV__H
#include <vector>

struct qstring : public std::string {
  int q;                // was explicitly quoted
// Constructors:
  qstring(): q(0) {}
  qstring(int const _q): q(_q) {}
  qstring(std::string const &s): std::string(s), q(0) {}
  qstring(std::string const &s, int const _q): std::string(s), q(_q) {}
};

// Helper functions, not class member functions:
// Simple case, do nothing:
template<class T> inline void set_q(T& target, int const val) {}
template<class T> inline int  get_q(T const& target) {return 0;}

// Specialization: Fancy case, actually act on q:
template<> inline void set_q(qstring& target, int const val)  {
  target.q = val;
}

template<> inline int  get_q(qstring const& target){
  return target.q;
}

template <class datum = qstring>
std::vector<datum> readCSVRow(std::istream& input);

template <class datum = qstring>
std::vector<std::vector<datum> > readCSV(std::istream &in);

template<class datum = qstring>
int count_header(std::vector<std::vector<datum> > const aoa);

#endif