MatchLib
All Classes Namespaces Files Functions Modules Pages
CSVFileReader.h
1/*
2 * Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License")
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef __CSV_FILE_READER__
18#define __CSV_FILE_READER__
19
20#include <string>
21#include <sstream>
22#include <vector>
23#include <math.h>
24#include <boost/assert.hpp>
25
26#include <cstdlib>
27#include <iostream>
28#include <fstream>
29#include <algorithm>
30#include <boost/algorithm/string.hpp>
31
38 std::string fileName;
39 std::string seperator;
40
41 public:
42 CSVFileReader(std::string filename, std::string sep = ",")
43 : fileName(filename), seperator(sep) {}
44
45 std::vector<std::vector<std::string> > readCSV() {
46 std::ifstream file(fileName.c_str());
47 std::vector<std::vector<std::string> > dataList;
48 std::string line = "";
49 while (getline(file, line)) {
50 std::vector<std::string> vec;
51 boost::algorithm::split(vec, line, boost::is_any_of(seperator));
52 dataList.push_back(vec);
53 }
54 file.close();
55 return dataList;
56 }
57};
58
59#endif
A helper class to read CSV files.