1/*************** FilAmGz H Declares Source Code File (.H) **************/
2/* Name: FILAMGZ.H Version 1.3 */
3/* */
4/* (C) Copyright to the author Olivier BERTRAND 2005-2016 */
5/* */
6/* This file contains the GZIP access method classes declares. */
7/***********************************************************************/
8#ifndef __FILAMGZ_H
9#define __FILAMGZ_H
10
11#include "zlib.h"
12
13typedef class GZFAM *PGZFAM;
14typedef class ZBKFAM *PZBKFAM;
15typedef class GZXFAM *PZIXFAM;
16typedef class ZLBFAM *PZLBFAM;
17
18/***********************************************************************/
19/* This is the access method class declaration for not optimized */
20/* variable record length files compressed using the gzip library */
21/* functions. File is accessed record by record (row). */
22/***********************************************************************/
23class DllExport GZFAM : public TXTFAM {
24// friend class DOSCOL;
25 public:
26 // Constructor
27 GZFAM(PDOSDEF tdp) : TXTFAM(tdp) {Zfile = NULL; Zpos = 0;}
28 GZFAM(PGZFAM txfp);
29
30 // Implementation
31 virtual AMT GetAmType(void) {return TYPE_AM_GZ;}
32 virtual int GetPos(void);
33 virtual int GetNextPos(void);
34 virtual PTXF Duplicate(PGLOBAL g)
35 {return (PTXF)new(g) GZFAM(this);}
36
37 // Methods
38 virtual void Reset(void);
39 virtual int GetFileLength(PGLOBAL g);
40 virtual int Cardinality(PGLOBAL g) {return (g) ? -1 : 0;}
41 virtual int MaxBlkSize(PGLOBAL g, int s) {return s;}
42 virtual bool AllocateBuffer(PGLOBAL g);
43 virtual int GetRowID(void);
44 virtual bool RecordPos(PGLOBAL g);
45 virtual bool SetPos(PGLOBAL g, int recpos);
46 virtual int SkipRecord(PGLOBAL g, bool header);
47 virtual bool OpenTableFile(PGLOBAL g);
48 virtual int ReadBuffer(PGLOBAL g);
49 virtual int WriteBuffer(PGLOBAL g);
50 virtual int DeleteRecords(PGLOBAL g, int irc);
51 virtual void CloseTableFile(PGLOBAL g, bool abort);
52 virtual void Rewind(void);
53
54 protected:
55 int Zerror(PGLOBAL g); // GZ error function
56
57 // Members
58 gzFile Zfile; // Points to GZ file structure
59 z_off_t Zpos; // Uncompressed file position
60 }; // end of class GZFAM
61
62/***********************************************************************/
63/* This is the access method class declaration for optimized variable */
64/* record length files compressed using the gzip library functions. */
65/* The File is accessed by block (requires an opt file). */
66/***********************************************************************/
67class DllExport ZBKFAM : public GZFAM {
68 public:
69 // Constructor
70 ZBKFAM(PDOSDEF tdp);
71 ZBKFAM(PZBKFAM txfp);
72
73 // Implementation
74 virtual int GetPos(void);
75 virtual int GetNextPos(void) {return 0;}
76 virtual PTXF Duplicate(PGLOBAL g)
77 {return (PTXF)new(g) ZBKFAM(this);}
78
79 // Methods
80 virtual int Cardinality(PGLOBAL g);
81 virtual int MaxBlkSize(PGLOBAL g, int s);
82 virtual bool AllocateBuffer(PGLOBAL g);
83 virtual int GetRowID(void);
84 virtual bool RecordPos(PGLOBAL g);
85 virtual int SkipRecord(PGLOBAL g, bool header);
86 virtual int ReadBuffer(PGLOBAL g);
87 virtual int WriteBuffer(PGLOBAL g);
88 virtual int DeleteRecords(PGLOBAL g, int irc);
89 virtual void CloseTableFile(PGLOBAL g, bool abort);
90 virtual void Rewind(void);
91
92 protected:
93 // Members
94 char *CurLine; // Position of current line in buffer
95 char *NxtLine; // Position of Next line in buffer
96 bool Closing; // True when closing on Insert
97 }; // end of class ZBKFAM
98
99/***********************************************************************/
100/* This is the access method class declaration for fixed record */
101/* length files compressed using the gzip library functions. */
102/* The file is always accessed by block. */
103/***********************************************************************/
104class DllExport GZXFAM : public ZBKFAM {
105 public:
106 // Constructor
107 GZXFAM(PDOSDEF tdp);
108 GZXFAM(PZIXFAM txfp) : ZBKFAM(txfp) {}
109
110 // Implementation
111 virtual int GetNextPos(void) {return 0;}
112 virtual PTXF Duplicate(PGLOBAL g)
113 {return (PTXF)new(g) GZXFAM(this);}
114
115 // Methods
116 virtual int Cardinality(PGLOBAL g);
117 virtual bool AllocateBuffer(PGLOBAL g);
118 virtual int ReadBuffer(PGLOBAL g);
119 virtual int WriteBuffer(PGLOBAL g);
120
121 protected:
122 // No additional Members
123 }; // end of class GZXFAM
124
125/***********************************************************************/
126/* This is the DOS/UNIX Access Method class declaration for PlugDB */
127/* fixed/variable files compressed using the zlib library functions. */
128/* Physically these are written and read using the same technique */
129/* than blocked variable files, only the contain of each block is */
130/* compressed using the deflate zlib function. The purpose of this */
131/* specific format is to have a fast mechanism for direct access of */
132/* records so blocked optimization is fast and direct access (joins) */
133/* is allowed. Note that the block length is written ahead of each */
134/* block to enable reading when optimization file is not available. */
135/***********************************************************************/
136class DllExport ZLBFAM : public BLKFAM {
137 public:
138 // Constructor
139 ZLBFAM(PDOSDEF tdp);
140 ZLBFAM(PZLBFAM txfp);
141
142 // Implementation
143 virtual AMT GetAmType(void) {return TYPE_AM_ZLIB;}
144 virtual int GetPos(void);
145 virtual int GetNextPos(void);
146 virtual PTXF Duplicate(PGLOBAL g)
147 {return (PTXF)new(g) ZLBFAM(this);}
148 inline void SetOptimized(bool b) {Optimized = b;}
149
150 // Methods
151 virtual int GetFileLength(PGLOBAL g);
152 virtual bool SetPos(PGLOBAL g, int recpos);
153 virtual bool AllocateBuffer(PGLOBAL g);
154 virtual int ReadBuffer(PGLOBAL g);
155 virtual int WriteBuffer(PGLOBAL g);
156 virtual void CloseTableFile(PGLOBAL g, bool abort);
157 virtual void Rewind(void);
158
159 protected:
160 bool WriteCompressedBuffer(PGLOBAL g);
161 int ReadCompressedBuffer(PGLOBAL g, void *rdbuf);
162
163 // Members
164 z_streamp Zstream; // Compression/decompression stream
165 Byte *Zbuffer; // Compressed block buffer
166 int *Zlenp; // Pointer to block length
167 bool Optimized; // true when opt file is available
168 }; // end of class ZLBFAM
169
170#endif // __FILAMGZ_H
171