All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ColTextParser.hpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of OpenFLUID software
4  Copyright(c) 2007, INRA - Montpellier SupAgro
5 
6 
7  == GNU General Public License Usage ==
8 
9  OpenFLUID is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  OpenFLUID is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
21 
22 
23  == Other Usage ==
24 
25  Other Usage means a use of OpenFLUID that is inconsistent with the GPL
26  license, and requires a written agreement between You and INRA.
27  Licensees for Other Usage of OpenFLUID may use this file in accordance
28  with the terms contained in the written agreement between You and INRA.
29 
30 */
31 
32 
33 
34 /**
35  @file
36 
37  @author Jean-Christophe FABRE <fabrejc@supagro.inra.fr>
38 */
39 
40 #ifndef __COLFILEPARSER_HPP__
41 #define __COLFILEPARSER_HPP__
42 
43 
44 #include <vector>
45 #include <string>
46 
47 #include <openfluid/dllexport.hpp>
48 
49 namespace openfluid { namespace tools {
50 
51 
52 /**
53  Class for column file management and handling
54 */
56 {
57 
58  protected:
59 
60  private:
61 
62  std::string m_Delimiter;
63  std::string m_CommentSymbol;
64 
65  unsigned int m_LinesCount;
66  unsigned int m_ColsCount;
67 
68  std::vector<std::vector<std::string> > m_Contents;
69 
70  std::vector<std::string> tokenizeLine(const std::string& Line);
71 
72  bool checkContents();
73 
74  bool isCommentLineStr(const std::string& LineStr);
75 
76  bool isEmptyLineStr(const std::string& LineStr);
77 
78 
79  public:
80 
81  /**
82  Constructor
83  */
84  ColumnTextParser(const std::string& CommentLineSymbol = "", const std::string& Delimiter = " \t\r\n");
85 
86  /**
87  Destructor
88  */
90 
91 
92  /**
93  Loads a column text file
94  @param[in] Filename the full path of the file to load
95  @return true if everything went fine
96  */
97  bool loadFromFile(const std::string& Filename);
98 
99  /**
100  Parses a one-line delimiter-separated string to set contents
101  ex: "147.2 18 15 25 36 51.3 25.1 15", for 4 columns
102  @param[in] Contents the string to parse
103  @param[in] ColumnsNbr the number of columns (for splitting the sting into lines)
104  @return true if everything went fine
105  */
106  bool setFromString(const std::string& Contents, unsigned int ColumnsNbr);
107 
108  /**
109  Returns the value at a specified row-column, as a string
110  @param[in] Line the line number of the value (first line is 0)
111  @param[in] Column the column number of the value (first column is 0)
112  @return the requested value
113  */
114  std::string getValue(unsigned int Line, unsigned int Column);
115 
116  /**
117  Gets the value at a specified row-column, as a string
118  @param[in] Line the line number of the value (first line is 0)
119  @param[in] Column the column number of the value (first column is 0)
120  @param[out] Value the requested value if exists
121  @return true if the value has been found, false otherwise
122  */
123  bool getStringValue(unsigned int Line, unsigned int Column, std::string *Value);
124 
125  /**
126  Gets the value at a specified row-column, as a long int
127  @param[in] Line the line number of the value (first line is 0)
128  @param[in] Column the column number of the value (first column is 0)
129  @param[out] Value the requested value if exists
130  @return true if the value has been found, false otherwise
131  */
132  bool getLongValue(unsigned int Line, unsigned int Column, long* Value);
133 
134 
135  /**
136  Gets the value at a specified row-column, as a double precision float
137  @param[in] Line the line number of the value (first line is 0)
138  @param[in] Column the column number of the value (first column is 0)
139  @param[out] Value the requested value if exists
140  @return true if the value has been found, false otherwise
141  */
142  bool getDoubleValue(unsigned int Line, unsigned int Column, double* Value);
143 
144  /**
145  Returns the values at a specified line
146  @param[in] Line the line number of the value (first line is 0)
147  @return the requested values
148  */
149  std::vector<std::string> getValues(unsigned int Line);
150 
151  /**
152  Returns the number of lines
153  @return the number of lines
154  */
155  inline unsigned int getLinesCount() const { return m_LinesCount;};
156 
157  /**
158  Returns the number of columns
159  @return the number of columns
160  */
161  inline unsigned int getColsCount() const { return m_ColsCount;};
162 
163  void streamContents(std::ostream& OStream);
164 
165 };
166 
167 } }
168 
169 
170 #endif
171 
172 
Definition: ColTextParser.hpp:55
unsigned int getColsCount() const
Definition: ColTextParser.hpp:161
unsigned int getLinesCount() const
Definition: ColTextParser.hpp:155
#define DLLEXPORT
Definition: dllexport.hpp:51