trase
CSVDownloader.hpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2018, University of Oxford.
3 All rights reserved.
4 
5 University of Oxford means the Chancellor, Masters and Scholars of the
6 University of Oxford, having an administrative office at Wellington
7 Square, Oxford OX1 2JD, UK.
8 
9 This file is part of trase.
10 
11 Redistribution and use in source and binary forms, with or without
12 modification, are permitted provided that the following conditions are met:
13 * Redistributions of source code must retain the above copyright notice, this
14  list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright notice,
16  this list of conditions and the following disclaimer in the documentation
17  and/or other materials provided with the distribution.
18 * Neither the name of the copyright holder nor the names of its
19  contributors may be used to endorse or promote products derived from
20  this software without specific prior written permission.
21 
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33 
35 
36 #ifndef _CSVDownloader_H_
37 #define _CSVDownloader_H_
38 
39 #include <map>
40 #include <string>
41 #include <vector>
42 
43 namespace trase {
44 
46 public:
49  using data_t = std::map<std::string, std::vector<std::string>>;
50 
52  CSVDownloader();
53 
54  ~CSVDownloader();
55 
62  data_t download(const std::string &url,
63  const std::vector<std::string> &labels = {});
64 
66  void set_delim(const char arg) { m_delim = arg; }
67 
68 private:
70  CSVDownloader::data_t parse_csv(std::stringstream &out,
71  const std::vector<std::string> &labels);
72 
74  void *m_curl;
75 
77  char m_delim;
78 };
79 
80 } // namespace trase
81 
82 #endif // _CSVDownloader_H_
std::map< std::string, std::vector< std::string > > data_t
columns of csv file returned as a map from string label to a column of data (vector of strings) ...
Definition: CSVDownloader.hpp:49
data_t download(const std::string &url, const std::vector< std::string > &labels={})
download a csv file at the url given by url
Definition: CSVDownloader.cpp:112
void set_delim(const char arg)
set the delimiter for the csv file format
Definition: CSVDownloader.hpp:66
Definition: CSVDownloader.hpp:45
Definition: Backend.cpp:39
CSVDownloader()
constructs a csv downloader with default delimiter of &#39;,&#39;
Definition: CSVDownloader.cpp:63