valblk.h 12.2 KB
Newer Older
Alexander Barkov's avatar
Alexander Barkov committed
1
/*************** Valblk H Declares Source Code File (.H) ***************/
2
/*  Name: VALBLK.H    Version 2.0                                      */
Alexander Barkov's avatar
Alexander Barkov committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*                                                                     */
/*  (C) Copyright to the author Olivier BERTRAND          2005-2013    */
/*                                                                     */
/*  This file contains the VALBLK and derived classes declares.        */
/***********************************************************************/

/***********************************************************************/
/*  Include required application header files                          */
/*  assert.h     is header required when using the assert function.    */
/*  block.h      is header containing Block    global declarations.    */
/***********************************************************************/
#ifndef __VALBLK__H__
#define __VALBLK__H__
#include "value.h"

/***********************************************************************/
/*  Utility used to allocate value blocks.                             */
/***********************************************************************/
21 22 23
DllExport PVBLK AllocValBlock(PGLOBAL, void*, int, int, int, int, 
                                              bool, bool, bool);
const char *GetFmt(int type, bool un = false);
Alexander Barkov's avatar
Alexander Barkov committed
24 25 26 27 28 29 30 31

/***********************************************************************/
/*  Class VALBLK represent a base class for variable blocks.           */
/***********************************************************************/
class VALBLK : public BLOCK {
//friend void SemColData(PGLOBAL g, PSEM semp);
 public:
  // Constructors
32
  VALBLK(void *mp, int type, int nval, bool un = false);
Alexander Barkov's avatar
Alexander Barkov committed
33 34 35 36 37 38 39

  // Implementation
          int    GetNval(void) {return Nval;}
          void   SetNval(int n) {Nval = n;}
          void  *GetValPointer(void) {return Blkp;}
          void   SetValPointer(void *mp) {Blkp = mp;}
          int    GetType(void) {return Type;}
40
          int    GetPrec(void) {return Prec;}
Alexander Barkov's avatar
Alexander Barkov committed
41
          void   SetCheck(bool b) {Check = b;}
42 43 44 45 46 47
          void   MoveNull(int i, int j)
                  {if (To_Nulls) To_Nulls[j] = To_Nulls[j];}
  virtual void   SetNull(int n, bool b)
                  {if (To_Nulls) {To_Nulls[n] = (b) ? '*' : 0;}}
  virtual bool   IsNull(int n) {return To_Nulls && To_Nulls[n];}
  virtual void   SetNullable(bool b);
48
  virtual bool   IsUnsigned(void) {return Unsigned;}
Alexander Barkov's avatar
Alexander Barkov committed
49 50 51
  virtual void   Init(PGLOBAL g, bool check) = 0;
  virtual int    GetVlen(void) = 0;
  virtual PSZ    GetCharValue(int n);
52 53
  virtual char   GetTinyValue(int n) = 0;
  virtual uchar  GetUTinyValue(int n) = 0;
Alexander Barkov's avatar
Alexander Barkov committed
54
  virtual short  GetShortValue(int n) = 0;
55
  virtual ushort GetUShortValue(int n) = 0;
Alexander Barkov's avatar
Alexander Barkov committed
56
  virtual int    GetIntValue(int n) = 0;
57
  virtual uint   GetUIntValue(int n) = 0;
Alexander Barkov's avatar
Alexander Barkov committed
58
  virtual longlong GetBigintValue(int n) = 0;
59
  virtual ulonglong GetUBigintValue(int n) = 0;
Alexander Barkov's avatar
Alexander Barkov committed
60 61 62 63 64 65 66 67 68
  virtual double GetFloatValue(int n) = 0;
  virtual void   ReAlloc(void *mp, int n) {Blkp = mp; Nval = n;}
  virtual void   Reset(int n) = 0;
  virtual bool   SetFormat(PGLOBAL g, PSZ fmt, int len, int year = 0);
  virtual void   SetPrec(int p) {}
  virtual bool   IsCi(void) {return false;}

