1 // TABXCL.H Olivier Bertrand 2013 2 // Defines the XCOL tables 3 4 #include "tabutil.h" 5 6 typedef class XCLDEF *PXCLDEF; 7 typedef class TDBXCL *PTDBXCL; 8 typedef class XCLCOL *PXCLCOL; 9 10 /* -------------------------- XCOL classes --------------------------- */ 11 12 /***********************************************************************/ 13 /* XCOL: table having one column containing several values comma */ 14 /* (or any other character) separated. When creating the table, the */ 15 /* name of the X column is given by the NAME option. */ 16 /* This sample has a limitation: */ 17 /* - The X column has the same length than in the physical file. */ 18 /* This tables produces as many rows for a physical row than the */ 19 /* number of items in the X column (eventually 0). */ 20 /***********************************************************************/ 21 22 /***********************************************************************/ 23 /* XCL table. */ 24 /***********************************************************************/ 25 class XCLDEF : public PRXDEF { /* Logical table description */ 26 friend class TDBXCL; 27 public: 28 // Constructor 29 XCLDEF(void); 30 31 // Implementation GetType(void)32 virtual const char *GetType(void) {return "XCL";} 33 34 // Methods 35 virtual bool DefineAM(PGLOBAL g, LPCSTR am, int poff); 36 virtual PTDB GetTable(PGLOBAL g, MODE mode); 37 38 protected: 39 // Members 40 char *Xcol; /* The column containing separated fields */ 41 char Sep; /* The field separator, defaults to comma */ 42 int Mult; /* Multiplication factor */ 43 }; // end of XCLDEF 44 45 /***********************************************************************/ 46 /* This is the class declaration for the XCOL table. */ 47 /***********************************************************************/ 48 class TDBXCL : public TDBPRX { 49 friend class XCLDEF; 50 friend class PRXCOL; 51 friend class XCLCOL; 52 public: 53 // Constructor 54 TDBXCL(PXCLDEF tdp); 55 56 // Implementation GetAmType(void)57 virtual AMT GetAmType(void) {return TYPE_AM_XCOL;} 58 59 // Methods ResetDB(void)60 virtual void ResetDB(void) {N = 0; Tdbp->ResetDB();} 61 virtual int RowNumber(PGLOBAL g, bool b = FALSE); 62 63 // Database routines 64 virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n); 65 virtual int GetMaxSize(PGLOBAL g); 66 virtual bool OpenDB(PGLOBAL g); 67 virtual int ReadDB(PGLOBAL g); 68 69 protected: 70 // Members 71 char *Xcolumn; // Multiple column name 72 PXCLCOL Xcolp; // To the XCVCOL column 73 int Mult; // Multiplication factor 74 int N; // The current table index 75 int M; // The occurence rank 76 BYTE RowFlag; // 0: Ok, 1: Same, 2: Skip 77 bool New; // TRUE for new line 78 char Sep; // The Xcol separator 79 }; // end of class TDBXCL 80 81 /***********************************************************************/ 82 /* Class XCLCOL: for the multiple CSV column. */ 83 /***********************************************************************/ 84 class XCLCOL : public PRXCOL { 85 friend class TDBXCL; 86 public: 87 // Constructors 88 XCLCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i); 89 90 // Methods 91 using PRXCOL::Init; Reset(void)92 virtual void Reset(void) {} // Evaluated only by TDBXCL 93 virtual void ReadColumn(PGLOBAL g); 94 virtual bool Init(PGLOBAL g, PTDB tp = NULL); 95 96 protected: 97 // Default constructor not to be used XCLCOL(void)98 XCLCOL(void) {} 99 100 // Members 101 char *Cbuf; // The column buffer 102 char *Cp; // Pointer to current position 103 char Sep; // The separator 104 }; // end of class XCLCOL 105