CsvReader.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T),
5 * Karlsruhe Institute of Technology (KIT), all rights reserved.
6 *
7 * ArmarX is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * ArmarX is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * @author Simon Ottenhaus (simon dot ottenhaus at kit dot edu)
20 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
21 * GNU General Public License
22 */
23
24#pragma once
25
26#include <fstream>
27#include <iostream>
28#include <map>
29#include <memory>
30#include <sstream>
31#include <string>
32#include <vector>
33
34namespace armarx
35{
36 class CsvReader;
37 using CsvReaderPtr = std::shared_ptr<CsvReader>;
38
40 {
41 public:
42 CsvReader(const std::string& filename, bool hasHeader);
43 bool read(std::vector<std::string>& row);
44 bool read(std::vector<float>& row);
45 bool read(std::map<std::string, float>& row);
46 std::vector<std::vector<float>> readAllFloatList();
47 std::vector<std::map<std::string, float>> readAllFloatMap();
48 std::map<std::string, std::vector<float>> readAllColumnsFloatMap();
49 std::vector<std::string> getHeader();
50 bool isEof();
51
52 private:
53 bool readLine(std::string& line);
54 std::ifstream file;
55 std::vector<std::string> header;
56 std::string separator;
57 };
58} // namespace armarx
std::vector< std::vector< float > > readAllFloatList()
Definition CsvReader.cpp:89
std::vector< std::string > getHeader()
CsvReader(const std::string &filename, bool hasHeader)
Definition CsvReader.cpp:30
bool read(std::vector< std::string > &row)
Definition CsvReader.cpp:43
std::vector< std::map< std::string, float > > readAllFloatMap()
std::map< std::string, std::vector< float > > readAllColumnsFloatMap()
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::shared_ptr< CsvReader > CsvReaderPtr
Definition CsvReader.h:37