  // Methods
  virtual void   SetValue(short sval, int n) {assert(false);}
69
  virtual void   SetValue(ushort sval, int n) {assert(false);}
Alexander Barkov's avatar
Alexander Barkov committed
70
  virtual void   SetValue(int lval, int n) {assert(false);}
71
  virtual void   SetValue(uint lval, int n) {assert(false);}
Alexander Barkov's avatar
Alexander Barkov committed
72
  virtual void   SetValue(longlong lval, int n) {assert(false);}
73
  virtual void   SetValue(ulonglong lval, int n) {assert(false);}
74
  virtual void   SetValue(double fval, int n) {assert(false);}
75
  virtual void   SetValue(char cval, int n) {assert(false);}
76
  virtual void   SetValue(uchar cval, int n) {assert(false);}
Alexander Barkov's avatar
Alexander Barkov committed
77
  virtual void   SetValue(PSZ sp, int n) {assert(false);}
78
  virtual void   SetValue(char *sp, uint len, int n) {assert(false);}
Alexander Barkov's avatar
Alexander Barkov committed
79
  virtual void   SetValue(PVAL valp, int n) = 0;
80 81
  virtual void   SetValue(PVBLK pv, int n1, int n2) = 0;
#if 0
Alexander Barkov's avatar
Alexander Barkov committed
82 83 84 85
  virtual void   SetMin(PVAL valp, int n) = 0;
  virtual void   SetMax(PVAL valp, int n) = 0;
  virtual void   SetValues(PVBLK pv, int i, int n) = 0;
  virtual void   AddMinus1(PVBLK pv, int n1, int n2) {assert(false);}
86
#endif // 0
Alexander Barkov's avatar
Alexander Barkov committed
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
  virtual void   Move(int i, int j) = 0;
  virtual int    CompVal(PVAL vp, int n) = 0;
  virtual int    CompVal(int i1, int i2) = 0;
  virtual void  *GetValPtr(int n) = 0;
  virtual void  *GetValPtrEx(int n) = 0;
  virtual int    Find(PVAL vp) = 0;
  virtual int    GetMaxLength(void) = 0;
          bool   Locate(PVAL vp, int& i);

 protected:
  void ChkIndx(int n);
  void ChkTyp(PVAL v);
  void ChkTyp(PVBLK vb);

  // Members
  PGLOBAL Global;           // Used for messages and allocation
103
  char   *To_Nulls;         // Null values array
Alexander Barkov's avatar
Alexander Barkov committed
104 105
  void   *Blkp;             // To value block
  bool    Check;            // If true SetValue types must match
106
  bool    Nullable;         // True if values can be null
107
  bool    Unsigned;         // True if values are unsigned
108 109 110
  int     Type;             // Type of individual values
  int     Nval;             // Max number of values in block
  int     Prec;             // Precision of float values
Alexander Barkov's avatar
Alexander Barkov committed
111 112
  }; // end of class VALBLK

113 114 115 116 117 118 119
/***********************************************************************/
/*  Class TYPBLK: represents a block of typed values.                  */
/***********************************************************************/
template <class TYPE>
class TYPBLK : public VALBLK {
 public:
  // Constructors
120 121
  TYPBLK(void *mp, int size, int type, int prec = 0, bool un = false);
//TYPBLK(void *mp, int size, int prec, int type);
122 123 124

  // Implementation
  virtual void   Init(PGLOBAL g, bool check);
125
  virtual int    GetVlen(void) {return sizeof(TYPE);}
126
//virtual PSZ    GetCharValue(int n);
127 128
  virtual char   GetTinyValue(int n) {return (char)Typp[n];}
  virtual uchar  GetUTinyValue(int n) {return (uchar)Typp[n];}
129
  virtual short  GetShortValue(int n) {return (short)Typp[n];}
130
  virtual ushort GetUShortValue(int n) {return (ushort)Typp[n];}
131
  virtual int    GetIntValue(int n) {return (int)Typp[n];}
132
  virtual uint   GetUIntValue(int n) {return (uint)Typp[n];}
133
  virtual longlong GetBigintValue(int n) {return (longlong)Typp[n];}
134
  virtual ulonglong GetUBigintValue(int n) {return (ulonglong)Typp[n];}
135 136 137 138 139
  virtual double GetFloatValue(int n) {return (double)Typp[n];}
  virtual void   Reset(int n) {Typp[n] = 0;}

