ATTPCROOT  0.3.0-alpha
A ROOT-based framework for analyzing data from active target detectors
Public Member Functions | List of all members
CSVRow< T > Class Template Reference

A simple CSV reader w/ modern cpp features. More...

#include <AtCSVReader.h>

Public Member Functions

operator[] (std::size_t index) const
 
std::size_t size () const
 
const std::string & getLine () const
 
void readNextLine (std::istream &stream)
 

Detailed Description

template<typename T>
class CSVRow< T >

A simple CSV reader w/ modern cpp features.

Assumes no commas or newlines in the file except as deliminators (ie you can't escape them) Will work for strings or basic numbers (basically anything that stringstream is overloaded for Skips over entries that don't match the type. i.e. CSVRow<int> will parse "0,tr,-2" into {0,-2} Supports ranged loops, example below

std::ifstream file("input.csv");

for(auto& row : CSVRange<double>(file)) std::cout << "4th Element(" << row[3] << ")" << std::endl; for(auto& row : CSVRange<double>(file)) for(int i = 0; i < row.size(); ++i) std::cout << i + 1 << "th Element(" << row[i] << ")" << std::endl;

Based on: https://stackoverflow.com/questions/1120140/how-can-i-read-and-parse-csv-files-in-c Represents a row of CSV file of type T

Definition at line 29 of file AtCSVReader.h.

Member Function Documentation

◆ getLine()

template<typename T >
const std::string& CSVRow< T >::getLine ( ) const
inline

Definition at line 33 of file AtCSVReader.h.

◆ operator[]()

template<typename T >
T CSVRow< T >::operator[] ( std::size_t  index) const
inline

Definition at line 31 of file AtCSVReader.h.

◆ readNextLine()

template<typename T >
void CSVRow< T >::readNextLine ( std::istream &  stream)
inline

Definition at line 34 of file AtCSVReader.h.

◆ size()

template<typename T >
std::size_t CSVRow< T >::size ( ) const
inline

Definition at line 32 of file AtCSVReader.h.


The documentation for this class was generated from the following file: