ToolMap
Loading...
Searching...
No Matches
textparser.h
Go to the documentation of this file.
1/***************************************************************************
2 textparser.h
3 Superclass for parsing text, used for importing list of values
4 -------------------
5 copyright : (C) 2007 CREALP Lucien Schreiber
6 ***************************************************************************/
7
8/***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16
17/***************************************************************************/
27#ifndef TEXTPARSER_H
28#define TEXTPARSER_H
29
30// For compilers that support precompilation, includes "wx/wx.h".
31#include <wx/wxprec.h>
32
33// Include wxWidgets' headers
34#ifndef WX_PRECOMP
35#include <wx/wx.h>
36#endif
37
38#include <wx/filename.h>
39#include <wx/textfile.h>
40#include <wx/tokenzr.h>
41
42#define TEXTPARSER_TYPE_TXTFILE _("Text file parser")
43
44enum TEXTPARSER_TYPE {
45 TXTFILE_COMMA = 0,
46 TXTFILE_TAB = 1
47};
48
49static wxString TEXTPARSER_WILDCARDS[] = {wxTRANSLATE("Semi-colon delimited text files (*.csv)|*.csv"),
50 wxTRANSLATE("Tab delimited text files (*.txt)|*.txt")};
51
52static wxString TEXTPARSER_NAME[] = {wxTRANSLATE("Semi-colon delimited text files"),
53 wxTRANSLATE("Tab delimited text files")};
54
55/***************************************************************************/
64class TextParser : public wxObject {
65 protected:
66 wxString m_ParseFileType;
67 wxFileName m_ParseFileName;
68 static int m_iActualLine;
69 int m_LineCount;
70 int m_NbFieldToParse;
71
72 bool CheckParseFileExist();
73
74 public:
75 TextParser();
76
78
79 wxString GetParserType() {
80 return m_ParseFileType;
81 }
82
83 void SetParseFileName(const wxString& myFileName);
84
85 void SetParseFileName(const wxFileName& myFileName);
86
87 virtual bool OpenParseFile(bool bCreate = FALSE);
88
89 virtual int ParseNextLine(wxArrayString& myValues);
90
91 virtual bool WriteNextLine(const wxArrayString& myValues) {
92 return TRUE;
93 }
94
95 virtual bool CloseParseFile();
96
97 int GetActualLineNumber() {
98 return m_iActualLine;
99 }
100
101 void InitActualLineNumber() {
102 m_iActualLine = 0;
103 }
104
105 inline void IncrementActualLineNumber(int iIncrement = 1);
106
107 int GetLineCount() {
108 return m_LineCount;
109 }
110
111 static wxString GetAllSupportedParserWildCards();
112
113 static TextParser* CreateParserBasedOnType(const int& textparser_index, const wxFileName& filename);
114
115 virtual bool CheckFileToParse() {
116 return TRUE;
117 }
118
119 void SetNumberOfFields(int inbfield);
120};
121
122/***************************************************************************/
130 protected:
131 wxTextFile* m_File;
132 wxString m_TextSeparator;
133
134 virtual void InitParserValue();
135
136 bool m_WriteMode;
137
138 public:
140
141 TextParserTxtFile(const wxString& filename);
142
143 TextParserTxtFile(const wxFileName& filename);
144
146
147 virtual bool OpenParseFile(bool bCreate = FALSE);
148
149 virtual bool CloseParseFile();
150
151 virtual int ParseNextLine(wxArrayString& myValues);
152
153 virtual bool WriteNextLine(const wxArrayString& myValues);
154
155 virtual bool CheckFileToParse();
156};
157
159 protected:
160 virtual void InitParserValue();
161
162 public:
164
165 TextParserTxtFileComma(const wxString& filename);
166
168 ;
169 }
170};
171
173 protected:
174 virtual void InitParserValue();
175
176 public:
178
179 TextParserTxtFileTab(const wxString& filename);
180
182 ;
183 }
184};
185
186#endif
Definition textparser.h:158
Definition textparser.h:172
for parsing text based file
Definition textparser.h:129
virtual bool CheckFileToParse()
Check that the file has the correct separator.
Definition textparser.cpp:249
Super-class for parsing different file.
Definition textparser.h:64
void SetNumberOfFields(int inbfield)
Set the number of fields we are looking for.
Definition textparser.cpp:109