tabmul.h 8.71 KB
Newer Older
Alexander Barkov's avatar
Alexander Barkov committed
1
/*************** Tabmul H Declares Source Code File (.H) ***************/
2
/*  Name: TABMUL.H   Version 1.5                                       */
Alexander Barkov's avatar
Alexander Barkov committed
3
/*                                                                     */
4
/*  (C) Copyright to PlugDB Software Development          2003-2017    */
Alexander Barkov's avatar
Alexander Barkov committed
5 6 7 8
/*  Author: Olivier BERTRAND                                           */
/*                                                                     */
/*  This file contains the TDBMUL and TDBDIR classes declares.         */
/***********************************************************************/
9
#if defined(__WIN__)
Alexander Barkov's avatar
Alexander Barkov committed
10
#include <io.h>
11
#else   // !__WIN__
Alexander Barkov's avatar
Alexander Barkov committed
12 13 14 15
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <dirent.h>
16
#endif  // !__WIN__
Alexander Barkov's avatar
Alexander Barkov committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30
//#include "osutil.h"
#include "block.h"

typedef class TDBMUL *PTDBMUL;
typedef class TDBSDR *PTDBSDR;

/***********************************************************************/
/*  This is the MUL Access Method class declaration for files that are */
/*  physically split in multiple files having the same format.         */
/***********************************************************************/
class DllExport TDBMUL : public TDBASE {
//friend class MULCOL;
 public:
  // Constructor
31
  TDBMUL(PTDB tdbp);
Alexander Barkov's avatar
Alexander Barkov committed
32 33 34 35 36 37 38 39
  TDBMUL(PTDBMUL tdbp);

  // Implementation
  virtual AMT  GetAmType(void) {return Tdbp->GetAmType();}
  virtual PTDB Duplicate(PGLOBAL g);

  // Methods
  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);}
Alexander Barkov's avatar
Alexander Barkov committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
  virtual int  GetRecpos(void) {return 0;}
  virtual PCOL ColDB(PGLOBAL g, PSZ name, int num);
          bool InitFileNames(PGLOBAL g);

  // Database routines
  virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n)
                {strcpy(g->Message, MSG(MUL_MAKECOL_ERR)); return NULL;}
  virtual int  Cardinality(PGLOBAL g);
  virtual int  GetMaxSize(PGLOBAL g);
  virtual int  GetProgMax(PGLOBAL g);
  virtual int  GetProgCur(void);
  virtual int  RowNumber(PGLOBAL g, bool b = false);
  virtual bool OpenDB(PGLOBAL g);
  virtual int  ReadDB(PGLOBAL g);
  virtual int  WriteDB(PGLOBAL g);
  virtual int  DeleteDB(PGLOBAL g, int irc);
  virtual void CloseDB(PGLOBAL g);

 protected:

  // Members
64
  PTDB    Tdbp;               // Points to a (file) table class
Alexander Barkov's avatar
Alexander Barkov committed
65 66 67 68 69 70 71
  char*  *Filenames;          // Points to file names
  int     Rows;               // Total rows of already read files
  int     Mul;                // Type of multiple file list
  int     NumFiles;           // Number of physical files
  int     iFile;              // Index of currently processed file
  }; // end of class TDBMUL

72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
#if 0
/***********************************************************************/
/*  This is the MSD Access Method class declaration for files that are */
/*  physically split in multiple files having the same format.         */
/*  This sub-class also include files of the sub-directories.          */
/***********************************************************************/
class DllExport TDBMSD : public TDBMUL {
	//friend class MULCOL;
public:
	// Constructor
	TDBMSD(PTDB tdbp) : TDBMUL(tdbp) {}
	TDBMSD(PTDBMSD tdbp) : TDBMUL(tdbp) {}

	// Implementation
	virtual PTDB Duplicate(PGLOBAL g);

	// Methods
	virtual PTDB Clone(PTABS t);
	bool InitFileNames(PGLOBAL g);

	// Database routines

protected:

	// Members
}; // end of class TDBMSD
#endif

Alexander Barkov's avatar
Alexander Barkov committed
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
/***********************************************************************/
/*  Directory listing table.                                           */
/***********************************************************************/
class DllExport DIRDEF : public TABDEF {    /* Directory listing table */
  friend class CATALOG;
  friend class TDBDIR;
 public:
  // Constructor
  DIRDEF(void) {Fn = NULL; Incl = false; Huge = false;}

  // Implementation
  virtual const char *GetType(void) {return "DIR";}

  // Methods
  virtual bool DefineAM(PGLOBAL g, LPCSTR am, int poff);
  virtual PTDB GetTable(PGLOBAL g, MODE m);

 protected:
  // Members
  PSZ     Fn;                 /* Path/Name of file search              */
  bool    Incl;               /* true to include sub-directories       */
121 122
	bool    Huge;               /* true if files can be larger than 2GB  */
	bool    Nodir;							/* true to exclude directories           */
Alexander Barkov's avatar
Alexander Barkov committed
123 124 125 126 127 128 129 130 131 132
  }; // end of DIRDEF

/***********************************************************************/
/*  This is the DIR Access Method class declaration for tables that    */
/*  represent a directory listing. The pathname is given at the create */
/*  time and can contain wildcard characters in the file name, and the */
/*  (virtual) table is populated when it is in use.                    */
/***********************************************************************/
class TDBDIR : public TDBASE {
  friend class DIRCOL;
133 134
	friend class TDBMUL;
public:
Alexander Barkov's avatar
Alexander Barkov committed
135 136
  // Constructor
  TDBDIR(PDIRDEF tdp);
137
	TDBDIR(PSZ fpat);
Alexander Barkov's avatar
Alexander Barkov committed
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156

  // Implementation
  virtual AMT  GetAmType(void) {return TYPE_AM_DIR;}

  // Methods
  virtual int GetRecpos(void) {return iFile;}

  // Database routines
  virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n);
  virtual int  GetMaxSize(PGLOBAL g);
  virtual int  GetProgMax(PGLOBAL g) {return GetMaxSize(g);}
  virtual int  GetProgCur(void) {return iFile;}
  virtual bool OpenDB(PGLOBAL g);
  virtual int  ReadDB(PGLOBAL g);
  virtual int  WriteDB(PGLOBAL g);
  virtual int  DeleteDB(PGLOBAL g, int irc);
  virtual void CloseDB(PGLOBAL g);

 protected:
157
	void Init(void);
Alexander Barkov's avatar
Alexander Barkov committed
158 159 160 161 162
  char *Path(PGLOBAL g);

  // Members
  PSZ  To_File;                 // Points to file search pathname
  int  iFile;                   // Index of currently retrieved file
163
#if defined(__WIN__)
164 165 166
	PVAL Dvalp;							      // Used to retrieve file date values
	WIN32_FIND_DATA FileData;			// Find data structure
	HANDLE hSearch;               // Search handle
Alexander Barkov's avatar
Alexander Barkov committed
167
  char Drive[_MAX_DRIVE];       // Drive name
168
#else   // !__WIN__
Alexander Barkov's avatar
Alexander Barkov committed
169 170 171 172 173
  struct stat    Fileinfo;      // File info structure
  struct dirent *Entry;         // Point to directory entry structure
  DIR *Dir;                     // To searched directory structure
  bool Done;                    // true when _splipath is done
  char Pattern[_MAX_FNAME+_MAX_EXT];
174
#endif  // !__WIN__
Alexander Barkov's avatar
Alexander Barkov committed
175 176 177 178
  char Fpath[_MAX_PATH];        // Absolute file search pattern
  char Direc[_MAX_DIR];         // Search path
  char Fname[_MAX_FNAME];       // File name
  char Ftype[_MAX_EXT];         // File extention
179
	bool Nodir;                   // Exclude directories from file list
Alexander Barkov's avatar
Alexander Barkov committed
180 181 182 183 184 185 186 187 188 189 190
  }; // end of class TDBDIR

/***********************************************************************/
/*  This is the DIR Access Method class declaration for tables that    */
/*  represent a directory listing. The pathname is given at the create */
/*  time and can contain wildcard characters in the file name, and the */
/*  (virtual) table is populated when it is in use. In addition, this  */
/*  class also includes files of included sub-directories.             */
/***********************************************************************/
class TDBSDR : public TDBDIR {
  friend class DIRCOL;
191
	friend class TDBMUL;
Alexander Barkov's avatar
Alexander Barkov committed
192 193 194
 public:
  // Constructors
  TDBSDR(PDIRDEF tdp) : TDBDIR(tdp) {Sub = NULL;}
195
	TDBSDR(PSZ fpat) : TDBDIR(fpat) {Sub = NULL;}
Alexander Barkov's avatar
Alexander Barkov committed
196 197 198 199 200 201 202 203 204 205 206 207 208 209

  // Database routines
  virtual int  GetMaxSize(PGLOBAL g);
  virtual int  GetProgMax(PGLOBAL g) {return GetMaxSize(g);}
  virtual bool OpenDB(PGLOBAL g);
  virtual int  ReadDB(PGLOBAL g);
//virtual void CloseDB(PGLOBAL g);

 protected:
          int  FindInDir(PGLOBAL g);

  typedef struct _Sub_Dir {
    struct _Sub_Dir *Next;
    struct _Sub_Dir *Prev;
210
#if defined(__WIN__)
211
    HANDLE H;               // Search handle
212
#else   // !__WIN__
Alexander Barkov's avatar
Alexander Barkov committed
213
    DIR *D;
214
#endif  // !__WIN__
Alexander Barkov's avatar
Alexander Barkov committed
215 216 217 218 219 220 221 222 223 224 225 226 227 228
    size_t Len;           // Initial directory name length
    } SUBDIR, *PSUBDIR;

  // Members
  PSUBDIR Sub;                  // To current Subdir block
  }; // end of class TDBSDR

/***********************************************************************/
/*  Class DIRCOL: DIR access method column descriptor.                 */
/*  This A.M. is used for tables populated by DIR file name list.      */
/***********************************************************************/
class DIRCOL : public COLBLK {
 public:
  // Constructors
229
  DIRCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i, PCSZ am = "DIR");
Alexander Barkov's avatar
Alexander Barkov committed
230 231 232 233 234 235 236 237 238 239 240
  DIRCOL(DIRCOL *colp, PTDB tdbp); // Constructor used in copy process

  // Implementation
  virtual int    GetAmType(void) {return TYPE_AM_DIR;}

  // Methods
  virtual void   ReadColumn(PGLOBAL g);

 protected:
  // Default constructor not to be used
  DIRCOL(void) {}
241 242 243
#if defined(__WIN__)
	void SetTimeValue(PGLOBAL g, FILETIME& ftime);
#endif   // __WIN__
Alexander Barkov's avatar
Alexander Barkov committed
244 245

  // Members
246
	PTDBDIR	Tdbp;								// To DIR table
Alexander Barkov's avatar
Alexander Barkov committed
247 248
  int     N;                  // Column number
  }; // end of class DIRCOL