gSAFE  1.3.8
xbio.h
1 /*
2  gSAFE - LIB
3  general Sql dAtabase FrontEnd
4 
5  (C) 2011 Peter Deak (hyper80@gmail.com)
6 
7  License: GPLv2 http://www.gnu.org/licenses/gpl-2.0.html
8 
9  XBase Import/Export lib
10  xbio.h
11 */
12 
13 /* This module is not depends from gSAFE
14  * Can be used separatedly (Just add xbio.h/xbio.cpp to your project)
15  *
16  * WARNING: This file's .cpp is depends on XBase library (http://linux.techass.com/projects/xdb/)
17  * If you don't want to use the XBase support just remove
18  * the xbio* files from your project, or undefine (remove) the ENABLE_XBASE_SUPPORT macro!
19  */
20 
21 #ifdef ENABLE_XBASE_SUPPORT
22 
23 #ifndef GSAFE_XBASE_IO_H
24 #define GSAFE_XBASE_IO_H
25 
26 #include <QtCore>
27 
29 /* @{ */
30 
31 #define CPCONV_BUFFERLENGTH 256
32 #define XBASESCHEMA_MAXFIELD 64
33 
34 class xbXBase;
35 class xbDbf;
36 class xbSchema;
37 
38 enum HXBaseFieldType {
39  Error,
40  Numeric,
41  Char,
42  Date,
43  Float,
44  Logical,
45  Memo
46  };
47 
51 {
52 
53 public:
54  HCodepageConvert(void) {}
55 
56  virtual QString conv_from(char * from) = 0;
57  virtual void conv_to(QString from,char * buffer,int bufflen) = 0;
58 };
59 
62 {
63 
64 public:
65  HCodepage852(void) {}
66 
67  virtual QString conv_from(char * from);
68  virtual void conv_to(QString from,char * buffer,int bufflen);
69 };
70 
73 {
74 
75 public:
76  HCodepage850(void) {}
77 
78  virtual QString conv_from(char * from);
79  virtual void conv_to(QString from,char * buffer,int bufflen);
80 };
81 
86 class HXBaseFileHandler : public QObject
87 {
88  Q_OBJECT
89 
90 protected:
92  char *buffer;
93  xbXBase *xbase;
94  xbDbf *dbf;
95  bool opened;
96  bool deleteconvertobject;
97 
98 public:
101  HXBaseFileHandler(HCodepageConvert *conv,bool deletecobj=false);
103  ~HXBaseFileHandler(void);
104 
106  int fieldCount(void);
108  QString fieldName(int n);
110  HXBaseFieldType fieldType(int n);
112  long recordCount(void);
113 
114 signals:
116  void errorSignal(QString error);
117 };
118 
135 {
136  Q_OBJECT
137 
138 public:
143  HXBaseFileReader(HCodepageConvert *conv,bool deletecobj=false);
145  ~HXBaseFileReader(void);
146 
150  int open(QString name);
152  int close(void);
153 
157  int toRecord(long idx);
169  int firstRecord(void);
173  int lastRecord(void);
177  int nextRecord(void);
181  int prevRecord(void);
183  long getCurrentRecordIdx(void);
184 
186  QString getFieldStr (QString fname);
188  long getFieldDecimal(QString fname);
190  double getFieldFloat (QString fname);
192  bool getFieldBool (QString fname);
194  QDate getFieldDate (QString fname);
195 
196 
197  QString getCellStr (long rec,QString fname);
198  long getCellDecimal(long rec,QString fname);
199  double getCellFloat (long rec,QString fname);
200  bool getCellBool (long rec,QString fname);
201  QDate getCellDate (long rec,QString fname);
202 
203 };
204 
230 {
231  Q_OBJECT
232 
233 protected:
234  xbSchema *schema;
235  int defined_fnum;
236 
237  void setLastDefinedField(int idx);
238 
239 public:
244  HXBaseFileWriter(HCodepageConvert *conv,bool deletecobj=false);
246  ~HXBaseFileWriter(void);
247 
248 public:
256  void defineField(QString name,HXBaseFieldType type,int length=0,int nofdecimals=0);
257 
262  int create(QString name,int version);
266  int open(QString name);
268  int close(void);
269 
271  int resetRecord(void);
273  int appendRecord(void);
274 
276  int setFieldStr (QString fname,QString str);
278  int setFieldDecimal(QString fname,long decimal);
280  int setFieldFloat (QString fname,double val);
282  int setFieldBool (QString fname,bool logical);
284  int setFieldDate (QString fname,QDate date);
285 
286 };
287 
288 /* @} */
289 
290 #endif // GSAFE_XBASE_IO_H
291 
292 #endif // ENABLE_XBASE_SUPPORT
int resetRecord(void)
Definition: xbio.cpp:493
HXBaseFileWriter(HCodepageConvert *conv, bool deletecobj=false)
Definition: xbio.cpp:386
long getFieldDecimal(QString fname)
Definition: xbio.cpp:291
HXBaseFileReader(HCodepageConvert *conv, bool deletecobj=false)
Definition: xbio.cpp:171
QDate getFieldDate(QString fname)
Definition: xbio.cpp:321
int toRecord(long idx)
Definition: xbio.cpp:213
int close(void)
Definition: xbio.cpp:426
int open(QString name)
Definition: xbio.cpp:182
int nextRecord(void)
Definition: xbio.cpp:251
int create(QString name, int version)
Definition: xbio.cpp:472
bool getFieldBool(QString fname)
Definition: xbio.cpp:311
int prevRecord(void)
Definition: xbio.cpp:263
HXBaseFileHandler(HCodepageConvert *conv, bool deletecobj=false)
Definition: xbio.cpp:104
~HXBaseFileReader(void)
Definition: xbio.cpp:176
~HXBaseFileHandler(void)
Definition: xbio.cpp:114
int setFieldFloat(QString fname, double val)
Definition: xbio.cpp:543
int open(QString name)
Definition: xbio.cpp:407
long getCurrentRecordIdx(void)
Definition: xbio.cpp:275
void errorSignal(QString error)
HXBaseFieldType fieldType(int n)
Definition: xbio.cpp:149
int close(void)
Definition: xbio.cpp:201
QString getFieldStr(QString fname)
Definition: xbio.cpp:280
QString fieldName(int n)
Definition: xbio.cpp:142
int setFieldBool(QString fname, bool logical)
Definition: xbio.cpp:554
~HXBaseFileWriter(void)
Definition: xbio.cpp:394
int firstRecord(void)
Definition: xbio.cpp:227
long recordCount(void)
Definition: xbio.cpp:131
int setFieldDecimal(QString fname, long decimal)
Definition: xbio.cpp:533
int appendRecord(void)
Definition: xbio.cpp:501
void error(QString s)
Definition: datalib.cpp:37
int setFieldDate(QString fname, QDate date)
Definition: xbio.cpp:565
void defineField(QString name, HXBaseFieldType type, int length=0, int nofdecimals=0)
Definition: xbio.cpp:438
double getFieldFloat(QString fname)
Definition: xbio.cpp:301
int fieldCount(void)
Definition: xbio.cpp:123
int setFieldStr(QString fname, QString str)
Definition: xbio.cpp:517
int lastRecord(void)
Definition: xbio.cpp:239