aGrUM  0.13.2
gum::learning::CSVParser< ALLOC > Class Template Reference

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

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

Public Member Functions

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

Public Types

using allocator_type = ALLOC< std::string >
 type for the allocators passed in arguments of methods More...
 

Detailed Description

template<template< typename > class ALLOC = std::allocator>
class gum::learning::CSVParser< ALLOC >

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();

Definition at line 78 of file CSVParser.h.

Member Typedef Documentation

template<template< typename > class ALLOC = std::allocator>
using gum::learning::CSVParser< ALLOC >::allocator_type = ALLOC<std::string>

type for the allocators passed in arguments of methods

Definition at line 82 of file CSVParser.h.

Constructor & Destructor Documentation

template<template< typename > class ALLOC = std::allocator>
gum::learning::CSVParser< ALLOC >::CSVParser ( std::istream &  in,
const std::string &  delimiter = ",",
const char  commentmarker = '#',
const char  quoteMarker = '"',
const allocator_type alloc = allocator_type () 
)

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
allocthe allocator used by all the methods
template<template< typename > class ALLOC = std::allocator>
virtual gum::learning::CSVParser< ALLOC >::~CSVParser ( )
virtual

destructor

Member Function Documentation

template<template< typename > class ALLOC = std::allocator>
const std::vector<std::string,ALLOC<std::string> >& gum::learning::CSVParser< ALLOC >::current ( ) const

returns the current parsed line

Exceptions
NullElementis raised if there is no data
template<template< typename > class ALLOC = std::allocator>
const std::size_t gum::learning::CSVParser< ALLOC >::nbLine ( ) const

returns the current line number within the stream

template<template< typename > class ALLOC = std::allocator>
bool gum::learning::CSVParser< ALLOC >::next ( )

gets the next line of the csv stream and parses it

Returns
false if there is no next line
template<template< typename > class ALLOC = std::allocator>
void gum::learning::CSVParser< ALLOC >::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: