1 | /************** FilAMTxt H Declares Source Code File (.H) **************/ |
2 | /* Name: FILAMTXT.H Version 1.3 */ |
3 | /* */ |
4 | /* (C) Copyright to the author Olivier BERTRAND 2005-2014 */ |
5 | /* */ |
6 | /* This file contains the file access method classes declares. */ |
7 | /***********************************************************************/ |
8 | |
9 | #ifndef __FILAMTXT_H |
10 | #define __FILAMTXT_H |
11 | |
12 | #include "block.h" |
13 | #include "array.h" |
14 | |
15 | typedef class TXTFAM *PTXF; |
16 | typedef class DOSFAM *PDOSFAM; |
17 | typedef class BLKFAM *PBLKFAM; |
18 | typedef class DOSDEF *PDOSDEF; |
19 | typedef class TDBDOS *PTDBDOS; |
20 | |
21 | /***********************************************************************/ |
22 | /* This is the base class for all file access method classes. */ |
23 | /***********************************************************************/ |
24 | class DllExport TXTFAM : public BLOCK { |
25 | friend class TDBDOS; |
26 | friend class TDBCSV; |
27 | friend class TDBFIX; |
28 | friend class TDBVCT; |
29 | friend class TDBJSON; |
30 | friend class DOSCOL; |
31 | friend class BINCOL; |
32 | friend class VCTCOL; |
33 | public: |
34 | // Constructor |
35 | TXTFAM(PDOSDEF tdp); |
36 | TXTFAM(PTXF txfp); |
37 | |
38 | // Implementation |
39 | virtual AMT GetAmType(void) = 0; |
40 | virtual int GetPos(void) = 0; |
41 | virtual int GetNextPos(void) = 0; |
42 | virtual PTXF Duplicate(PGLOBAL g) = 0; |
43 | virtual bool GetUseTemp(void) {return false;} |
44 | virtual int GetDelRows(void) {return DelRows;} |
45 | PFBLOCK GetTo_Fb(void) {return To_Fb;} |
46 | int GetCurBlk(void) {return CurBlk;} |
47 | void SetTdbp(PTDBDOS tdbp) {Tdbp = tdbp;} |
48 | int GetBlock(void) {return Block;} |
49 | void SetBlkPos(int *bkp) {BlkPos = bkp;} |
50 | void SetNrec(int n) {Nrec = n;} |
51 | char *GetBuf(void) {return To_Buf;} |
52 | int GetRows(void) {return Rows;} |
53 | bool IsBlocked(void) {return Blocked;} |
54 | |
55 | // Methods |
56 | virtual void Reset(void); |
57 | virtual int GetFileLength(PGLOBAL g); |
58 | virtual int Cardinality(PGLOBAL g); |
59 | virtual int MaxBlkSize(PGLOBAL g, int s); |
60 | virtual bool AllocateBuffer(PGLOBAL) {return false;} |
61 | virtual void ResetBuffer(PGLOBAL) {} |
62 | virtual int GetNerr(void) {return 0;} |
63 | virtual int GetRowID(void) = 0; |
64 | virtual bool RecordPos(PGLOBAL g) = 0; |
65 | virtual bool SetPos(PGLOBAL g, int recpos) = 0; |
66 | virtual int SkipRecord(PGLOBAL g, bool ) = 0; |
67 | virtual bool OpenTableFile(PGLOBAL g) = 0; |
68 | virtual bool DeferReading(void) {IsRead = false; return true;} |
69 | virtual int ReadBuffer(PGLOBAL g) = 0; |
70 | virtual int WriteBuffer(PGLOBAL g) = 0; |
71 | virtual int DeleteRecords(PGLOBAL g, int irc) = 0; |
72 | virtual void CloseTableFile(PGLOBAL g, bool abort) = 0; |
73 | virtual void Rewind(void) = 0; |
74 | virtual int InitDelete(PGLOBAL g, int fpos, int spos); |
75 | bool AddListValue(PGLOBAL g, int type, void *val, PPARM *top); |
76 | int StoreValues(PGLOBAL g, bool upd); |
77 | int UpdateSortedRows(PGLOBAL g); |
78 | int DeleteSortedRows(PGLOBAL g); |
79 | |
80 | protected: |
81 | // Members |
82 | PTDBDOS Tdbp; // To table class |
83 | PCSZ To_File; // Points to table file name |
84 | PFBLOCK To_Fb; // Pointer to file block |
85 | PPARM To_Pos; // Pointer to position list |
86 | PPARM To_Sos; // Pointer to start position list |
87 | PPARM To_Upd; // Pointer to udated line list |
88 | PARRAY Posar; // Pointer to position array |
89 | PARRAY Sosar; // Pointer to start position array |
90 | PARRAY Updar; // Pointer to udated lines array |
91 | bool Placed; // true if Recpos was externally set |
92 | bool IsRead; // false for deferred reading |
93 | bool Blocked; // true if using blocked I/O |
94 | char *To_Buf; // Points to I/O buffer |
95 | void *DelBuf; // Buffer used to move lines in Delete |
96 | int *BlkPos; // To array of block positions |
97 | int BlkLen; // Current block length |
98 | int Buflen; // Buffer length |
99 | int Dbflen; // Delete buffer length |
100 | int Rows; // Number of rows read so far |
101 | int DelRows; // Number of deleted rows |
102 | int Headlen; // Number of bytes in header |
103 | int Lrecl; // Logical Record Length |
104 | int Block; // Number of blocks in table |
105 | int Last; // Number of elements of last block |
106 | int Nrec; // Number of records in buffer |
107 | int OldBlk; // Index of last read block |
108 | int CurBlk; // Index of current block |
109 | int CurNum; // Current buffer line number |
110 | int ReadBlks; // Number of blocks read (selected) |
111 | int Rbuf; // Number of lines read in buffer |
112 | int Modif; // Number of modified lines in block |
113 | int Blksize; // Size of padded blocks |
114 | int Ending; // Length of line end |
115 | int Fpos; // Position of last read record |
116 | int Spos; // Start position for update/delete move |
117 | int Tpos; // Target Position for delete move |
118 | bool Padded; // true if fixed size blocks are padded |
119 | bool Eof; // true if an EOF (0xA) character exists |
120 | bool Abort; // To abort on error |
121 | char *CrLf; // End of line character(s) |
122 | }; // end of class TXTFAM |
123 | |
124 | /***********************************************************************/ |
125 | /* This is the DOS/UNIX Access Method class declaration for standard */ |
126 | /* text files with variable record format (DOS, CSV, FMT) */ |
127 | /***********************************************************************/ |
128 | class DllExport DOSFAM : public TXTFAM { |
129 | public: |
130 | // Constructor |
131 | DOSFAM(PDOSDEF tdp); |
132 | DOSFAM(PDOSFAM txfp); |
133 | DOSFAM(PBLKFAM tdfp, PDOSDEF tdp); |
134 | |
135 | // Implementation |
136 | virtual AMT GetAmType(void) {return TYPE_AM_DOS;} |
137 | virtual bool GetUseTemp(void) {return UseTemp;} |
138 | virtual int GetPos(void); |
139 | virtual int GetNextPos(void); |
140 | virtual PTXF Duplicate(PGLOBAL g) |
141 | {return (PTXF)new(g) DOSFAM(this);} |
142 | |
143 | // Methods |
144 | virtual void Reset(void); |
145 | virtual int GetFileLength(PGLOBAL g); |
146 | virtual int Cardinality(PGLOBAL g); |
147 | virtual int MaxBlkSize(PGLOBAL g, int s); |
148 | virtual bool AllocateBuffer(PGLOBAL g); |
149 | virtual int GetRowID(void); |
150 | virtual bool RecordPos(PGLOBAL g); |
151 | virtual bool SetPos(PGLOBAL g, int recpos); |
152 | virtual int SkipRecord(PGLOBAL g, bool ); |
153 | virtual bool OpenTableFile(PGLOBAL g); |
154 | virtual int ReadBuffer(PGLOBAL g); |
155 | virtual int WriteBuffer(PGLOBAL g); |
156 | virtual int DeleteRecords(PGLOBAL g, int irc); |
157 | virtual void CloseTableFile(PGLOBAL g, bool abort); |
158 | virtual void Rewind(void); |
159 | |
160 | protected: |
161 | virtual bool OpenTempFile(PGLOBAL g); |
162 | virtual bool MoveIntermediateLines(PGLOBAL g, bool *b); |
163 | virtual int RenameTempFile(PGLOBAL g); |
164 | virtual int InitDelete(PGLOBAL g, int fpos, int spos); |
165 | |
166 | // Members |
167 | FILE *Stream; // Points to Dos file structure |
168 | FILE *T_Stream; // Points to temporary file structure |
169 | PFBLOCK To_Fbt; // Pointer to temp file block |
170 | bool UseTemp; // True to use a temporary file in Upd/Del |
171 | bool Bin; // True to force binary mode |
172 | }; // end of class DOSFAM |
173 | |
174 | /***********************************************************************/ |
175 | /* This is the DOS/UNIX Access Method class declaration for standard */ |
176 | /* text files with variable record format (DOS, CSV, FMT) */ |
177 | /***********************************************************************/ |
178 | class DllExport BLKFAM : public DOSFAM { |
179 | public: |
180 | // Constructor |
181 | BLKFAM(PDOSDEF tdp); |
182 | BLKFAM(PBLKFAM txfp); |
183 | |
184 | // Implementation |
185 | virtual AMT GetAmType(void) {return TYPE_AM_BLK;} |
186 | virtual int GetPos(void); |
187 | virtual int GetNextPos(void); |
188 | virtual PTXF Duplicate(PGLOBAL g) |
189 | {return (PTXF)new(g) BLKFAM(this);} |
190 | |
191 | // Methods |
192 | virtual void Reset(void); |
193 | virtual int Cardinality(PGLOBAL g); |
194 | virtual int MaxBlkSize(PGLOBAL g, int s); |
195 | virtual bool AllocateBuffer(PGLOBAL g); |
196 | virtual int GetRowID(void); |
197 | virtual bool RecordPos(PGLOBAL g); |
198 | virtual bool SetPos(PGLOBAL g, int recpos); |
199 | virtual int SkipRecord(PGLOBAL g, bool ); |
200 | virtual int ReadBuffer(PGLOBAL g); |
201 | virtual int WriteBuffer(PGLOBAL g); |
202 | virtual void CloseTableFile(PGLOBAL g, bool abort); |
203 | virtual void Rewind(void); |
204 | |
205 | protected: |
206 | // Members |
207 | char *CurLine; // Position of current line in buffer |
208 | char *NxtLine; // Position of Next line in buffer |
209 | char *OutBuf; // Buffer to write in temporary file |
210 | bool Closing; // True when closing on Update |
211 | }; // end of class BLKFAM |
212 | |
213 | #endif // __FILAMTXT_H |
214 | |