aGrUM
3.2.0
a C++ library for (probabilistic) graphical models
Toggle main menu visibility
CSVParser.h
Go to the documentation of this file.
1
/***************************************************************************
2
* Copyright (c) 2005-2024 by Christophe GONZALES(_at_AMU) and Pierre-Henri WUILLEMIN(_at_LIP6) *
3
* info_at_agrum_dot_org *
4
* *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
9
* *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
14
* *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19
***************************************************************************/
42
43
#ifndef GUM_CSV_PARSER_H
44
#define GUM_CSV_PARSER_H
45
46
#include <istream>
47
#include <string>
48
#include <string_view>
49
#include <vector>
50
51
#include <
agrum/agrum.h
>
52
53
namespace
gum
{
54
55
namespace
learning
{
56
78
class
GUM_SHARED_PUBLIC
CSVParser
final {
79
public
:
80
// ##########################################################################
82
// ##########################################################################
84
86
93
CSVParser
(std::istream& in,
94
const
std::string& filename,
95
const
std::string& delimiter =
","
,
96
const
char
commentmarker =
'#'
,
97
const
char
quoteMarker =
'"'
);
98
100
virtual
~CSVParser
();
101
103
104
105
// ########################################################################
107
// ########################################################################
109
111
113
bool
next
();
114
116
118
const
std::vector< std::string >&
current
()
const
;
119
121
std::size_t
nbLine
()
const
;
122
124
void
useNewStream
(std::istream& in,
125
const
std::string& delimiter =
","
,
126
const
char
commentmarker =
'#'
,
127
const
char
quoteMarker =
'"'
);
128
130
131
132
#ifndef DOXYGEN_SHOULD_SKIP_THIS
133
134
private
:
135
void
_getNextTriplet_(std::string_view str,
136
std::size_t& first_letter_token,
137
std::size_t& next_token,
138
std::size_t& last_letter_token,
139
std::size_t from)
const
;
140
141
void
_tokenize_(std::string_view str);
142
143
std::size_t _correspondingQuoteMarker_(std::string_view str, std::size_t pos)
const
;
144
145
146
std::string _line_;
147
std::string _delimiter_;
148
std::string _spaces_;
149
std::string _delimiterPlusSpaces_;
150
std::size_t _nbLine_;
151
char
_commentMarker_;
152
char
_quoteMarker_;
153
bool
_emptyData_;
154
155
std::istream* _instream_;
156
std::vector< std::string > _data_;
157
const
std::string _filename_;
158
159
#endif
/* DOXYGEN_SHOULD_SKIP_THIS */
160
};
161
162
}
// namespace learning
163
164
}
// namespace gum
165
167
#ifndef GUM_NO_INLINE
168
#include <
agrum/base/database/CSVParser_inl.h
>
169
#endif
/* GUM_NO_INLINE */
170
171
#endif
// GUM_CSV_PARSER_H
CSVParser_inl.h
agrum.h
gum::learning::CSVParser::CSVParser
CSVParser(std::istream &in, const std::string &filename, const std::string &delimiter=",", const char commentmarker='#', const char quoteMarker='"')
default constructor
gum::learning::CSVParser::useNewStream
void useNewStream(std::istream &in, const std::string &delimiter=",", const char commentmarker='#', const char quoteMarker='"')
reopens a new input stream to parse
gum::learning::CSVParser::next
bool next()
gets the next line of the csv stream and parses it
gum::learning::CSVParser::nbLine
std::size_t nbLine() const
returns the current line number within the stream
gum::learning::CSVParser::~CSVParser
virtual ~CSVParser()
destructor
gum::learning::CSVParser::current
const std::vector< std::string > & current() const
returns the current parsed line
gum::learning
include the inlined functions if necessary
Definition
CSVParser.h:55
gum
gum is the global namespace for all aGrUM entities
Definition
agrum.h:46
aGrUM
3.2.0
© PHW&CG&others - 2022
DoXyGeN 1.18.0