1/*************** Tabmul H Declares Source Code File (.H) ***************/
2/* Name: TABMUL.H Version 1.5 */
3/* */
4/* (C) Copyright to PlugDB Software Development 2003-2017 */
5/* Author: Olivier BERTRAND */
6/* */
7/* This file contains the TDBMUL and TDBDIR classes declares. */
8/***********************************************************************/
9#if defined(__WIN__)
10#include <io.h>
11#else // !__WIN__
12#include <sys/types.h>
13#include <unistd.h>
14#include <sys/stat.h>
15#include <dirent.h>
16#endif // !__WIN__
17//#include "osutil.h"
18#include "block.h"
19
20typedef class TDBMUL *PTDBMUL;
21typedef class TDBSDR *PTDBSDR;
22
23/***********************************************************************/
24/* This is the MUL Access Method class declaration for files that are */
25/* physically split in multiple files having the same format. */
26/***********************************************************************/
27class DllExport TDBMUL : public TDBASE {
28//friend class MULCOL;
29 public:
30 // Constructor
31 TDBMUL(PTDB tdbp);
32 TDBMUL(PTDBMUL tdbp);
33
34 // Implementation
35 virtual AMT GetAmType(void) {return Tdbp->GetAmType();}
36 virtual PTDB Duplicate(PGLOBAL g);
37
38 // Methods
39 virtual void ResetDB(void);
40 virtual PTDB Clone(PTABS t);
41 virtual bool IsSame(PTDB tp) {return tp == (PTDB)Tdbp;}
42 virtual PCSZ GetFile(PGLOBAL g) {return Tdbp->GetFile(g);}
43 virtual int GetRecpos(void) {return 0;}
44 virtual PCOL ColDB(PGLOBAL g, PSZ name, int num);
45 bool InitFileNames(PGLOBAL g);
46
47 // Database routines
48 virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n)
49 {strcpy(g->Message, MSG(MUL_MAKECOL_ERR)); return NULL;}
50 virtual int Cardinality(PGLOBAL g);
51 virtual int GetMaxSize(PGLOBAL g);
52 virtual int GetProgMax(PGLOBAL g);
53 virtual int GetProgCur(void);
54 virtual int RowNumber(PGLOBAL g, bool b = false);
55 virtual bool OpenDB(PGLOBAL g);
56 virtual int ReadDB(PGLOBAL g);
57 virtual int WriteDB(PGLOBAL g);
58 virtual int DeleteDB(PGLOBAL g, int irc);
59 virtual void CloseDB(PGLOBAL g);
60
61 protected:
62
63 // Members
64 PTDB Tdbp; // Points to a (file) table class
65 char* *Filenames; // Points to file names
66 int Rows; // Total rows of already read files
67 int Mul; // Type of multiple file list
68 int NumFiles; // Number of physical files
69 int iFile; // Index of currently processed file
70 }; // end of class TDBMUL
71
72#if 0
73/***********************************************************************/
74/* This is the MSD Access Method class declaration for files that are */
75/* physically split in multiple files having the same format. */
76/* This sub-class also include files of the sub-directories. */
77/***********************************************************************/
78class DllExport TDBMSD : public TDBMUL {
79 //friend class MULCOL;
80public:
81 // Constructor
82 TDBMSD(PTDB tdbp) : TDBMUL(tdbp) {}
83 TDBMSD(PTDBMSD tdbp) : TDBMUL(tdbp) {}
84
85 // Implementation
86 virtual PTDB Duplicate(PGLOBAL g);
87
88 // Methods
89 virtual PTDB Clone(PTABS t);
90 bool InitFileNames(PGLOBAL g);
91
92 // Database routines
93
94protected:
95
96 // Members
97}; // end of class TDBMSD
98#endif
99
100/***********************************************************************/
101/* Directory listing table. */
102/***********************************************************************/
103class DllExport DIRDEF : public TABDEF { /* Directory listing table */
104 friend class CATALOG;
105 friend class TDBDIR;
106 public:
107 // Constructor
108 DIRDEF(void) {Fn = NULL; Incl = false; Huge = false;}
109
110 // Implementation
111 virtual const char *GetType(void) {return "DIR";}
112
113 // Methods
114 virtual bool DefineAM(PGLOBAL g, LPCSTR am, int poff);
115 virtual PTDB GetTable(PGLOBAL g, MODE m);
116
117 protected:
118 // Members
119 PSZ Fn; /* Path/Name of file search */
120 bool Incl; /* true to include sub-directories */
121 bool Huge; /* true if files can be larger than 2GB */
122 bool Nodir; /* true to exclude directories */
123 }; // end of DIRDEF
124
125/***********************************************************************/
126/* This is the DIR Access Method class declaration for tables that */
127/* represent a directory listing. The pathname is given at the create */
128/* time and can contain wildcard characters in the file name, and the */
129/* (virtual) table is populated when it is in use. */
130/***********************************************************************/
131class TDBDIR : public TDBASE {
132 friend class DIRCOL;
133 friend class TDBMUL;
134public:
135 // Constructor
136 TDBDIR(PDIRDEF tdp);
137 TDBDIR(PSZ fpat);
138
139 // Implementation
140 virtual AMT GetAmType(void) {return TYPE_AM_DIR;}
141
142 // Methods
143 virtual int GetRecpos(void) {return iFile;}
144
145 // Database routines
146 virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n);
147 virtual int GetMaxSize(PGLOBAL g);
148 virtual int GetProgMax(PGLOBAL g) {return GetMaxSize(g);}
149 virtual int GetProgCur(void) {return iFile;}
150 virtual bool OpenDB(PGLOBAL g);
151 virtual int ReadDB(PGLOBAL g);
152 virtual int WriteDB(PGLOBAL g);
153 virtual int DeleteDB(PGLOBAL g, int irc);
154 virtual void CloseDB(PGLOBAL g);
155
156 protected:
157 void Init(void);
158 char *Path(PGLOBAL g);
159
160 // Members
161 PSZ To_File; // Points to file search pathname
162 int iFile; // Index of currently retrieved file
163#if defined(__WIN__)
164 PVAL Dvalp; // Used to retrieve file date values
165 WIN32_FIND_DATA FileData; // Find data structure
166 HANDLE hSearch; // Search handle
167 char Drive[_MAX_DRIVE]; // Drive name
168#else // !__WIN__
169 struct stat Fileinfo; // File info structure
170 struct dirent *Entry; // Point to directory entry structure
171 DIR *Dir; // To searched directory structure
172 bool Done; // true when _splipath is done
173 char Pattern[_MAX_FNAME+_MAX_EXT];
174#endif // !__WIN__
175 char Fpath[_MAX_PATH]; // Absolute file search pattern
176 char Direc[_MAX_DIR]; // Search path
177 char Fname[_MAX_FNAME]; // File name
178 char Ftype[_MAX_EXT]; // File extention
179 bool Nodir; // Exclude directories from file list
180 }; // end of class TDBDIR
181
182/***********************************************************************/
183/* This is the DIR Access Method class declaration for tables that */
184/* represent a directory listing. The pathname is given at the create */
185/* time and can contain wildcard characters in the file name, and the */
186/* (virtual) table is populated when it is in use. In addition, this */
187/* class also includes files of included sub-directories. */
188/***********************************************************************/
189class TDBSDR : public TDBDIR {
190 friend class DIRCOL;
191 friend class TDBMUL;
192 public:
193 // Constructors
194 TDBSDR(PDIRDEF tdp) : TDBDIR(tdp) {Sub = NULL;}
195 TDBSDR(PSZ fpat) : TDBDIR(fpat) {Sub = NULL;}
196
197 // Database routines
198 virtual int GetMaxSize(PGLOBAL g);
199 virtual int GetProgMax(PGLOBAL g) {return GetMaxSize(g);}
200 virtual bool OpenDB(PGLOBAL g);
201 virtual int ReadDB(PGLOBAL g);
202//virtual void CloseDB(PGLOBAL g);
203
204 protected:
205 int FindInDir(PGLOBAL g);
206
207 typedef struct _Sub_Dir {
208 struct _Sub_Dir *Next;
209 struct _Sub_Dir *Prev;
210#if defined(__WIN__)
211 HANDLE H; // Search handle
212#else // !__WIN__
213 DIR *D;
214#endif // !__WIN__
215 size_t Len; // Initial directory name length
216 } SUBDIR, *PSUBDIR;
217
218 // Members
219 PSUBDIR Sub; // To current Subdir block
220 }; // end of class TDBSDR
221
222/***********************************************************************/
223/* Class DIRCOL: DIR access method column descriptor. */
224/* This A.M. is used for tables populated by DIR file name list. */
225/***********************************************************************/
226class DIRCOL : public COLBLK {
227 public:
228 // Constructors
229 DIRCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i, PCSZ am = "DIR");
230 DIRCOL(DIRCOL *colp, PTDB tdbp); // Constructor used in copy process
231
232 // Implementation
233 virtual int GetAmType(void) {return TYPE_AM_DIR;}
234
235 // Methods
236 virtual void ReadColumn(PGLOBAL g);
237
238 protected:
239 // Default constructor not to be used
240 DIRCOL(void) {}
241#if defined(__WIN__)
242 void SetTimeValue(PGLOBAL g, FILETIME& ftime);
243#endif // __WIN__
244
245 // Members
246 PTDBDIR Tdbp; // To DIR table
247 int N; // Column number
248 }; // end of class DIRCOL
249