Flow123d  master-f44eb46
csv_tokenizer.hh
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file csv_tokenizer.hh
15  * @brief
16  */
17 
18 #ifndef CSV_TOKENIZER_HH_
19 #define CSV_TOKENIZER_HH_
20 
21 #include <system/tokenizer.hh>
22 
23 /**
24  * @brief Simple class for parsing CSV files.
25  *
26  * CSV tokenizer use backslash '\\' as the escape character, double quotas '"' as quotation
27  * character, and comma ',' as the separator of tokens.
28  */
29 class CSVTokenizer : public Tokenizer {
30 public:
31  /**
32  * Opens a file given by file path @p fp. And construct the CSV tokenizer over the
33  * input stream for this file.
34  */
35  CSVTokenizer(const FilePath &fp, std::string field_separator = ",");
36 
37  /**
38  * @brief Construct the CSV tokenizer over given input stream @p in.
39  *
40  * @code CSVTokenizer( ifstream("my_file") );
41  *
42  */
43  CSVTokenizer(std::istream &in, std::string field_separator = ",");
44 
45  /// Get count of lines in CSV file.
46  unsigned int get_n_lines();
47 
48  /**
49  * @brief Skip header lines of CSV file.
50  *
51  * @param n_head_lines number of head lines given by user
52  */
53  void skip_header(unsigned int n_head_lines);
54 
55  /// Cast token on actual position to integer value and return its.
56  int get_int_val();
57 
58  /// Cast token on actual position to double value and return its.
59  double get_double_val();
60 
61  /// Return string value of token on actual position.
62  std::string get_string_val();
63 };
64 
65 #endif /* CSV_TOKENIZER_HH_ */
Dedicated class for storing path to input and output files.
Definition: file_path.hh:54