ClockWork DB CoreAPI
1.0.48
Abstract Time Series and Storage/Management Library
Loading...
Searching...
No Matches
csv_file.hpp
1
#ifndef HAVE_TOM__CSV_FILE_HPP
2
#define HAVE_TOM__CSV_FILE_HPP
3
4
#include <tom-util/defines.hpp>
5
#include <tom-util/csv_threaded_stream_parser.hpp>
6
#include <tom-util/csv_column.hpp>
7
#include <tom-util/scalar.hpp>
8
9
#include <map>
10
#include <fstream>
11
#include <stdexcept>
12
13
namespace
tom {
14
15
class
TOM_UTIL_API
csv_file
:
private
std::ifstream
16
{
17
public
:
18
typedef
std::pair<
const
tom::string
,
19
named_ordinal_observation
*> column_pair_type;
20
typedef
std::map<
tom::string
,
21
named_ordinal_observation
*,
22
std::less<tom::string> > column_map_type;
23
typedef
column_map_type::iterator column_iterator;
24
typedef
column_map_type::const_iterator const_column_iterator;
25
26
csv_file
(
const
String
&path,
char
delim=
','
,
char
escape =
'\\'
,
char
quote =
'\"'
) :
27
std::ifstream( path.value().c_str() ), m_parser( *
this
, delim, escape, quote), m_initialized(
false
) {init();}
28
csv_file
(
const
String
&path,
bool
autoInitOn) :
29
std::ifstream( path.value().c_str() ), m_parser( *
this
), m_initialized(
false
) {
if
(autoInitOn) init();}
30
virtual
~csv_file
() { }
31
32
const
named_ordinal_observation
&
33
addColumn(
const
observation
&name,
const
observation
&pos,
34
const
observation
&type,
const
observation
&missing,
35
const
observation
& image );
36
37
bool
nextLine();
38
39
void
init(
int
skipLines);
40
void
init(
int
skipLines,
char
delim);
41
void
init(
int
skipLines,
const
std::vector<int> &offsets);
42
43
const_column_iterator
44
begin()
const
{
return
column_map.begin(); }
45
46
column_iterator
47
begin() {
return
column_map.begin(); }
48
49
const_column_iterator
50
end()
const
{
return
column_map.end(); }
51
52
column_iterator
53
end() {
return
column_map.end(); }
54
const
observation
&
55
operator[](
const
observation
& name );
56
const
observation
&
57
getColumn(
const
observation
& name );
// throw(std::runtime_error);
58
59
protected
:
60
61
template
<
typename
T>
62
const
named_ordinal_observation
&
63
add_column(
const
observation
&name,
const
observation
&pos,
64
const
observation
&missing,
const
observation
& image);
65
66
csv_threaded_stream_parser
m_parser;
67
column_map_type column_map;
68
bool
m_initialized;
69
void
init();
70
71
};
72
73
template
<
typename
T>
74
const
named_ordinal_observation
&
75
csv_file::add_column(
const
observation
&name,
const
observation
&pos,
76
const
observation
&missing,
const
observation
& image)
77
{
78
csv_column<T>
*col =
new
csv_column<T>
(name, pos, missing, image);
79
column_map[ col->name() ] = col;
80
return
*col;
81
}
82
83
}
// end tom namespace
84
85
#endif
tom::String
Definition
string.hpp:15
tom::csv_column
Definition
csv_column.hpp:25
tom::csv_file
Definition
csv_file.hpp:16
tom::csv_threaded_stream_parser
Definition
csv_threaded_stream_parser.hpp:13
tom::named_ordinal_observation
Definition
csv_column.hpp:13
tom::observation
Definition
observation.hpp:13
tom::value_types::string
Definition
value_types.hpp:96
tom-util
csv_file.hpp
Generated on Wed Oct 8 2025 10:10:36 for ClockWork DB CoreAPI by
1.9.8