ip2cparser.h
1 //------------------------------------------------------------------------------
2 // ip2cparser.h
3 //------------------------------------------------------------------------------
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301, USA.
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2009 "Blzut3" <admin@maniacsvault.net>
22 //------------------------------------------------------------------------------
23 #ifndef __IP2CPARSER_H__
24 #define __IP2CPARSER_H__
25 
26 #include "ip2c.h"
27 #include <QMutex>
28 #include <QThread>
29 
55 class IP2CParser : public QObject
56 {
57  Q_OBJECT
58 
59  public:
61 
65  IP2C* ip2c() const { return pTargetDatabase; }
66 
71  bool isParsing() const { return bIsParsing; }
72 
73  bool readDatabase(const QString& filePath);
74  void readDatabaseThreaded(const QString& filePath);
75 
76  signals:
83  void parsingFinished(bool bSuccess);
84 
85  protected:
92  {
93  public:
96 
97  private:
98  IP2CParser* pParser;
99  };
100 
101  class ParsingThread : public QThread
102  {
103  public:
104  bool bSuccessState;
105  QString filePath;
106  IP2CParser* pParser;
107 
108 
109  ParsingThread(IP2CParser* pParser, const QString& filePath)
110  {
111  bSuccessState = false;
112  this->filePath = filePath;
113  this->pParser = pParser;
114  }
115 
116  void run();
117  };
118 
122  typedef QHash<QString, QList<IP2C::IP2CData> > Countries;
123  typedef QHash<QString, QList<IP2C::IP2CData> >::iterator CountriesIt;
124  typedef QHash<QString, QList<IP2C::IP2CData> >::const_iterator CountriesConstIt;
125 
126  bool bIsParsing;
127  ParsingThread* currentParsingThread;
128 
137 
138  QMutex thisLock;
139 
140  bool doReadDatabase(const QString& filePath);
141  bool readDatabaseVersion2(const QByteArray& dataArray);
142 
143  protected slots:
144  void parsingThreadFinished();
145 };
146 
147 #endif
Sets states for IP2C when being constructed and destructed.
Definition: ip2cparser.h:91
IP2C * pTargetDatabase
Database to which the IP2C parser will save the data it retrieves from IP2C file. ...
Definition: ip2cparser.h:136
bool isParsing() const
For multi-threading purposes. If this is true it is not recommended to delete this object nor the und...
Definition: ip2cparser.h:71
IP to Country database handler.
Definition: ip2c.h:48
QHash< QString, QList< IP2C::IP2CData > > Countries
Definition: ip2cparser.h:122
void parsingFinished(bool bSuccess)
A signal emitted when parser finishes its job.
IP2C * ip2c() const
Retrieves the IP2C database this parser operates on.
Definition: ip2cparser.h:65