  // Methods
  virtual void   SetValue(PSZ sp, int n);
140
  virtual void   SetValue(char *sp, uint len, int n);
141 142
  virtual void   SetValue(short sval, int n)
                  {Typp[n] = (TYPE)sval; SetNull(n, false);}
143 144
  virtual void   SetValue(ushort sval, int n)
                  {Typp[n] = (TYPE)sval; SetNull(n, false);}
145 146
  virtual void   SetValue(int lval, int n)
                  {Typp[n] = (TYPE)lval; SetNull(n, false);}
147 148
  virtual void   SetValue(uint lval, int n)
                  {Typp[n] = (TYPE)lval; SetNull(n, false);}
149 150
  virtual void   SetValue(longlong lval, int n)
                  {Typp[n] = (TYPE)lval; SetNull(n, false);}
151 152
  virtual void   SetValue(ulonglong lval, int n)
                  {Typp[n] = (TYPE)lval; SetNull(n, false);}
153 154
  virtual void   SetValue(double fval, int n)
                  {Typp[n] = (TYPE)fval; SetNull(n, false);}
155 156
  virtual void   SetValue(char cval, int n)
                  {Typp[n] = (TYPE)cval; SetNull(n, false);}
157 158
  virtual void   SetValue(uchar cval, int n)
                  {Typp[n] = (TYPE)cval; SetNull(n, false);}
159 160 161 162 163 164 165 166 167 168 169 170 171
  virtual void   SetValue(PVAL valp, int n);
  virtual void   SetValue(PVBLK pv, int n1, int n2);
//virtual void   SetValues(PVBLK pv, int k, int n);
  virtual void   Move(int i, int j);
  virtual int    CompVal(PVAL vp, int n);
  virtual int    CompVal(int i1, int i2);
  virtual void  *GetValPtr(int n);
  virtual void  *GetValPtrEx(int n);
  virtual int    Find(PVAL vp);
  virtual int    GetMaxLength(void);

 protected:
  // Specialized functions
172
  static ulonglong MaxVal(void);
173 174 175 176 177 178 179 180
  TYPE GetTypedValue(PVAL vp);
  TYPE GetTypedValue(PVBLK blk, int n);

  // Members
  TYPE* const &Typp;
  const char  *Fmt;
  }; // end of class TYPBLK

Alexander Barkov's avatar
Alexander Barkov committed
181 182 183 184 185 186 187 188 189 190 191 192
/***********************************************************************/
/*  Class CHRBLK: represent a block of fixed length strings.           */
/***********************************************************************/
class CHRBLK : public VALBLK {
 public:
  // Constructors
  CHRBLK(void *mp, int size, int len, int prec, bool b);

  // Implementation
  virtual void   Init(PGLOBAL g, bool check);
  virtual int    GetVlen(void) {return Long;}
  virtual PSZ    GetCharValue(int n);
193 194
  virtual char   GetTinyValue(int n);
  virtual uchar  GetUTinyValue(int n);
Alexander Barkov's avatar
Alexander Barkov committed
195
  virtual short  GetShortValue(int n);
196
  virtual ushort GetUShortValue(int n);
Alexander Barkov's avatar
Alexander Barkov committed
197
  virtual int    GetIntValue(int n);
198
  virtual uint   GetUIntValue(int n);
Alexander Barkov's avatar
Alexander Barkov committed
199
  virtual longlong GetBigintValue(int n);
200
  virtual ulonglong GetUBigintValue(int n);
Alexander Barkov's avatar
Alexander Barkov committed
201 202 203 204 205 206 207
  virtual double GetFloatValue(int n);
  virtual void   Reset(int n);
  virtual void   SetPrec(int p) {Ci = (p != 0);}
  virtual bool   IsCi(void) {return Ci;}

