Commit 63798ef4 authored by Olivier Bertrand's avatar Olivier Bertrand

- Rewrite some VALBLK classes as templates

- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
  instead of {0,0,0,1,0,70,0,0,0}

modified:
  storage/connect/valblk.cpp
  storage/connect/valblk.h
  storage/connect/value.cpp
  storage/connect/value.h
parent cdf3606b
This diff is collapsed.
/*************** Valblk H Declares Source Code File (.H) ***************/ /*************** Valblk H Declares Source Code File (.H) ***************/
/* Name: VALBLK.H Version 1.7 */ /* Name: VALBLK.H Version 1.8 */
/* */ /* */
/* (C) Copyright to the author Olivier BERTRAND 2005-2013 */ /* (C) Copyright to the author Olivier BERTRAND 2005-2013 */
/* */ /* */
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
/* Utility used to allocate value blocks. */ /* Utility used to allocate value blocks. */
/***********************************************************************/ /***********************************************************************/
DllExport PVBLK AllocValBlock(PGLOBAL, void*, int, int, int, int, bool, bool); DllExport PVBLK AllocValBlock(PGLOBAL, void*, int, int, int, int, bool, bool);
const char *GetFmt(int type);
/***********************************************************************/ /***********************************************************************/
/* Class VALBLK represent a base class for variable blocks. */ /* Class VALBLK represent a base class for variable blocks. */
...@@ -59,6 +60,7 @@ class VALBLK : public BLOCK { ...@@ -59,6 +60,7 @@ class VALBLK : public BLOCK {
virtual void SetValue(short sval, int n) {assert(false);} virtual void SetValue(short sval, int n) {assert(false);}
virtual void SetValue(int lval, int n) {assert(false);} virtual void SetValue(int lval, int n) {assert(false);}
virtual void SetValue(longlong lval, int n) {assert(false);} virtual void SetValue(longlong lval, int n) {assert(false);}
virtual void SetValue(double fval, int n) {assert(false);}
virtual void SetValue(PSZ sp, int n) {assert(false);} virtual void SetValue(PSZ sp, int n) {assert(false);}
virtual void SetValue(PVAL valp, int n) = 0; virtual void SetValue(PVAL valp, int n) = 0;
virtual void SetValue(PVBLK pv, int n1, int n2) = 0; virtual void SetValue(PVBLK pv, int n1, int n2) = 0;
...@@ -78,23 +80,73 @@ class VALBLK : public BLOCK { ...@@ -78,23 +80,73 @@ class VALBLK : public BLOCK {
bool Locate(PVAL vp, int& i); bool Locate(PVAL vp, int& i);
protected: protected:
#if defined(_DEBUG) || defined(DEBTRACE)
void ChkIndx(int n); void ChkIndx(int n);
void ChkPrm(PVAL v, int n);
void ChkTyp(PVAL v); void ChkTyp(PVAL v);
void ChkTyp(PVBLK vb); void ChkTyp(PVBLK vb);
#endif // _DEBUG) || DEBTRACE
// Members // Members
PGLOBAL Global; // Used for messages and allocation PGLOBAL Global; // Used for messages and allocation
char *To_Nulls; // Null values array char *To_Nulls; // Null values array
void *Blkp; // To value block void *Blkp; // To value block
int Type; // Type of individual values
int Nval; // Max number of values in block
bool Check; // If true SetValue types must match bool Check; // If true SetValue types must match
bool Nullable; // True if values can be null bool Nullable; // True if values can be null
int Type; // Type of individual values
int Nval; // Max number of values in block
int Prec; // Precision of float values
}; // end of class VALBLK }; // end of class VALBLK
/***********************************************************************/
/* Class TYPBLK: represents a block of typed values. */
/***********************************************************************/
template <class TYPE>
class TYPBLK : public VALBLK {
public:
// Constructors
TYPBLK(void *mp, int size, int type);
TYPBLK(void *mp, int size, int prec, int type);
// Implementation
virtual void Init(PGLOBAL g, bool check);
virtual int GetVlen(void) {return sizeof(int);}
//virtual PSZ GetCharValue(int n);
virtual short GetShortValue(int n) {return (short)Typp[n];}
virtual int GetIntValue(int n) {return (int)Typp[n];}
virtual longlong GetBigintValue(int n) {return (longlong)Typp[n];}
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);
virtual void SetValue(short sval, int n)
{Typp[n] = (TYPE)sval; SetNull(n, false);}
virtual void SetValue(int lval, int n)
{Typp[n] = (TYPE)lval; SetNull(n, false);}
virtual void SetValue(longlong lval, int n)
{Typp[n] = (TYPE)lval; SetNull(n, false);}
virtual void SetValue(double fval, int n)
{Typp[n] = (TYPE)fval; SetNull(n, false);}
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
TYPE GetTypedValue(PVAL vp);
TYPE GetTypedValue(PVBLK blk, int n);
TYPE GetTypedValue(PSZ s);
// Members
TYPE* const &Typp;
const char *Fmt;
}; // end of class TYPBLK
/***********************************************************************/ /***********************************************************************/
/* Class CHRBLK: represent a block of fixed length strings. */ /* Class CHRBLK: represent a block of fixed length strings. */
/***********************************************************************/ /***********************************************************************/
...@@ -119,11 +171,7 @@ class CHRBLK : public VALBLK { ...@@ -119,11 +171,7 @@ class CHRBLK : public VALBLK {
virtual void SetValue(PSZ sp, int n); virtual void SetValue(PSZ sp, int n);
virtual void SetValue(PVAL valp, int n); virtual void SetValue(PVAL valp, int n);
virtual void SetValue(PVBLK pv, int n1, int n2); virtual void SetValue(PVBLK pv, int n1, int n2);
#if 0 //virtual void SetValues(PVBLK pv, int k, int n);
virtual void SetMin(PVAL valp, int n);
virtual void SetMax(PVAL valp, int n);
virtual void SetValues(PVBLK pv, int k, int n);
#endif // 0
virtual void Move(int i, int j); virtual void Move(int i, int j);
virtual int CompVal(PVAL vp, int n); virtual int CompVal(PVAL vp, int n);
virtual int CompVal(int i1, int i2); virtual int CompVal(int i1, int i2);
...@@ -168,11 +216,7 @@ class STRBLK : public VALBLK { ...@@ -168,11 +216,7 @@ class STRBLK : public VALBLK {
virtual void SetValue(PSZ sp, int n); virtual void SetValue(PSZ sp, int n);
virtual void SetValue(PVAL valp, int n); virtual void SetValue(PVAL valp, int n);
virtual void SetValue(PVBLK pv, int n1, int n2); virtual void SetValue(PVBLK pv, int n1, int n2);
#if 0 //virtual void SetValues(PVBLK pv, int k, int n);
virtual void SetMin(PVAL valp, int n);
virtual void SetMax(PVAL valp, int n);
virtual void SetValues(PVBLK pv, int k, int n);
#endif // 0
virtual void Move(int i, int j); virtual void Move(int i, int j);
virtual int CompVal(PVAL vp, int n); virtual int CompVal(PVAL vp, int n);
virtual int CompVal(int i1, int i2); virtual int CompVal(int i1, int i2);
...@@ -186,8 +230,9 @@ class STRBLK : public VALBLK { ...@@ -186,8 +230,9 @@ class STRBLK : public VALBLK {
PSZ* const &Strp; // Pointer to PSZ buffer PSZ* const &Strp; // Pointer to PSZ buffer
}; // end of class STRBLK }; // end of class STRBLK
#if 0
/***********************************************************************/ /***********************************************************************/
/* Class SHRBLK: represents a block of int integer values. */ /* Class SHRBLK: represents a block of short integer values. */
/***********************************************************************/ /***********************************************************************/
class SHRBLK : public VALBLK { class SHRBLK : public VALBLK {
public: public:
...@@ -214,12 +259,7 @@ class SHRBLK : public VALBLK { ...@@ -214,12 +259,7 @@ class SHRBLK : public VALBLK {
{Shrp[n] = (short)lval; SetNull(n, false);} {Shrp[n] = (short)lval; SetNull(n, false);}
virtual void SetValue(PVAL valp, int n); virtual void SetValue(PVAL valp, int n);
virtual void SetValue(PVBLK pv, int n1, int n2); virtual void SetValue(PVBLK pv, int n1, int n2);
#if 0 //virtual void SetValues(PVBLK pv, int k, int n);
virtual void SetMin(PVAL valp, int n);
virtual void SetMax(PVAL valp, int n);
virtual void SetValues(PVBLK pv, int k, int n);
virtual void AddMinus1(PVBLK pv, int n1, int n2);
#endif // 0
virtual void Move(int i, int j); virtual void Move(int i, int j);
virtual int CompVal(PVAL vp, int n); virtual int CompVal(PVAL vp, int n);
virtual int CompVal(int i1, int i2); virtual int CompVal(int i1, int i2);
...@@ -261,12 +301,7 @@ class LNGBLK : public VALBLK { ...@@ -261,12 +301,7 @@ class LNGBLK : public VALBLK {
{Lngp[n] = (int)lval; SetNull(n, false);} {Lngp[n] = (int)lval; SetNull(n, false);}
virtual void SetValue(PVAL valp, int n); virtual void SetValue(PVAL valp, int n);
virtual void SetValue(PVBLK pv, int n1, int n2); virtual void SetValue(PVBLK pv, int n1, int n2);
#if 0 //virtual void SetValues(PVBLK pv, int k, int n);
virtual void SetMin(PVAL valp, int n);
virtual void SetMax(PVAL valp, int n);
virtual void SetValues(PVBLK pv, int k, int n);
virtual void AddMinus1(PVBLK pv, int n1, int n2);
#endif // 0
virtual void Move(int i, int j); virtual void Move(int i, int j);
virtual int CompVal(PVAL vp, int n); virtual int CompVal(PVAL vp, int n);
virtual int CompVal(int i1, int i2); virtual int CompVal(int i1, int i2);
...@@ -279,11 +314,12 @@ class LNGBLK : public VALBLK { ...@@ -279,11 +314,12 @@ class LNGBLK : public VALBLK {
// Members // Members
int* const &Lngp; int* const &Lngp;
}; // end of class LNGBLK }; // end of class LNGBLK
#endif // 0
/***********************************************************************/ /***********************************************************************/
/* Class DATBLK: represents a block of time stamp values. */ /* Class DATBLK: represents a block of time stamp values. */
/***********************************************************************/ /***********************************************************************/
class DATBLK : public LNGBLK { class DATBLK : public TYPBLK<int> {
public: public:
// Constructor // Constructor
DATBLK(void *mp, int size); DATBLK(void *mp, int size);
...@@ -299,6 +335,7 @@ class DATBLK : public LNGBLK { ...@@ -299,6 +335,7 @@ class DATBLK : public LNGBLK {
PVAL Dvalp; // Date value used to convert string PVAL Dvalp; // Date value used to convert string
}; // end of class DATBLK }; // end of class DATBLK
#if 0
/***********************************************************************/ /***********************************************************************/
/* Class BIGBLK: represents a block of big integer values. */ /* Class BIGBLK: represents a block of big integer values. */
/***********************************************************************/ /***********************************************************************/
...@@ -327,12 +364,7 @@ class BIGBLK : public VALBLK { ...@@ -327,12 +364,7 @@ class BIGBLK : public VALBLK {
{Lngp[n] = lval; SetNull(n, false);} {Lngp[n] = lval; SetNull(n, false);}
virtual void SetValue(PVAL valp, int n); virtual void SetValue(PVAL valp, int n);
virtual void SetValue(PVBLK pv, int n1, int n2); virtual void SetValue(PVBLK pv, int n1, int n2);
#if 0 //virtual void SetValues(PVBLK pv, int k, int n);
virtual void SetMin(PVAL valp, int n);
virtual void SetMax(PVAL valp, int n);
virtual void SetValues(PVBLK pv, int k, int n);
virtual void AddMinus1(PVBLK pv, int n1, int n2);
#endif // 0
virtual void Move(int i, int j); virtual void Move(int i, int j);
virtual int CompVal(PVAL vp, int n); virtual int CompVal(PVAL vp, int n);
virtual int CompVal(int i1, int i2); virtual int CompVal(int i1, int i2);
...@@ -369,11 +401,7 @@ class DBLBLK : public VALBLK { ...@@ -369,11 +401,7 @@ class DBLBLK : public VALBLK {
virtual void SetValue(PSZ sp, int n); virtual void SetValue(PSZ sp, int n);
virtual void SetValue(PVAL valp, int n); virtual void SetValue(PVAL valp, int n);
virtual void SetValue(PVBLK pv, int n1, int n2); virtual void SetValue(PVBLK pv, int n1, int n2);
#if 0 //virtual void SetValues(PVBLK pv, int k, int n);
virtual void SetMin(PVAL valp, int n);
virtual void SetMax(PVAL valp, int n);
virtual void SetValues(PVBLK pv, int k, int n);
#endif // 0
virtual void Move(int i, int j); virtual void Move(int i, int j);
virtual int CompVal(PVAL vp, int n); virtual int CompVal(PVAL vp, int n);
virtual int CompVal(int i1, int i2); virtual int CompVal(int i1, int i2);
...@@ -385,8 +413,8 @@ class DBLBLK : public VALBLK { ...@@ -385,8 +413,8 @@ class DBLBLK : public VALBLK {
protected: protected:
// Members // Members
double* const &Dblp; double* const &Dblp;
int Prec;
}; // end of class DBLBLK }; // end of class DBLBLK
#endif // 0
#endif // __VALBLK__H__ #endif // __VALBLK__H__
...@@ -262,6 +262,23 @@ bool IsTypeNum(int type) ...@@ -262,6 +262,23 @@ bool IsTypeNum(int type)
return false; return false;
} // end of IsTypeNum } // end of IsTypeNum
/***********************************************************************/
/* GetFmt: returns the format to use with a typed value. */
/***********************************************************************/
const char *GetFmt(int type)
{
const char *fmt = "%d";;
switch (type) {
case TYPE_STRING: fmt = "%s"; break;
case TYPE_SHORT: fmt = "%hd"; break;
case TYPE_BIGINT: fmt = "%lld"; break;
case TYPE_FLOAT: fmt = "%.*lf"; break;
} // endswitch Type
return fmt;
} // end of GetFmt
/***********************************************************************/ /***********************************************************************/
/* ConvertType: what this function does is to determine the type to */ /* ConvertType: what this function does is to determine the type to */
/* which should be converted a value so no precision would be lost. */ /* which should be converted a value so no precision would be lost. */
...@@ -430,7 +447,7 @@ PVAL AllocateValue(PGLOBAL g, PVAL valp, int newtype) ...@@ -430,7 +447,7 @@ PVAL AllocateValue(PGLOBAL g, PVAL valp, int newtype)
/***********************************************************************/ /***********************************************************************/
VALUE::VALUE(int type) : Type(type) VALUE::VALUE(int type) : Type(type)
{ {
Fmt = GetFmt(); Fmt = GetFmt(Type);
Xfmt = GetXfmt(); Xfmt = GetXfmt();
Null = false; Null = false;
Nullable = false; Nullable = false;
...@@ -438,23 +455,6 @@ VALUE::VALUE(int type) : Type(type) ...@@ -438,23 +455,6 @@ VALUE::VALUE(int type) : Type(type)
Prec = 0; Prec = 0;
} // end of VALUE constructor } // end of VALUE constructor
/***********************************************************************/
/* VALUE GetFmt: returns the format to use with typed value. */
/***********************************************************************/
const char *VALUE::GetFmt(void)
{
const char *fmt = "%d";;
switch (Type) {
case TYPE_STRING: fmt = "%s"; break;
case TYPE_SHORT: fmt = "%hd"; break;
case TYPE_BIGINT: fmt = "%lld"; break;
case TYPE_FLOAT: fmt = "%.*lf"; break;
} // endswitch Type
return fmt;
} // end of GetFmt
/***********************************************************************/ /***********************************************************************/
/* VALUE GetXfmt: returns the extended format to use with typed value. */ /* VALUE GetXfmt: returns the extended format to use with typed value. */
/***********************************************************************/ /***********************************************************************/
...@@ -1278,9 +1278,9 @@ bool DTVAL::MakeDate(PGLOBAL g, int *val, int nval) ...@@ -1278,9 +1278,9 @@ bool DTVAL::MakeDate(PGLOBAL g, int *val, int nval)
int n; int n;
bool rc = false; bool rc = false;
#if defined(WIN32) #if defined(WIN32)
struct tm datm = {0,0,0,2,0,70,0,0,0}; struct tm datm = {0,0,0,1,0,70,0,0,0};
#else // !WIN32 #else // !WIN32
struct tm datm = {0,0,0,2,0,70,0,0,0,0,0}; struct tm datm = {0,0,0,1,0,70,0,0,0,0,0};
#endif // !WIN32 #endif // !WIN32
if (trace) if (trace)
......
...@@ -111,7 +111,6 @@ class DllExport VALUE : public BLOCK { ...@@ -111,7 +111,6 @@ class DllExport VALUE : public BLOCK {
protected: protected:
virtual bool SetConstFormat(PGLOBAL, FORMAT&) = 0; virtual bool SetConstFormat(PGLOBAL, FORMAT&) = 0;
const char *GetFmt(void);
const char *GetXfmt(void); const char *GetXfmt(void);
// Constructor used by derived classes // Constructor used by derived classes
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment