ip2cparser.h
1 //------------------------------------------------------------------------------
2 // ip2cparser.h
3 //------------------------------------------------------------------------------
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library 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 GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; 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 Braden "Blzut3" Obrzut <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
66  {
67  return pTargetDatabase;
68  }
69 
74  bool isParsing() const
75  {
76  return bIsParsing;
77  }
78 
79  bool readDatabase(const QString &filePath);
80  void readDatabaseThreaded(const QString &filePath);
81 
82 signals:
89  void parsingFinished(bool bSuccess);
90 
91 protected:
98  {
99  public:
102 
103  private:
104  IP2CParser *pParser;
105  };
106 
107  class ParsingThread : public QThread
108  {
109  public:
110  bool bSuccessState;
111  QString filePath;
112  IP2CParser *pParser;
113 
114 
115  ParsingThread(IP2CParser *pParser, const QString &filePath)
116  {
117  bSuccessState = false;
118  this->filePath = filePath;
119  this->pParser = pParser;
120  }
121 
122  void run() override;
123  };
124 
128  typedef QHash<QString, QList<IP2C::IP2CData> > Countries;
129  typedef QHash<QString, QList<IP2C::IP2CData> >::iterator CountriesIt;
130  typedef QHash<QString, QList<IP2C::IP2CData> >::const_iterator CountriesConstIt;
131 
132  bool bIsParsing;
133  ParsingThread *currentParsingThread;
134 
143 
144  QMutex thisLock;
145 
146  bool doReadDatabase(const QString &filePath);
147  bool readDatabaseVersion2(const QByteArray &dataArray);
148 
149 protected slots:
150  void parsingThreadFinished();
151 };
152 
153 #endif
Sets states for IP2C when being constructed and destructed.
Definition: ip2cparser.h:97
IP2C * pTargetDatabase
Database to which the IP2C parser will save the data it retrieves from IP2C file. ...
Definition: ip2cparser.h:142
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:74
IP to Country database handler.
Definition: ip2c.h:48
QHash< QString, QList< IP2C::IP2CData > > Countries
Definition: ip2cparser.h:128
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