  // Methods
  virtual void   SetValue(PSZ sp, int n);
208
  virtual void   SetValue(char *sp, uint len, int n);
Alexander Barkov's avatar
Alexander Barkov committed
209
  virtual void   SetValue(PVAL valp, int n);
210
  virtual void   SetValue(PVBLK pv, int n1, int n2);
211
//virtual void   SetValues(PVBLK pv, int k, int n);
Alexander Barkov's avatar
Alexander Barkov committed
212 213 214 215 216 217 218 219 220 221 222 223 224
  virtual void   Move(int i, int j);
  virtual int    CompVal(PVAL vp, int n);
  virtual int    CompVal(int i1, int i2);
  virtual void  *GetValPtr(int n);
  virtual void  *GetValPtrEx(int n);
  virtual int    Find(PVAL vp);
  virtual int    GetMaxLength(void);

 protected:
  // Members
  char* const &Chrp;             // Pointer to char buffer
  PSZ   Valp;                    // Used to make a zero ended value
  bool  Blanks;                  // True for right filling with blanks
225
  bool  Ci;                      // True if case insensitive
Alexander Barkov's avatar
Alexander Barkov committed
226 227 228 229 230 231 232 233 234 235 236 237 238 239
  int   Long;                    // Length of each string
  }; // end of class CHRBLK

/***********************************************************************/
/*  Class STRBLK: represent a block of string pointers.                */
/*  Currently this class is used only by the DECODE scalar function    */
/*  and by the MyColumn function to store date formats.                */
/***********************************************************************/
class STRBLK : public VALBLK {
 public:
  // Constructors
  STRBLK(PGLOBAL g, void *mp, int size);

  // Implementation
240 241 242
  virtual void   SetNull(int n, bool b) {if (b) {Strp[n] = NULL;}}
  virtual bool   IsNull(int n) {return Strp[n] == NULL;}
  virtual void   SetNullable(bool b) {}    // Always nullable
Alexander Barkov's avatar
Alexander Barkov committed
243 244 245
  virtual void   Init(PGLOBAL g, bool check);
  virtual int    GetVlen(void) {return sizeof(PSZ);}
  virtual PSZ    GetCharValue(int n) {return Strp[n];}
246 247 248 249 250 251 252 253
  virtual char   GetTinyValue(int n);
  virtual uchar  GetUTinyValue(int n);
  virtual short  GetShortValue(int n);
  virtual ushort GetUShortValue(int n);
  virtual int    GetIntValue(int n);
  virtual uint   GetUIntValue(int n);
  virtual longlong GetBigintValue(int n);
  virtual ulonglong GetUBigintValue(int n);
Alexander Barkov's avatar
Alexander Barkov committed
254 255 256 257 258
  virtual double GetFloatValue(int n) {return atof(Strp[n]);}
  virtual void   Reset(int n) {Strp[n] = NULL;}

  // Methods
  virtual void   SetValue(PSZ sp, int n);
259
  virtual void   SetValue(char *sp, uint len, int n);
Alexander Barkov's avatar
Alexander Barkov committed
260
  virtual void   SetValue(PVAL valp, int n);
261
  virtual void   SetValue(PVBLK pv, int n1, int n2);
262
//virtual void   SetValues(PVBLK pv, int k, int n);
Alexander Barkov's avatar
Alexander Barkov committed
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
  virtual void   Move(int i, int j);
  virtual int    CompVal(PVAL vp, int n);
  virtual int    CompVal(int i1, int i2);
  virtual void  *GetValPtr(int n);
  virtual void  *GetValPtrEx(int n);
  virtual int    Find(PVAL vp);
  virtual int    GetMaxLength(void);

 protected:
  // Members
  PSZ* const &Strp;              // Pointer to PSZ buffer
  }; // end of class STRBLK

/***********************************************************************/
/*  Class DATBLK: represents a block of time stamp values.             */
/***********************************************************************/
279
class DATBLK : public TYPBLK<int> {
Alexander Barkov's avatar
Alexander Barkov committed
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
 public:
  // Constructor
  DATBLK(void *mp, int size);

  // Implementation
  virtual bool SetFormat(PGLOBAL g, PSZ fmt, int len, int year = 0);

  // Methods
  virtual void SetValue(PSZ sp, int n);

 protected:
  // Members
  PVAL Dvalp;                    // Date value used to convert string
  }; // end of class DATBLK

#endif // __VALBLK__H__