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
/************ Valblk C++ Functions Source Code File (.CPP) *************/
/* Name: VALBLK.CPP Version 1.5 */
/* Name: VALBLK.CPP Version 1.6 */
/* */
/* (C) Copyright to the author Olivier BERTRAND 2005-2013 */
/* */
......@@ -14,8 +14,9 @@
/* to avoid too complicated classes and unuseful duplication of many */
/* functions used on one family only. The drawback is that for new */
/* types of objects, we shall have more classes to update. */
/* Currently the only implemented types are STRING, int and DOUBLE. */
/* Shortly we should add at least int VARCHAR and DATE. */
/* This is why we are now using a template class for many types. */
/* Currently the only implemented types are PSZ, chars, int, short, */
/* DATE, longlong, and double. Shortly we should add more types. */
/***********************************************************************/
/***********************************************************************/
......@@ -39,49 +40,7 @@
#include "plgdbsem.h"
#include "valblk.h"
/***********************************************************************/
/* Check macro's. */
/***********************************************************************/
#if defined(_DEBUG) || defined(DEBTRACE)
#define CheckIndex(N) ChkIndx(N);
void VALBLK::ChkIndx(int n) {
if (n >= Nval) {
PGLOBAL& g = Global;
strcpy(g->Message, MSG(BAD_VALBLK_INDX));
longjmp(g->jumper[g->jump_level], Type);
} // endif N
} // end of ChkIndx
#define CheckParms(V,N) ChkPrm(V,N);
void VALBLK::ChkPrm(PVAL v, int n) {
ChkIndx(n);
if (Check && Type != v->GetType()) {
PGLOBAL& g = Global;
strcpy(g->Message, MSG(VALTYPE_NOMATCH));
longjmp(g->jumper[g->jump_level], Type);
} // endif Check
} // end of ChkPrm
#define CheckBlanks assert(!Blanks);
#define CheckType(V) ChkTyp(V);
void VALBLK::ChkTyp(PVAL v) {
if (Type != v->GetType()) {
PGLOBAL& g = Global;
strcpy(g->Message, MSG(VALTYPE_NOMATCH));
longjmp(g->jumper[g->jump_level], Type);
} // endif Type
} // end of ChkTyp
void VALBLK::ChkTyp(PVBLK vb) {
if (Type != vb->GetType()) {
PGLOBAL& g = Global;
strcpy(g->Message, MSG(VALTYPE_NOMATCH));
longjmp(g->jumper[g->jump_level], Type);
} // endif Type
} // end of ChkTyp
#else
#define CheckIndex(N)
#define CheckParms(V,N)
#define CheckBlanks
#define CheckType(V)
#endif
/***********************************************************************/
/* AllocValBlock: allocate a VALBLK according to type. */
......@@ -105,19 +64,19 @@ PVBLK AllocValBlock(PGLOBAL g, void *mp, int type, int nval, int len,
break;
case TYPE_SHORT:
blkp = new(g) SHRBLK(mp, nval);
blkp = new(g) TYPBLK<short>(mp, nval, type);
break;
case TYPE_INT:
blkp = new(g) LNGBLK(mp, nval);
blkp = new(g) TYPBLK<int>(mp, nval, type);
break;
case TYPE_DATE: // ?????
blkp = new(g) DATBLK(mp, nval);
break;
case TYPE_BIGINT:
blkp = new(g) BIGBLK(mp, nval);
blkp = new(g) TYPBLK<longlong>(mp, nval, type);
break;
case TYPE_FLOAT:
blkp = new(g) DBLBLK(mp, nval, prec);
blkp = new(g) TYPBLK<double>(mp, nval, prec, type);
break;
default:
sprintf(g->Message, MSG(BAD_VALBLK_TYPE), type);
......@@ -137,10 +96,11 @@ VALBLK::VALBLK(void *mp, int type, int nval)
{
Blkp = mp;
To_Nulls = NULL;
Type = type;
Nval = nval;
Check = true;
Nullable = false;
Type = type;
Nval = nval;
Prec = 0;
} // end of VALBLK constructor
/***********************************************************************/
......@@ -172,7 +132,7 @@ bool VALBLK::SetFormat(PGLOBAL g, PSZ fmt, int len, int year)
/***********************************************************************/
bool VALBLK::Locate(PVAL vp, int& i)
{
CheckType(vp)
ChkTyp(vp);
int n = 1;
......@@ -187,14 +147,289 @@ bool VALBLK::Locate(PVAL vp, int& i)
/* Set Nullable and allocate the Null array. */
/***********************************************************************/
void VALBLK::SetNullable(bool b)
{
{
if ((Nullable = b)) {
To_Nulls = (char*)PlugSubAlloc(Global, NULL, Nval);
memset(To_Nulls, 0, Nval);
} else
To_Nulls = NULL;
} // end of SetNullable
} // end of SetNullable
/***********************************************************************/
/* Check functions. */
/***********************************************************************/
void VALBLK::ChkIndx(int n)
{
if (n < 0 || n >= Nval) {
PGLOBAL& g = Global;
strcpy(g->Message, MSG(BAD_VALBLK_INDX));
longjmp(g->jumper[g->jump_level], Type);
} // endif n
} // end of ChkIndx
void VALBLK::ChkTyp(PVAL v)
{
if (Check && Type != v->GetType()) {
PGLOBAL& g = Global;
strcpy(g->Message, MSG(VALTYPE_NOMATCH));
longjmp(g->jumper[g->jump_level], Type);
} // endif Type
} // end of ChkTyp
void VALBLK::ChkTyp(PVBLK vb)
{
if (Check && Type != vb->GetType()) {
PGLOBAL& g = Global;
strcpy(g->Message, MSG(VALTYPE_NOMATCH));
longjmp(g->jumper[g->jump_level], Type);
} // endif Type
} // end of ChkTyp
/* -------------------------- Class TYPBLK --------------------------- */
/***********************************************************************/
/* Constructors. */
/***********************************************************************/
template <class TYPE>
TYPBLK<TYPE>::TYPBLK(void *mp, int nval, int type)
: VALBLK(mp, type, nval), Typp((TYPE*&)Blkp)
{
Fmt = GetFmt(Type);
} // end of TYPBLK constructor
template <class TYPE>
TYPBLK<TYPE>::TYPBLK(void *mp, int nval, int prec, int type)
: VALBLK(mp, type, nval), Typp((TYPE*&)Blkp)
{
DBUG_ASSERT(Type == TYPE_FLOAT);
Prec = prec;
Fmt = GetFmt(Type);
} // end of DBLBLK constructor
/***********************************************************************/
/* Initialization routine. */
/***********************************************************************/
template <class TYPE>
void TYPBLK<TYPE>::Init(PGLOBAL g, bool check)
{
if (!Blkp)
Blkp = PlugSubAlloc(g, NULL, Nval * sizeof(TYPE));
Check = check;
Global = g;
} // end of Init
/***********************************************************************/
/* Set one value in a block. */
/***********************************************************************/
template <class TYPE>
void TYPBLK<TYPE>::SetValue(PVAL valp, int n)
{
bool b;
ChkIndx(n);
ChkTyp(valp);
if (!(b = valp->IsNull() && Nullable))
Typp[n] = GetTypedValue(valp);
else
Reset(n);
SetNull(n, b);
} // end of SetValue
template <>
int TYPBLK<int>::GetTypedValue(PVAL valp)
{return valp->GetIntValue();}
template <>
short TYPBLK<short>::GetTypedValue(PVAL valp)
{return valp->GetShortValue();}
template <>
longlong TYPBLK<longlong>::GetTypedValue(PVAL valp)
{return valp->GetBigintValue();}
template <>
double TYPBLK<double>::GetTypedValue(PVAL valp)
{return valp->GetFloatValue();}
/***********************************************************************/
/* Set one value in a block. */
/***********************************************************************/
template <class TYPE>
void TYPBLK<TYPE>::SetValue(PSZ p, int n)
{
ChkIndx(n);
if (Check) {
PGLOBAL& g = Global;
strcpy(g->Message, MSG(BAD_SET_STRING));
longjmp(g->jumper[g->jump_level], Type);
} // endif Check
Typp[n] = GetTypedValue(p);
SetNull(n, false);
} // end of SetValue
template <>
int TYPBLK<int>::GetTypedValue(PSZ p) {return atol(p);}
template <>
short TYPBLK<short>::GetTypedValue(PSZ p) {return (short)atoi(p);}
template <>
longlong TYPBLK<longlong>::GetTypedValue(PSZ p) {return atoll(p);}
template <>
double TYPBLK<double>::GetTypedValue(PSZ p) {return atof(p);}
/***********************************************************************/
/* Set one value in a block from a value in another block. */
/***********************************************************************/
template <class TYPE>
void TYPBLK<TYPE>::SetValue(PVBLK pv, int n1, int n2)
{
bool b;
ChkIndx(n1);
ChkTyp(pv);
if (!(b = pv->IsNull(n2) && Nullable))
Typp[n1] = GetTypedValue(pv, n2);
else
Reset(n1);
SetNull(n1, b);
} // end of SetValue
template <>
int TYPBLK<int>::GetTypedValue(PVBLK blk, int n)
{return blk->GetIntValue(n);}
template <>
short TYPBLK<short>::GetTypedValue(PVBLK blk, int n)
{return blk->GetShortValue(n);}
template <>
longlong TYPBLK<longlong>::GetTypedValue(PVBLK blk, int n)
{return blk->GetBigintValue(n);}
template <>
double TYPBLK<double>::GetTypedValue(PVBLK blk, int n)
{return blk->GetFloatValue(n);}
#if 0
/***********************************************************************/
/* Set many values in a block from values in another block. */
/***********************************************************************/
template <class TYPE>
void TYPBLK<TYPE>::SetValues(PVBLK pv, int k, int n)
{
CheckType(pv)
TYPE *lp = ((TYPBLK*)pv)->Typp;
for (register int i = k; i < n; i++) // TODO
Typp[i] = lp[i];
} // end of SetValues
#endif // 0
/***********************************************************************/
/* Move one value from i to j. */
/***********************************************************************/
template <class TYPE>
void TYPBLK<TYPE>::Move(int i, int j)
{
Typp[j] = Typp[i];
MoveNull(i, j);
} // end of Move
/***********************************************************************/
/* Compare a Value object with the nth value of the block. */
/***********************************************************************/
template <class TYPE>
int TYPBLK<TYPE>::CompVal(PVAL vp, int n)
{
#if defined(_DEBUG)
ChkIndx(n);
ChkTyp(vp);
#endif // _DEBUG
TYPE mlv = Typp[n];
TYPE vlv = GetTypedValue(vp);
return (vlv > mlv) ? 1 : (vlv < mlv) ? (-1) : 0;
} // end of CompVal
/***********************************************************************/
/* Compare two values of the block. */
/***********************************************************************/
template <class TYPE>
int TYPBLK<TYPE>::CompVal(int i1, int i2)
{
TYPE lv1 = Typp[i1];
TYPE lv2 = Typp[i2];
return (lv1 > lv2) ? 1 : (lv1 < lv2) ? (-1) : 0;
} // end of CompVal
/***********************************************************************/
/* Get a pointer on the nth value of the block. */
/***********************************************************************/
template <class TYPE>
void *TYPBLK<TYPE>::GetValPtr(int n)
{
ChkIndx(n);
return Typp + n;
} // end of GetValPtr
/***********************************************************************/
/* Get a pointer on the nth value of the block. */
/***********************************************************************/
template <class TYPE>
void *TYPBLK<TYPE>::GetValPtrEx(int n)
{
ChkIndx(n);
return Typp + n;
} // end of GetValPtrEx
/***********************************************************************/
/* Returns index of matching value in block or -1. */
/***********************************************************************/
template <class TYPE>
int TYPBLK<TYPE>::Find(PVAL vp)
{
ChkTyp(vp);
int i;
TYPE n = GetTypedValue(vp);
for (i = 0; i < Nval; i++)
if (n == Typp[i])
break;
return (i < Nval) ? i : (-1);
} // end of Find
/***********************************************************************/
/* Returns the length of the longest string in the block. */
/***********************************************************************/
template <class TYPE>
int TYPBLK<TYPE>::GetMaxLength(void)
{
char buf[12];
int i, n;
for (i = n = 0; i < Nval; i++) {
sprintf(buf, Fmt, Typp[i]);
n = max(n, (signed)strlen(buf));
} // endfor i
return n;
} // end of GetMaxLength
/* -------------------------- Class CHRBLK --------------------------- */
......@@ -282,9 +517,11 @@ double CHRBLK::GetFloatValue(int n)
/***********************************************************************/
void CHRBLK::SetValue(PVAL valp, int n)
{
CheckParms(valp, n)
bool b;
ChkIndx(n);
ChkTyp(valp);
if (!(b = valp->IsNull() && Nullable))
SetValue((PSZ)valp->GetCharValue(), n);
else
......@@ -327,14 +564,13 @@ void CHRBLK::SetValue(PSZ sp, int n)
/***********************************************************************/
void CHRBLK::SetValue(PVBLK pv, int n1, int n2)
{
#if defined(_DEBUG) || defined(DEBTRACE)
bool b;
if (Type != pv->GetType() || Long != ((CHRBLK*)pv)->Long) {
PGLOBAL& g = Global;
strcpy(g->Message, MSG(BLKTYPLEN_MISM));
longjmp(g->jumper[g->jump_level], Type);
} // endif Type
#endif
bool b;
if (!(b = pv->IsNull(n2) && Nullable))
memcpy(Chrp + n1 * Long, ((CHRBLK*)pv)->Chrp + n2 * Long, Long);
......@@ -365,36 +601,6 @@ void CHRBLK::SetValues(PVBLK pv, int k, int n)
memcpy(Chrp + k * Long, p + k * Long, Long * (n - k));
} // end of SetValues
/***********************************************************************/
/* Set one value in a block if val is less than the current value. */
/***********************************************************************/
void CHRBLK::SetMin(PVAL valp, int n)
{
CheckParms(valp, n)
CheckBlanks
char *vp = valp->GetCharValue();
char *bp = Chrp + n * Long;
if (((Ci) ? strnicmp(vp, bp, Long) : strncmp(vp, bp, Long)) < 0)
memcpy(bp, vp, Long);
} // end of SetMin
/***********************************************************************/
/* Set one value in a block if val is greater than the current value. */
/***********************************************************************/
void CHRBLK::SetMax(PVAL valp, int n)
{
CheckParms(valp, n)
CheckBlanks
char *vp = valp->GetCharValue();
char *bp = Chrp + n * Long;
if (((Ci) ? strnicmp(vp, bp, Long) : strncmp(vp, bp, Long)) > 0)
memcpy(bp, vp, Long);
} // end of SetMax
#endif // 0
/***********************************************************************/
......@@ -411,7 +617,9 @@ void CHRBLK::Move(int i, int j)
/***********************************************************************/
int CHRBLK::CompVal(PVAL vp, int n)
{
CheckParms(vp, n)
ChkIndx(n);
ChkTyp(vp);
char *xvp = vp->GetCharValue(); // Get Value zero ended string
bool ci = Ci || vp->IsCi(); // true if is case insensitive
......@@ -433,7 +641,7 @@ int CHRBLK::CompVal(int i1, int i2)
/***********************************************************************/
void *CHRBLK::GetValPtr(int n)
{
CheckIndex(n)
ChkIndx(n);
return Chrp + n * Long;
} // end of GetValPtr
......@@ -442,7 +650,7 @@ void *CHRBLK::GetValPtr(int n)
/***********************************************************************/
void *CHRBLK::GetValPtrEx(int n)
{
CheckIndex(n)
ChkIndx(n);
memcpy(Valp, Chrp + n * Long, Long);
if (IsNull(n))
......@@ -468,7 +676,8 @@ void *CHRBLK::GetValPtrEx(int n)
/***********************************************************************/
int CHRBLK::Find(PVAL vp)
{
CheckType(vp)
ChkTyp(vp);
int i;
bool ci = Ci || vp->IsCi();
PSZ s = vp->GetCharValue();
......@@ -536,8 +745,7 @@ void STRBLK::Init(PGLOBAL g, bool check)
/***********************************************************************/
void STRBLK::SetValue(PVBLK pv, int n1, int n2)
{
CheckType(pv)
ChkTyp(pv);
Strp[n1] = (!pv->IsNull(n2)) ? ((STRBLK*)pv)->Strp[n2] : NULL;
} // end of SetValue
......@@ -561,7 +769,8 @@ void STRBLK::SetValues(PVBLK pv, int k, int n)
/***********************************************************************/
void STRBLK::SetValue(PVAL valp, int n)
{
CheckParms(valp, n)
ChkIndx(n);
ChkTyp(valp);
if (!valp->IsNull())
SetValue((PSZ)valp->GetCharValue(), n);
......@@ -579,36 +788,6 @@ void STRBLK::SetValue(PSZ p, int n)
strcpy(Strp[n], p);
} // end of SetValue
#if 0
/***********************************************************************/
/* Set one value in a block if val is less than the current value. */
/***********************************************************************/
void STRBLK::SetMin(PVAL valp, int n)
{
CheckParms(valp, n)
char *vp = valp->GetCharValue();
char *bp = Strp[n];
if (strcmp(vp, bp) < 0)
SetValue(valp, n);
} // end of SetMin
/***********************************************************************/
/* Set one value in a block if val is greater than the current value. */
/***********************************************************************/
void STRBLK::SetMax(PVAL valp, int n)
{
CheckParms(valp, n)
char *vp = valp->GetCharValue();
char *bp = Strp[n];
if (strcmp(vp, bp) > 0)
SetValue(valp, n);
} // end of SetMax
#endif // 0
/***********************************************************************/
/* Move one value from i to j. */
/***********************************************************************/
......@@ -622,7 +801,8 @@ void STRBLK::Move(int i, int j)
/***********************************************************************/
int STRBLK::CompVal(PVAL vp, int n)
{
CheckParms(vp, n)
ChkIndx(n);
ChkTyp(vp);
if (vp->IsNull() || !Strp[n])
DBUG_ASSERT(false);
......@@ -635,7 +815,7 @@ int STRBLK::CompVal(PVAL vp, int n)
/***********************************************************************/
int STRBLK::CompVal(int i1, int i2)
{
if (!Strp[i1] || Strp[i2])
if (!Strp[i1] || !Strp[i2])
DBUG_ASSERT(false);
return (strcmp(Strp[i1], Strp[i2]));
......@@ -646,7 +826,7 @@ int STRBLK::CompVal(int i1, int i2)
/***********************************************************************/
void *STRBLK::GetValPtr(int n)
{
CheckIndex(n)
ChkIndx(n);
return Strp + n;
} // end of GetValPtr
......@@ -655,7 +835,7 @@ void *STRBLK::GetValPtr(int n)
/***********************************************************************/
void *STRBLK::GetValPtrEx(int n)
{
CheckIndex(n)
ChkIndx(n);
return (Strp[n]) ? Strp[n] : "";
} // end of GetValPtrEx
......@@ -664,10 +844,11 @@ void *STRBLK::GetValPtrEx(int n)
/***********************************************************************/
int STRBLK::Find(PVAL vp)
{
CheckType(vp)
int i;
PSZ s;
ChkTyp(vp);
if (vp->IsNull())
return -1;
else
......@@ -694,7 +875,7 @@ int STRBLK::GetMaxLength(void)
return n;
} // end of GetMaxLength
#if 0
/* -------------------------- Class SHRBLK --------------------------- */
/***********************************************************************/
......@@ -766,34 +947,6 @@ void SHRBLK::SetValue(PVBLK pv, int n1, int n2)
} // end of SetValue
#if 0
/***********************************************************************/
/* Set one value in a block if val is less than the current value. */
/***********************************************************************/
void SHRBLK::SetMin(PVAL valp, int n)
{
CheckParms(valp, n)
short sval = valp->GetShortValue();
short& smin = Shrp[n];
if (sval < smin)
smin = sval;
} // end of SetMin
/***********************************************************************/
/* Set one value in a block if val is greater than the current value. */
/***********************************************************************/
void SHRBLK::SetMax(PVAL valp, int n)
{
CheckParms(valp, n)
short sval = valp->GetShortValue();
short& smin = Shrp[n];
if (sval > smin)
smin = sval;
} // end of SetMax
/***********************************************************************/
/* Set many values in a block from values in another block. */
/***********************************************************************/
......@@ -806,15 +959,6 @@ void SHRBLK::SetValues(PVBLK pv, int k, int n)
Shrp[i] = sp[i];
} // end of SetValues
/***********************************************************************/
/* This function is used by class RESCOL when calculating COUNT. */
/***********************************************************************/
void SHRBLK::AddMinus1(PVBLK pv, int n1, int n2)
{
assert(Type == pv->GetType());
Shrp[n1] += (((SHRBLK*)pv)->Shrp[n2] - 1);
} // end of AddMinus1
#endif // 0
/***********************************************************************/
......@@ -854,7 +998,7 @@ int SHRBLK::CompVal(int i1, int i2)
/***********************************************************************/
void *SHRBLK::GetValPtr(int n)
{
CheckIndex(n)
ChkIndx(n);
return Shrp + n;
} // end of GetValPtr
......@@ -863,7 +1007,7 @@ void *SHRBLK::GetValPtr(int n)
/***********************************************************************/
void *SHRBLK::GetValPtrEx(int n)
{
CheckIndex(n)
ChkIndx(n);
return Shrp + n;
} // end of GetValPtrEx
......@@ -972,34 +1116,6 @@ void LNGBLK::SetValue(PVBLK pv, int n1, int n2)
} // end of SetValue
#if 0
/***********************************************************************/
/* Set one value in a block if val is less than the current value. */
/***********************************************************************/
void LNGBLK::SetMin(PVAL valp, int n)
{
CheckParms(valp, n)
int lval = valp->GetIntValue();
int& lmin = Lngp[n];
if (lval < lmin)
lmin = lval;
} // end of SetMin
/***********************************************************************/
/* Set one value in a block if val is greater than the current value. */
/***********************************************************************/
void LNGBLK::SetMax(PVAL valp, int n)
{
CheckParms(valp, n)
int lval = valp->GetIntValue();
int& lmax = Lngp[n];
if (lval > lmax)
lmax = lval;
} // end of SetMax
/***********************************************************************/
/* Set many values in a block from values in another block. */
/***********************************************************************/
......@@ -1012,15 +1128,6 @@ void LNGBLK::SetValues(PVBLK pv, int k, int n)
Lngp[i] = lp[i];
} // end of SetValues
/***********************************************************************/
/* This function is used by class RESCOL when calculating COUNT. */
/***********************************************************************/
void LNGBLK::AddMinus1(PVBLK pv, int n1, int n2)
{
assert(Type == pv->GetType());
Lngp[n1] += (((LNGBLK*)pv)->Lngp[n2] - 1);
} // end of AddMinus1
#endif // 0
/***********************************************************************/
......@@ -1060,7 +1167,7 @@ int LNGBLK::CompVal(int i1, int i2)
/***********************************************************************/
void *LNGBLK::GetValPtr(int n)
{
CheckIndex(n)
ChkIndx(n);
return Lngp + n;
} // end of GetValPtr
......@@ -1069,7 +1176,7 @@ void *LNGBLK::GetValPtr(int n)
/***********************************************************************/
void *LNGBLK::GetValPtrEx(int n)
{
CheckIndex(n)
ChkIndx(n);
return Lngp + n;
} // end of GetValPtrEx
......@@ -1105,14 +1212,14 @@ int LNGBLK::GetMaxLength(void)
return n;
} // end of GetMaxLength
#endif // 0
/* -------------------------- Class DATBLK --------------------------- */
/***********************************************************************/
/* Constructor. */
/***********************************************************************/
DATBLK::DATBLK(void *mp, int nval) : LNGBLK(mp, nval)
DATBLK::DATBLK(void *mp, int nval) : TYPBLK<int>(mp, nval, TYPE_INT)
{
Type = TYPE_DATE;
Dvalp = NULL;
......@@ -1137,13 +1244,13 @@ void DATBLK::SetValue(PSZ p, int n)
if (Dvalp) {
// Decode the string according to format
Dvalp->SetValue_psz(p);
Lngp[n] = Dvalp->GetIntValue();
Typp[n] = Dvalp->GetIntValue();
} else
LNGBLK::SetValue(p, n);
TYPBLK<int>::SetValue(p, n);
} // end of SetValue
#if 0
/* -------------------------- Class BIGBLK --------------------------- */
/***********************************************************************/
......@@ -1215,34 +1322,6 @@ void BIGBLK::SetValue(PVBLK pv, int n1, int n2)
} // end of SetValue
#if 0
/***********************************************************************/
/* Set one value in a block if val is less than the current value. */
/***********************************************************************/
void BIGBLK::SetMin(PVAL valp, int n)
{
CheckParms(valp, n)
longlong lval = valp->GetIntValue();
longlong& lmin = Lngp[n];
if (lval < lmin)
lmin = lval;
} // end of SetMin
/***********************************************************************/
/* Set one value in a block if val is greater than the current value. */
/***********************************************************************/
void BIGBLK::SetMax(PVAL valp, int n)
{
CheckParms(valp, n)
longlong lval = valp->GetIntValue();
longlong& lmax = Lngp[n];
if (lval > lmax)
lmax = lval;
} // end of SetMax
/***********************************************************************/
/* Set many values in a block from values in another block. */
/***********************************************************************/
......@@ -1255,15 +1334,6 @@ void BIGBLK::SetValues(PVBLK pv, int k, int n)
Lngp[i] = lp[i];
} // end of SetValues
/***********************************************************************/
/* This function is used by class RESCOL when calculating COUNT. */
/***********************************************************************/
void BIGBLK::AddMinus1(PVBLK pv, int n1, int n2)
{
assert(Type == pv->GetType());
Lngp[n1] += (((BIGBLK*)pv)->Lngp[n2] - 1);
} // end of AddMinus1
#endif // 0
/***********************************************************************/
......@@ -1303,7 +1373,7 @@ int BIGBLK::CompVal(int i1, int i2)
/***********************************************************************/
void *BIGBLK::GetValPtr(int n)
{
CheckIndex(n)
ChkIndx(n);
return Lngp + n;
} // end of GetValPtr
......@@ -1312,7 +1382,7 @@ void *BIGBLK::GetValPtr(int n)
/***********************************************************************/
void *BIGBLK::GetValPtrEx(int n)
{
CheckIndex(n)
ChkIndx(n);
return Lngp + n;
} // end of GetValPtrEx
......@@ -1434,34 +1504,6 @@ void DBLBLK::SetValues(PVBLK pv, int k, int n)
Dblp[i] = dp[i];
} // end of SetValues
/***********************************************************************/
/* Set one value in a block if val is less than the current value. */
/***********************************************************************/
void DBLBLK::SetMin(PVAL valp, int n)
{
CheckParms(valp, n)
double fval = valp->GetFloatValue();
double& fmin = Dblp[n];
if (fval < fmin)
fmin = fval;
} // end of SetMin
/***********************************************************************/
/* Set one value in a block if val is greater than the current value. */
/***********************************************************************/
void DBLBLK::SetMax(PVAL valp, int n)
{
CheckParms(valp, n)
double fval = valp->GetFloatValue();
double& fmax = Dblp[n];
if (fval > fmax)
fmax = fval;
} // end of SetMax
#endif // 0
/***********************************************************************/
......@@ -1501,7 +1543,7 @@ int DBLBLK::CompVal(int i1, int i2)
/***********************************************************************/
void *DBLBLK::GetValPtr(int n)
{
CheckIndex(n)
ChkIndx(n);
return Dblp + n;
} // end of GetValPtr
......@@ -1510,7 +1552,7 @@ void *DBLBLK::GetValPtr(int n)
/***********************************************************************/
void *DBLBLK::GetValPtrEx(int n)
{
CheckIndex(n)
ChkIndx(n);
return Dblp + n;
} // end of GetValPtrEx
......@@ -1546,6 +1588,7 @@ int DBLBLK::GetMaxLength(void)
return n;
} // end of GetMaxLength
#endif // 0
/* ------------------------- End of Valblk --------------------------- */
/*************** 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 */
/* */
......@@ -19,6 +19,7 @@
/* Utility used to allocate value blocks. */
/***********************************************************************/
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. */
......@@ -59,6 +60,7 @@ class VALBLK : public BLOCK {
virtual void SetValue(short sval, 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(double fval, int n) {assert(false);}
virtual void SetValue(PSZ sp, int n) {assert(false);}
virtual void SetValue(PVAL valp, int n) = 0;
virtual void SetValue(PVBLK pv, int n1, int n2) = 0;
......@@ -78,23 +80,73 @@ class VALBLK : public BLOCK {
bool Locate(PVAL vp, int& i);
protected:
#if defined(_DEBUG) || defined(DEBTRACE)
void ChkIndx(int n);
void ChkPrm(PVAL v, int n);
void ChkTyp(PVAL v);
void ChkTyp(PVBLK vb);
#endif // _DEBUG) || DEBTRACE
// Members
PGLOBAL Global; // Used for messages and allocation
char *To_Nulls; // Null values array
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 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
/***********************************************************************/
/* 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. */
/***********************************************************************/
......@@ -119,11 +171,7 @@ class CHRBLK : public VALBLK {
virtual void SetValue(PSZ sp, int n);
virtual void SetValue(PVAL valp, int n);
virtual void SetValue(PVBLK pv, int n1, int n2);
#if 0
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 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);
......@@ -168,11 +216,7 @@ class STRBLK : public VALBLK {
virtual void SetValue(PSZ sp, int n);
virtual void SetValue(PVAL valp, int n);
virtual void SetValue(PVBLK pv, int n1, int n2);
#if 0
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 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);
......@@ -186,8 +230,9 @@ class STRBLK : public VALBLK {
PSZ* const &Strp; // Pointer to PSZ buffer
}; // 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 {
public:
......@@ -214,12 +259,7 @@ class SHRBLK : public VALBLK {
{Shrp[n] = (short)lval; SetNull(n, false);}
virtual void SetValue(PVAL valp, int n);
virtual void SetValue(PVBLK pv, int n1, int n2);
#if 0
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 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);
......@@ -261,12 +301,7 @@ class LNGBLK : public VALBLK {
{Lngp[n] = (int)lval; SetNull(n, false);}
virtual void SetValue(PVAL valp, int n);
virtual void SetValue(PVBLK pv, int n1, int n2);
#if 0
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 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);
......@@ -279,11 +314,12 @@ class LNGBLK : public VALBLK {
// Members
int* const &Lngp;
}; // end of class LNGBLK
#endif // 0
/***********************************************************************/
/* Class DATBLK: represents a block of time stamp values. */
/***********************************************************************/
class DATBLK : public LNGBLK {
class DATBLK : public TYPBLK<int> {
public:
// Constructor
DATBLK(void *mp, int size);
......@@ -299,6 +335,7 @@ class DATBLK : public LNGBLK {
PVAL Dvalp; // Date value used to convert string
}; // end of class DATBLK
#if 0
/***********************************************************************/
/* Class BIGBLK: represents a block of big integer values. */
/***********************************************************************/
......@@ -327,12 +364,7 @@ class BIGBLK : public VALBLK {
{Lngp[n] = lval; SetNull(n, false);}
virtual void SetValue(PVAL valp, int n);
virtual void SetValue(PVBLK pv, int n1, int n2);
#if 0
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 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);
......@@ -369,11 +401,7 @@ class DBLBLK : public VALBLK {
virtual void SetValue(PSZ sp, int n);
virtual void SetValue(PVAL valp, int n);
virtual void SetValue(PVBLK pv, int n1, int n2);
#if 0
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 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);
......@@ -385,8 +413,8 @@ class DBLBLK : public VALBLK {
protected:
// Members
double* const &Dblp;
int Prec;
}; // end of class DBLBLK
#endif // 0
#endif // __VALBLK__H__
......@@ -262,6 +262,23 @@ bool IsTypeNum(int type)
return false;
} // 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 */
/* which should be converted a value so no precision would be lost. */
......@@ -430,7 +447,7 @@ PVAL AllocateValue(PGLOBAL g, PVAL valp, int newtype)
/***********************************************************************/
VALUE::VALUE(int type) : Type(type)
{
Fmt = GetFmt();
Fmt = GetFmt(Type);
Xfmt = GetXfmt();
Null = false;
Nullable = false;
......@@ -438,23 +455,6 @@ VALUE::VALUE(int type) : Type(type)
Prec = 0;
} // 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. */
/***********************************************************************/
......@@ -1278,9 +1278,9 @@ bool DTVAL::MakeDate(PGLOBAL g, int *val, int nval)
int n;
bool rc = false;
#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
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
if (trace)
......
......@@ -111,7 +111,6 @@ class DllExport VALUE : public BLOCK {
protected:
virtual bool SetConstFormat(PGLOBAL, FORMAT&) = 0;
const char *GetFmt(void);
const char *GetXfmt(void);
// 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