1 | // TABOCCUR.H Olivier Bertrand 2013 |
2 | // Defines the OCCUR tables |
3 | |
4 | #include "tabutil.h" |
5 | |
6 | typedef class OCCURDEF *POCCURDEF; |
7 | typedef class TDBOCCUR *PTDBOCCUR; |
8 | typedef class OCCURCOL *POCCURCOL; |
9 | typedef class RANKCOL *PRANKCOL; |
10 | |
11 | /* -------------------------- OCCUR classes -------------------------- */ |
12 | |
13 | /***********************************************************************/ |
14 | /* OCCUR: Table that provides a view of a source table where the */ |
15 | /* contain of several columns of the source table is placed in only */ |
16 | /* one column, the OCCUR column, this resulting into several rows. */ |
17 | /***********************************************************************/ |
18 | |
19 | /***********************************************************************/ |
20 | /* OCCUR table. */ |
21 | /***********************************************************************/ |
22 | class OCCURDEF : public PRXDEF { /* Logical table description */ |
23 | friend class TDBOCCUR; |
24 | public: |
25 | // Constructor |
26 | OCCURDEF(void) {Pseudo = 3; Colist = Xcol = NULL;} |
27 | |
28 | // Implementation |
29 | virtual const char *GetType(void) {return "OCCUR" ;} |
30 | |
31 | // Methods |
32 | virtual bool DefineAM(PGLOBAL g, LPCSTR am, int poff); |
33 | virtual PTDB GetTable(PGLOBAL g, MODE m); |
34 | |
35 | protected: |
36 | // Members |
37 | char *Colist; /* The source column list */ |
38 | char *Xcol; /* The multiple occurence column */ |
39 | char *Rcol; /* The rank column */ |
40 | }; // end of OCCURDEF |
41 | |
42 | /***********************************************************************/ |
43 | /* This is the class declaration for the OCCUR table. */ |
44 | /***********************************************************************/ |
45 | class TDBOCCUR : public TDBPRX { |
46 | friend class OCCURCOL; |
47 | friend class RANKCOL; |
48 | public: |
49 | // Constructor |
50 | TDBOCCUR(POCCURDEF tdp); |
51 | |
52 | // Implementation |
53 | virtual AMT GetAmType(void) {return TYPE_AM_OCCUR;} |
54 | void SetTdbp(PTDBASE tdbp) {Tdbp = tdbp;} |
55 | |
56 | // Methods |
57 | virtual void ResetDB(void) {N = 0; Tdbp->ResetDB();} |
58 | virtual int RowNumber(PGLOBAL g, bool b = FALSE); |
59 | bool MakeColumnList(PGLOBAL g); |
60 | bool ViewColumnList(PGLOBAL g); |
61 | |
62 | // Database routines |
63 | virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n); |
64 | virtual bool InitTable(PGLOBAL g); |
65 | virtual int GetMaxSize(PGLOBAL g); |
66 | virtual bool OpenDB(PGLOBAL g); |
67 | virtual int ReadDB(PGLOBAL g); |
68 | |
69 | protected: |
70 | // Members |
71 | LPCSTR Tabname; // Name of source table |
72 | char *Colist; // Source column list |
73 | char *Xcolumn; // Occurence column name |
74 | char *Rcolumn; // Rank column name |
75 | POCCURCOL Xcolp; // To the OCCURCOL column |
76 | PCOL *Col; // To source multiple columns |
77 | int Mult; // Multiplication factor |
78 | int N; // The current table index |
79 | int M; // The occurence rank |
80 | BYTE RowFlag; // 0: Ok, 1: Same, 2: Skip |
81 | }; // end of class TDBOCCUR |
82 | |
83 | /***********************************************************************/ |
84 | /* Class OCCURCOL: for the multiple occurence column. */ |
85 | /***********************************************************************/ |
86 | class OCCURCOL : public COLBLK { |
87 | public: |
88 | // Constructors |
89 | OCCURCOL(PCOLDEF cdp, PTDBOCCUR tdbp, int n); |
90 | |
91 | // Implementation |
92 | virtual int GetAmType(void) {return TYPE_AM_OCCUR;} |
93 | int GetI(void) {return I;} |
94 | |
95 | // Methods |
96 | virtual void Reset(void) {} // Evaluated only by TDBOCCUR |
97 | virtual void ReadColumn(PGLOBAL g); |
98 | void Xreset(void) {I = 0;}; |
99 | |
100 | protected: |
101 | // Default constructor not to be used |
102 | OCCURCOL(void) {} |
103 | |
104 | // Members |
105 | int I; |
106 | }; // end of class OCCURCOL |
107 | |
108 | /***********************************************************************/ |
109 | /* Class RANKCOL: for the multiple occurence column ranking. */ |
110 | /***********************************************************************/ |
111 | class RANKCOL : public COLBLK { |
112 | public: |
113 | // Constructors |
114 | RANKCOL(PCOLDEF cdp, PTDBOCCUR tdbp, int n) : COLBLK(cdp, tdbp, n) {} |
115 | |
116 | // Implementation |
117 | virtual int GetAmType(void) {return TYPE_AM_OCCUR;} |
118 | |
119 | // Methods |
120 | virtual void ReadColumn(PGLOBAL g); |
121 | |
122 | protected: |
123 | // Default constructor not to be used |
124 | RANKCOL(void) {} |
125 | |
126 | // Members |
127 | }; // end of class RANKCOL |
128 | |
129 | /***********************************************************************/ |
130 | /* Definition of class XCOLDEF. */ |
131 | /* This class purpose is just to access COLDEF protected items! */ |
132 | /***********************************************************************/ |
133 | class XCOLDEF: public COLDEF { |
134 | friend class TDBOCCUR; |
135 | }; // end of class XCOLDEF |
136 | |
137 | |
138 | bool OcrColumns(PGLOBAL g, PQRYRES qrp, const char *col, |
139 | const char *ocr, const char *rank); |
140 | |
141 | bool OcrSrcCols(PGLOBAL g, PQRYRES qrp, const char *col, |
142 | const char *ocr, const char *rank); |
143 | |