1/*************** Valblk H Declares Source Code File (.H) ***************/
2/* Name: VALBLK.H Version 2.1 */
3/* */
4/* (C) Copyright to the author Olivier BERTRAND 2005-2014 */
5/* */
6/* This file contains the VALBLK and derived classes declares. */
7/***********************************************************************/
8
9/***********************************************************************/
10/* Include required application header files */
11/* assert.h is header required when using the assert function. */
12/* block.h is header containing Block global declarations. */
13/***********************************************************************/
14#ifndef __VALBLK__H__
15#define __VALBLK__H__
16#include "value.h"
17
18/***********************************************************************/
19/* Utility used to allocate value blocks. */
20/***********************************************************************/
21DllExport PVBLK AllocValBlock(PGLOBAL, void*, int, int, int, int,
22 bool, bool, bool);
23const char *GetFmt(int type, bool un = false);
24
25/***********************************************************************/
26/* DB static external variables. */
27/***********************************************************************/
28extern MBLOCK Nmblk; /* Used to initialize MBLOCK's */
29
30/***********************************************************************/
31/* Class MBVALS is a utility class for (re)allocating VALBLK's. */
32/***********************************************************************/
33class MBVALS : public BLOCK {
34//friend class LSTBLK;
35 friend class ARRAY;
36 public:
37 // Constructors
38 MBVALS(void) {Vblk = NULL; Mblk = Nmblk;}
39
40 // Methods
41 void *GetMemp(void) {return Mblk.Memp;}
42 PVBLK Allocate(PGLOBAL g, int type, int len, int prec,
43 int n, bool sub = false);
44 bool ReAllocate(PGLOBAL g, int n);
45 void Free(void);
46
47 protected:
48 // Members
49 PVBLK Vblk; // Pointer to VALBLK
50 MBLOCK Mblk; // The memory block
51 }; // end of class MBVALS
52
53typedef class MBVALS *PMBV;
54
55/***********************************************************************/
56/* Class VALBLK represent a base class for variable blocks. */
57/***********************************************************************/
58class VALBLK : public BLOCK {
59 public:
60 // Constructors
61 VALBLK(void *mp, int type, int nval, bool un = false);
62
63 // Implementation
64 int GetNval(void) {return Nval;}
65 void SetNval(int n) {Nval = n;}
66 void *GetValPointer(void) {return Blkp;}
67 void SetValPointer(void *mp) {Blkp = mp;}
68 int GetType(void) {return Type;}
69 int GetPrec(void) {return Prec;}
70 void SetCheck(bool b) {Check = b;}
71 void MoveNull(int i, int j)
72 {if (To_Nulls) To_Nulls[j] = To_Nulls[j];}
73 virtual void SetNull(int n, bool b)
74 {if (To_Nulls) {To_Nulls[n] = (b) ? '*' : 0;}}
75 virtual bool IsNull(int n) {return To_Nulls && To_Nulls[n];}
76 virtual bool IsNullable(void) {return Nullable;}
77 virtual void SetNullable(bool b);
78 virtual bool IsUnsigned(void) {return Unsigned;}
79 virtual bool Init(PGLOBAL g, bool check) = 0;
80 virtual int GetVlen(void) = 0;
81 virtual PSZ GetCharValue(int n);
82 virtual char GetTinyValue(int n) = 0;
83 virtual uchar GetUTinyValue(int n) = 0;
84 virtual short GetShortValue(int n) = 0;
85 virtual ushort GetUShortValue(int n) = 0;
86 virtual int GetIntValue(int n) = 0;
87 virtual uint GetUIntValue(int n) = 0;
88 virtual longlong GetBigintValue(int n) = 0;
89 virtual ulonglong GetUBigintValue(int n) = 0;
90 virtual double GetFloatValue(int n) = 0;
91 virtual char *GetCharString(char *p, int n) = 0;
92 virtual void ReAlloc(void *mp, int n) {Blkp = mp; Nval = n;}
93 virtual void Reset(int n) = 0;
94 virtual bool SetFormat(PGLOBAL g, PCSZ fmt, int len, int year = 0);
95 virtual void SetPrec(int p) {}
96 virtual bool IsCi(void) {return false;}
97
98 // Methods
99 virtual void SetValue(short, int) {assert(false);}
100 virtual void SetValue(ushort, int) {assert(false);}
101 virtual void SetValue(int, int) {assert(false);}
102 virtual void SetValue(uint, int) {assert(false);}
103 virtual void SetValue(longlong, int) {assert(false);}
104 virtual void SetValue(ulonglong, int) {assert(false);}
105 virtual void SetValue(double, int) {assert(false);}
106 virtual void SetValue(char, int) {assert(false);}
107 virtual void SetValue(uchar, int) {assert(false);}
108 virtual void SetValue(PCSZ, int) {assert(false);}
109 virtual void SetValue(const char *, uint, int) {assert(false);}
110 virtual void SetValue(PVAL valp, int n) = 0;
111 virtual void SetValue(PVBLK pv, int n1, int n2) = 0;
112 virtual void SetMin(PVAL valp, int n) = 0;
113 virtual void SetMax(PVAL valp, int n) = 0;
114 virtual void Move(int i, int j) = 0;
115 virtual int CompVal(PVAL vp, int n) = 0;
116 virtual int CompVal(int i1, int i2) = 0;
117 virtual void *GetValPtr(int n) = 0;
118 virtual void *GetValPtrEx(int n) = 0;
119 virtual int Find(PVAL vp) = 0;
120 virtual int GetMaxLength(void) = 0;
121 bool Locate(PVAL vp, int& i);
122
123 protected:
124 bool AllocBuff(PGLOBAL g, size_t size);
125 void ChkIndx(int n);
126 void ChkTyp(PVAL v);
127 void ChkTyp(PVBLK vb);
128
129 // Members
130 PGLOBAL Global; // Used for messages and allocation
131 MBLOCK Mblk; // Used to allocate buffer
132 char *To_Nulls; // Null values array
133 void *Blkp; // To value block
134 bool Check; // If true SetValue types must match
135 bool Nullable; // True if values can be null
136 bool Unsigned; // True if values are unsigned
137 int Type; // Type of individual values
138 int Nval; // Max number of values in block
139 int Prec; // Precision of float values
140 }; // end of class VALBLK
141
142/***********************************************************************/
143/* Class TYPBLK: represents a block of typed values. */
144/***********************************************************************/
145template <class TYPE>
146class TYPBLK : public VALBLK {
147 public:
148 // Constructors
149 TYPBLK(void *mp, int size, int type, int prec = 0, bool un = false);
150
151 // Implementation
152 virtual bool Init(PGLOBAL g, bool check);
153 virtual int GetVlen(void) {return sizeof(TYPE);}
154 virtual char GetTinyValue(int n) {return (char)Typp[n];}
155 virtual uchar GetUTinyValue(int n) {return (uchar)Typp[n];}
156 virtual short GetShortValue(int n) {return (short)Typp[n];}
157 virtual ushort GetUShortValue(int n) {return (ushort)Typp[n];}
158 virtual int GetIntValue(int n) {return (int)Typp[n];}
159 virtual uint GetUIntValue(int n) {return (uint)Typp[n];}
160 virtual longlong GetBigintValue(int n) {return (longlong)Typp[n];}
161 virtual ulonglong GetUBigintValue(int n) {return (ulonglong)Typp[n];}
162 virtual double GetFloatValue(int n) {return (double)Typp[n];}
163 virtual char *GetCharString(char *p, int n);
164 virtual void Reset(int n) {Typp[n] = 0;}
165
166 // Methods
167 using VALBLK::SetValue;
168 virtual void SetValue(PCSZ sp, int n);
169 virtual void SetValue(const char *sp, uint len, int n);
170 virtual void SetValue(short sval, int n)
171 {Typp[n] = (TYPE)sval; SetNull(n, false);}
172 virtual void SetValue(ushort sval, int n)
173 {Typp[n] = (TYPE)sval; SetNull(n, false);}
174 virtual void SetValue(int lval, int n)
175 {Typp[n] = (TYPE)lval; SetNull(n, false);}
176 virtual void SetValue(uint lval, int n)
177 {Typp[n] = (TYPE)lval; SetNull(n, false);}
178 virtual void SetValue(longlong lval, int n)
179 {Typp[n] = (TYPE)lval; SetNull(n, false);}
180 virtual void SetValue(ulonglong lval, int n)
181 {Typp[n] = (TYPE)lval; SetNull(n, false);}
182 virtual void SetValue(double fval, int n)
183 {Typp[n] = (TYPE)fval; SetNull(n, false);}
184 virtual void SetValue(char cval, int n)
185 {Typp[n] = (TYPE)cval; SetNull(n, false);}
186 virtual void SetValue(uchar cval, int n)
187 {Typp[n] = (TYPE)cval; SetNull(n, false);}
188 virtual void SetValue(PVAL valp, int n);
189 virtual void SetValue(PVBLK pv, int n1, int n2);
190 virtual void SetMin(PVAL valp, int n);
191 virtual void SetMax(PVAL valp, int n);
192 virtual void Move(int i, int j);
193 virtual int CompVal(PVAL vp, int n);
194 virtual int CompVal(int i1, int i2);
195 virtual void *GetValPtr(int n);
196 virtual void *GetValPtrEx(int n);
197 virtual int Find(PVAL vp);
198 virtual int GetMaxLength(void);
199
200 protected:
201 // Specialized functions
202 static ulonglong MaxVal(void);
203 TYPE GetTypedValue(PVAL vp);
204 TYPE GetTypedValue(PVBLK blk, int n);
205
206 // Members
207 TYPE* const &Typp;
208 const char *Fmt;
209 }; // end of class TYPBLK
210
211/***********************************************************************/
212/* Class CHRBLK: represent a block of fixed length strings. */
213/***********************************************************************/
214class CHRBLK : public VALBLK {
215 public:
216 // Constructors
217 CHRBLK(void *mp, int size, int type, int len, int prec, bool b);
218
219 // Implementation
220 virtual bool Init(PGLOBAL g, bool check);
221 virtual int GetVlen(void) {return Long;}
222 virtual PSZ GetCharValue(int n);
223 virtual char GetTinyValue(int n);
224 virtual uchar GetUTinyValue(int n);
225 virtual short GetShortValue(int n);
226 virtual ushort GetUShortValue(int n);
227 virtual int GetIntValue(int n);
228 virtual uint GetUIntValue(int n);
229 virtual longlong GetBigintValue(int n);
230 virtual ulonglong GetUBigintValue(int n);
231 virtual double GetFloatValue(int n);
232 virtual char *GetCharString(char *p, int n);
233 virtual void Reset(int n);
234 virtual void SetPrec(int p) {Ci = (p != 0);}
235 virtual bool IsCi(void) {return Ci;}
236
237 // Methods
238 using VALBLK::SetValue;
239 virtual void SetValue(PCSZ sp, int n);
240 virtual void SetValue(const char *sp, uint len, int n);
241 virtual void SetValue(PVAL valp, int n);
242 virtual void SetValue(PVBLK pv, int n1, int n2);
243 virtual void SetMin(PVAL valp, int n);
244 virtual void SetMax(PVAL valp, int n);
245 virtual void Move(int i, int j);
246 virtual int CompVal(PVAL vp, int n);
247 virtual int CompVal(int i1, int i2);
248 virtual void *GetValPtr(int n);
249 virtual void *GetValPtrEx(int n);
250 virtual int Find(PVAL vp);
251 virtual int GetMaxLength(void);
252
253 protected:
254 // Members
255 char* const &Chrp; // Pointer to char buffer
256 PSZ Valp; // Used to make a zero ended value
257 bool Blanks; // True for right filling with blanks
258 bool Ci; // True if case insensitive
259 int Long; // Length of each string
260 }; // end of class CHRBLK
261
262/***********************************************************************/
263/* Class STRBLK: represent a block of string pointers. */
264/* Currently this class is used only by the DECODE scalar function */
265/* and by the MyColumn function to store date formats. */
266/***********************************************************************/
267class STRBLK : public VALBLK {
268 public:
269 // Constructors
270 STRBLK(PGLOBAL g, void *mp, int size, int type);
271
272 // Implementation
273 virtual void SetNull(int n, bool b) {if (b) {Strp[n] = NULL;}}
274 virtual bool IsNull(int n) {return Strp[n] == NULL;}
275 virtual void SetNullable(bool) {} // Always nullable
276 virtual bool Init(PGLOBAL g, bool check);
277 virtual int GetVlen(void) {return sizeof(PSZ);}
278 virtual PSZ GetCharValue(int n) {return Strp[n];}
279 virtual char GetTinyValue(int n);
280 virtual uchar GetUTinyValue(int n);
281 virtual short GetShortValue(int n);
282 virtual ushort GetUShortValue(int n);
283 virtual int GetIntValue(int n);
284 virtual uint GetUIntValue(int n);
285 virtual longlong GetBigintValue(int n);
286 virtual ulonglong GetUBigintValue(int n);
287 virtual double GetFloatValue(int n) {return atof(Strp[n]);}
288 virtual char *GetCharString(char *, int n) {return Strp[n];}
289 virtual void Reset(int n) {Strp[n] = NULL;}
290
291 // Methods
292 using VALBLK::SetValue;
293 virtual void SetValue(PCSZ sp, int n);
294 virtual void SetValue(const char *sp, uint len, int n);
295 virtual void SetValue(PVAL valp, int n);
296 virtual void SetValue(PVBLK pv, int n1, int n2);
297 virtual void SetMin(PVAL valp, int n);
298 virtual void SetMax(PVAL valp, int n);
299 virtual void Move(int i, int j);
300 virtual int CompVal(PVAL vp, int n);
301 virtual int CompVal(int i1, int i2);
302 virtual void *GetValPtr(int n);
303 virtual void *GetValPtrEx(int n);
304 virtual int Find(PVAL vp);
305 virtual int GetMaxLength(void);
306
307 // Specific
308 void SetSorted(bool b) {Sorted = b;}
309
310 protected:
311 // Members
312 PSZ* const &Strp; // Pointer to PSZ buffer
313 bool Sorted; // Values are (semi?) sorted
314 }; // end of class STRBLK
315
316/***********************************************************************/
317/* Class DATBLK: represents a block of time stamp values. */
318/***********************************************************************/
319class DATBLK : public TYPBLK<int> {
320 public:
321 // Constructor
322 DATBLK(void *mp, int size);
323
324 // Implementation
325 virtual bool SetFormat(PGLOBAL g, PCSZ fmt, int len, int year = 0);
326 virtual char *GetCharString(char *p, int n);
327
328 // Methods
329 using TYPBLK<int>::SetValue;
330 virtual void SetValue(PCSZ sp, int n);
331
332 protected:
333 // Members
334 PVAL Dvalp; // Date value used to convert string
335 }; // end of class DATBLK
336
337/***********************************************************************/
338/* Class PTRBLK: represent a block of char pointers. */
339/* Currently this class is used only by the ARRAY class to make and */
340/* sort a list of char pointers. */
341/***********************************************************************/
342class PTRBLK : public STRBLK {
343 friend class ARRAY;
344 friend PVBLK AllocValBlock(PGLOBAL, void *, int, int, int, int,
345 bool, bool, bool);
346 protected:
347 // Constructors
348 PTRBLK(PGLOBAL g, void *mp, int size) : STRBLK(g, mp, size, TYPE_PCHAR) {}
349
350 // Implementation
351
352 // Methods
353 using STRBLK::SetValue;
354 using STRBLK::CompVal;
355 virtual void SetValue(PCSZ p, int n) {Strp[n] = (char*)p;}
356 virtual int CompVal(int i1, int i2);
357
358 protected:
359 // Members
360 }; // end of class PTRBLK
361
362#endif // __VALBLK__H__
363
364