aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
gum::learning::CSVParser Class Referencefinal

Class for fast parsing of CSV file (never more than one line in application memory). More...

#include <agrum/base/database/CSVParser.h>

Public Member Functions

Constructors / Destructors
 CSVParser (std::istream &in, const std::string &filename, const std::string &delimiter=",", const char commentmarker='#', const char quoteMarker='"')
 default constructor
virtual ~CSVParser ()
 destructor
Accessors / Modifiers
bool next ()
 gets the next line of the csv stream and parses it
const std::vector< std::string > & current () const
 returns the current parsed line
std::size_t nbLine () const
 returns the current line number within the stream
void useNewStream (std::istream &in, const std::string &delimiter=",", const char commentmarker='#', const char quoteMarker='"')
 reopens a new input stream to parse

Detailed Description

Class for fast parsing of CSV file (never more than one line in application memory).

Typical use:

// open the CSV file
std::string filename="foo.csv"
std::ifstream in(filename.c_str());
// read each line in the CSV file
while (csvp.next()) {
csvp.current ();
}
in.close();
Class for fast parsing of CSV file (never more than one line in application memory).
Definition CSVParser.h:77

Definition at line 77 of file CSVParser.h.

Constructor & Destructor Documentation

◆ CSVParser()

gum::learning::CSVParser::CSVParser ( std::istream & in,
const std::string & filename,
const std::string & delimiter = ",",
const char commentmarker = '#',
const char quoteMarker = '"' )

default constructor

Parameters
inan input stream containing the CSV
delimiterthe character that acts as the column separator in the CSV
commentmarkerthe character that marks the beginning of a comment
quoteMarkerthe character that is used to quote the sentences in the CSV

◆ ~CSVParser()

virtual gum::learning::CSVParser::~CSVParser ( )
virtual

destructor

Member Function Documentation

◆ current()

const std::vector< std::string > & gum::learning::CSVParser::current ( ) const

returns the current parsed line

Exceptions
NullElementis raised if there is no data

◆ nbLine()

std::size_t gum::learning::CSVParser::nbLine ( ) const

returns the current line number within the stream

◆ next()

bool gum::learning::CSVParser::next ( )

gets the next line of the csv stream and parses it

Returns
false if there is no next line

◆ useNewStream()

void gum::learning::CSVParser::useNewStream ( std::istream & in,
const std::string & delimiter = ",",
const char commentmarker = '#',
const char quoteMarker = '"' )

reopens a new input stream to parse


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