diff options
Diffstat (limited to 'parse_csv.h')
-rw-r--r-- | parse_csv.h | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/parse_csv.h b/parse_csv.h new file mode 100644 index 0000000..362c478 --- /dev/null +++ b/parse_csv.h @@ -0,0 +1,34 @@ +#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); + +#endif |