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 <memory>
27 #include <sstream>
28 #include <string>
29 #include <map>
30 #include <iostream>
31 #include <fstream>
32 #include <vector>
33 
34 namespace armarx
35 {
36  class CsvReader;
37  using CsvReaderPtr = std::shared_ptr<CsvReader>;
38 
39  class CsvReader
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 }
59 
armarx::CsvReader::getHeader
std::vector< std::string > getHeader()
Definition: CsvReader.cpp:121
armarx::CsvReader::isEof
bool isEof()
Definition: CsvReader.cpp:127
armarx::CsvReader::readAllFloatList
std::vector< std::vector< float > > readAllFloatList()
Definition: CsvReader.cpp:85
armarx::CsvReader
Definition: CsvReader.h:39
armarx::CsvReaderPtr
std::shared_ptr< CsvReader > CsvReaderPtr
Definition: CsvReader.h:37
armarx::CsvReader::readAllColumnsFloatMap
std::map< std::string, std::vector< float > > readAllColumnsFloatMap()
Definition: CsvReader.cpp:107
filename
std::string filename
Definition: VisualizationRobot.cpp:83
armarx::CsvReader::readAllFloatMap
std::vector< std::map< std::string, float > > readAllFloatMap()
Definition: CsvReader.cpp:96
armarx::CsvReader::read
bool read(std::vector< std::string > &row)
Definition: CsvReader.cpp:42
armarx::CsvReader::CsvReader
CsvReader(const std::string &filename, bool hasHeader)
Definition: CsvReader.cpp:29
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28