1/*************** Filter H Declares Source Code File (.H) ***************/
2/* Name: FILTER.H Version 1.3 */
3/* */
4/* (C) Copyright to the author Olivier BERTRAND 2010-2017 */
5/* */
6/* This file contains the FILTER and derived classes declares. */
7/***********************************************************************/
8#ifndef __FILTER__
9#define __FILTER__
10
11/***********************************************************************/
12/* Include required application header files */
13/***********************************************************************/
14#include "xobject.h"
15
16/***********************************************************************/
17/* Utilities for WHERE condition building. */
18/***********************************************************************/
19PFIL MakeFilter(PGLOBAL g, PFIL filp, OPVAL vop, PFIL fp);
20PFIL MakeFilter(PGLOBAL g, PCOL *colp, POPER pop, PPARM pfirst, bool neg);
21
22/***********************************************************************/
23/* Definition of class FILTER with all its method functions. */
24/* Note: Most virtual implementation functions are not in use yet */
25/* but could be in future system evolution. */
26/***********************************************************************/
27class DllExport FILTER : public XOBJECT { /* Filter description block */
28//friend PFIL PrepareFilter(PGLOBAL, PFIL, bool);
29 friend DllExport bool ApplyFilter(PGLOBAL, PFIL);
30 public:
31 // Constructors
32 FILTER(PGLOBAL g, POPER pop, PPARM *tp = NULL);
33 FILTER(PGLOBAL g, OPVAL opc, PPARM *tp = NULL);
34 FILTER(PFIL fil1);
35
36 // Implementation
37 virtual int GetType(void) {return TYPE_FILTER;}
38 virtual int GetResultType(void) {return TYPE_INT;}
39 virtual int GetLength(void) {return 1;}
40 virtual int GetLengthEx(void) {assert(FALSE); return 0;}
41 virtual int GetScale() {return 0;};
42 PFIL GetNext(void) {return Next;}
43 OPVAL GetOpc(void) {return Opc;}
44 int GetOpm(void) {return Opm;}
45 int GetArgType(int i) {return Arg(i)->GetType();}
46 bool GetResult(void) {return Value->GetIntValue() != 0;}
47 PXOB &Arg(int i) {return Test[i].Arg;}
48 PVAL &Val(int i) {return Test[i].Value;}
49 bool &Conv(int i) {return Test[i].Conv;}
50 void SetNext(PFIL filp) {Next = filp;}
51
52 // Methods
53 virtual void Reset(void);
54 virtual bool Compare(PXOB) {return FALSE;} // Not used yet
55 virtual bool Init(PGLOBAL);
56 virtual bool Eval(PGLOBAL);
57 virtual bool SetFormat(PGLOBAL, FORMAT&) {return TRUE;} // NUY
58//virtual int CheckColumn(PGLOBAL g, PSQL sqlp, PXOB &xp, int &ag);
59//virtual int RefNum(PSQL);
60//virtual PXOB SetSelect(PGLOBAL, PSQL, bool) {return NULL;} // NUY
61//virtual PXOB CheckSubQuery(PGLOBAL, PSQL);
62//virtual bool CheckLocal(PTDB);
63//virtual int CheckSpcCol(PTDB tdbp, int n);
64 virtual void Printf(PGLOBAL g, FILE *f, uint n);
65 virtual void Prints(PGLOBAL g, char *ps, uint z);
66// PFIL Linearize(bool nosep);
67// PFIL Link(PGLOBAL g, PFIL fil2);
68// PFIL RemoveLastSep(void);
69// PFIL SortJoin(PGLOBAL g);
70// bool FindJoinFilter(POPJOIN opj, PFIL fprec, bool teq,
71// bool tek, bool tk2, bool tc2, bool tix, bool thx);
72// bool CheckHaving(PGLOBAL g, PSQL sqlp);
73 bool Convert(PGLOBAL g, bool having);
74// int SplitFilter(PFIL *fp);
75// int SplitFilter(PFIL *fp, PTDB tp, int n);
76// PFIL LinkFilter(PGLOBAL g, PFIL fp2);
77// PFIL Copy(PTABS t);
78
79 protected:
80 FILTER(void) {} // Standard constructor not to be used
81 void Constr(PGLOBAL g, OPVAL opc, int opm, PPARM *tp);
82
83 // Members
84 PFIL Next; // Used for linearization
85 OPVAL Opc; // Comparison operator
86 int Opm; // Modificator
87 BYTE Bt; // Operator bitmap
88 struct {
89 int B_T; // Buffer type
90 PXOB Arg; // Points to argument
91 PVAL Value; // Points to argument value
92 bool Conv; // TRUE if argument must be converted
93 } Test[2];
94 }; // end of class FILTER
95
96/***********************************************************************/
97/* Derived class FILTERX: used to replace a filter by a derived class */
98/* using an Eval method optimizing the filtering evaluation. */
99/* Note: this works only if the members of the derived class are the */
100/* same than the ones of the original class (NO added members). */
101/***********************************************************************/
102class FILTERX : public FILTER {
103 public:
104 // Methods
105 virtual bool Eval(PGLOBAL) = 0; // just to prevent direct FILTERX use
106
107 // Fake operator new used to change a filter into a derived filter
108 void * operator new(size_t, PFIL filp) {return filp;}
109#if defined(__WIN__)
110 // Avoid warning C4291 by defining a matching dummy delete operator
111 void operator delete(void *, PFIL) {}
112#else
113 void operator delete(void *) {}
114#endif
115 }; // end of class FILTERX
116
117/***********************************************************************/
118/* Derived class FILTEREQ: OP_EQ, no conversion and Xobject args. */
119/***********************************************************************/
120class FILTERCMP : public FILTERX {
121 public:
122 // Constructor
123 FILTERCMP(PGLOBAL g);
124
125 // Methods
126 virtual bool Eval(PGLOBAL);
127 }; // end of class FILTEREQ
128
129/***********************************************************************/
130/* Derived class FILTERAND: OP_AND, no conversion and Xobject args. */
131/***********************************************************************/
132class FILTERAND : public FILTERX {
133 public:
134 // Methods
135 virtual bool Eval(PGLOBAL);
136 }; // end of class FILTERAND
137
138/***********************************************************************/
139/* Derived class FILTEROR: OP_OR, no conversion and Xobject args. */
140/***********************************************************************/
141class FILTEROR : public FILTERX {
142 public:
143 // Methods
144 virtual bool Eval(PGLOBAL);
145 }; // end of class FILTEROR
146
147/***********************************************************************/
148/* Derived class FILTERNOT: OP_NOT, no conversion and Xobject args. */
149/***********************************************************************/
150class FILTERNOT : public FILTERX {
151 public:
152 // Methods
153 virtual bool Eval(PGLOBAL);
154 }; // end of class FILTERNOT
155
156/***********************************************************************/
157/* Derived class FILTERIN: OP_IN, no conversion and Array 2nd arg. */
158/***********************************************************************/
159class FILTERIN : public FILTERX {
160 public:
161 // Methods
162 virtual bool Eval(PGLOBAL);
163 }; // end of class FILTERIN
164
165/***********************************************************************/
166/* Derived class FILTERTRUE: Always returns TRUE. */
167/***********************************************************************/
168class FILTERTRUE : public FILTERX {
169 public:
170 // Constructor
171 FILTERTRUE(PVAL valp) {Value = valp; Value->SetValue_bool(TRUE);}
172
173 // Methods
174 virtual void Reset(void);
175 virtual bool Eval(PGLOBAL);
176 }; // end of class FILTERTRUE
177
178#endif // __FILTER__
179