Classes | Variables

Comma Separated Values
[Utility Library]

Wrapper for comma-separated-value (csv) files. More...

Collaboration diagram for Comma Separated Values:


struct  col_data_t


const char * col_data_t::value

typedef std::vector< col_data_tvec_col_t
 vector of values provided to callback
typedef void(* csv_callback_fn )(void *context, const vec_col_t &data)
 callback for parseCsvStream()
void parseCsvStream (std::istream &in, const VecString &columns, csv_callback_fn callback, void *context)
 parse a stream of lines containing comma-separated values.

Detailed Description

Wrapper for comma-separated-value (csv) files.

This is for special files where: 1) columns are delimited by commas (duh), 2) the first row defines the column names (and column names are unique!), 3) all subsequent rows have the same number of columns

NOTE: the csv parser respects the orders of the input column names! If you specify the ordering as "A,B,C", you'll receive that order in the callback vector, even if the data is actually ordered as "C,A,B". Put another way: applications can assume that data is ordered in the callback data array in the exact same column order that was passed in to the parseCsvStream() call.

Typedef Documentation

typedef std::vector<col_data_t> vec_col_t

vector of values provided to callback

Definition at line 78 of file csv.h.

typedef void(* csv_callback_fn)(void *context,const vec_col_t &data)

callback for parseCsvStream()

Definition at line 81 of file csv.h.

Function Documentation

void parseCsvStream ( std::istream &  in,
const VecString columns,
csv_callback_fn  callback,
void *  context 

parse a stream of lines containing comma-separated values.

The caller must provide:

  • the input stream
  • a vector of the desired fields they would like
  • a callback routine

This routine will:

  • parse the first line as column headers
  • parse each remaining line as comma-separated values
  • based on the header line, find the values the caller asked for
  • put the values in the order the caller asked for
  • call the callback with the values

Definition at line 87 of file csv.cpp.

Variable Documentation

const char* col_data_t::value [inherited]

Definition at line 74 of file csv.h.