Commit bf6c3f51 authored by Olivier Bertrand's avatar Olivier Bertrand

- Second version of template value classes

  The first one did not compile with GCC on Linux

modified:
  storage/connect/value.cpp
  storage/connect/value.h
parent 812c1a7f
......@@ -319,7 +319,7 @@ PVAL AllocateValue(PGLOBAL g, void *value, short type)
switch (type) {
case TYPE_STRING:
valp = new(g) TYPVAL<PSZ>(NULL, (PSZ)value, 0, 0, TYPE_STRING);
valp = new(g) TYPVAL<PSZ>((PSZ)value);
break;
case TYPE_SHORT:
valp = new(g) TYPVAL<short>(*(short*)value, TYPE_SHORT);
......@@ -352,7 +352,7 @@ PVAL AllocateValue(PGLOBAL g, int type, int len, int prec,
switch (type) {
case TYPE_STRING:
valp = new(g) TYPVAL<PSZ>(g, (PSZ)NULL, len, prec, TYPE_STRING);
valp = new(g) TYPVAL<PSZ>(g, (PSZ)NULL, len, prec);
break;
case TYPE_DATE:
valp = new(g) DTVAL(g, len, prec, dom);
......@@ -396,8 +396,7 @@ PVAL AllocateValue(PGLOBAL g, PVAL valp, int newtype)
if ((sp = valp->GetCharString(p)) != p)
strcpy (p, sp);
valp = new(g) TYPVAL<PSZ>(g, p, valp->GetValLen(),
valp->GetValPrec(), TYPE_STRING);
valp = new(g) TYPVAL<PSZ>(g, p, valp->GetValLen(), valp->GetValPrec());
break;
case TYPE_SHORT:
valp = new(g) TYPVAL<short>(valp->GetShortValue(), TYPE_SHORT);
......@@ -435,9 +434,7 @@ VALUE::VALUE(int type) : Type(type)
Xfmt = GetXfmt();
Null = false;
Nullable = false;
Ci = false;
Clen = 0;
Len = 0;
Prec = 0;
} // end of VALUE constructor
......@@ -488,26 +485,6 @@ TYPVAL<TYPE>::TYPVAL(TYPE n, int type) : VALUE(type)
Prec = (Type == TYPE_FLOAT) ? 2 : 0;
} // end of TYPVAL constructor
/***********************************************************************/
/* STRING public constructor from char. */
/***********************************************************************/
template <class TYPE>
TYPVAL<TYPE>::TYPVAL(PGLOBAL g, PSZ s, int n, int c, int type)
: VALUE(type)
{
assert(Type == TYPE_STRING && (g || s));
Len = (g) ? n : strlen(s);
if (g && !s) {
Tval = (char *)PlugSubAlloc(g, NULL, Len + 1);
Tval[Len] = '\0';
} else
Tval = s;
Clen = Len;
Ci = (c != 0);
} // end of STRING constructor
/***********************************************************************/
/* TYPVAL public constructor from typed value. */
/***********************************************************************/
......@@ -531,8 +508,6 @@ int TYPVAL<TYPE>::GetValLen(void)
return sprintf(c, Fmt, Tval);
} // end of GetValLen
int TYPVAL<PSZ>::GetValLen(void) {return Len;};
int TYPVAL<double>::GetValLen(void)
{
char c[32];
......@@ -552,13 +527,25 @@ bool TYPVAL<TYPE>::SetValue_pval(PVAL valp, bool chktype)
if (!(Null = valp->IsNull() && Nullable))
// Tval = (TYPE)valp->GetBigintValue();
Tval = GetTypedValue(valp, (TYPE)0);
Tval = GetTypedValue(valp);
else
Reset();
return false;
} // end of SetValue
short TYPVAL<short>::GetTypedValue(PVAL valp)
{return valp->GetShortValue();}
int TYPVAL<int>::GetTypedValue(PVAL valp)
{return valp->GetIntValue();}
longlong TYPVAL<longlong>::GetTypedValue(PVAL valp)
{return valp->GetBigintValue();}
double TYPVAL<double>::GetTypedValue(PVAL valp)
{return valp->GetFloatValue();}
/***********************************************************************/
/* TYPVAL SetValue: convert chars extracted from a line to TYPE value.*/
/***********************************************************************/
......@@ -600,21 +587,6 @@ void TYPVAL<TYPE>::SetValue_char(char *p, int n)
Null = false;
} // end of SetValue
void TYPVAL<PSZ>::SetValue_char(char *p, int n)
{
n = min(n, Len);
strncpy(Tval, p, n);
for (p = Tval + n - 1; (*p == ' ' || *p == '\0') && p >= Tval; p--) ;
*(++p) = '\0';
if (trace)
htrc(" Setting string to: '%s'\n", Tval);
Null = false;
} // end of SetValue_char
void TYPVAL<double>::SetValue_char(char *p, int n)
{
char *p2, buf[32];
......@@ -638,104 +610,37 @@ void TYPVAL<double>::SetValue_char(char *p, int n)
template <class TYPE>
void TYPVAL<TYPE>::SetValue_psz(PSZ s)
{
Tval = GetTypedValue(s, (TYPE)0);
Tval = GetTypedValue(s);
Null = false;
} // end of SetValue
int TYPVAL<int>::GetTypedValue(PSZ s) {return atol(s);}
short TYPVAL<short>::GetTypedValue(PSZ s) {return (short)atoi(s);}
longlong TYPVAL<longlong>::GetTypedValue(PSZ s) {return atoll(s);}
double TYPVAL<double>::GetTypedValue(PSZ s) {return atof(s);}
/***********************************************************************/
/* TYPVAL SetValue: set value with a TYPE extracted from a block. */
/***********************************************************************/
template <class TYPE>
void TYPVAL<TYPE>::SetValue_pvblk(PVBLK blk, int n)
{
Tval = GetTypedValue(blk, n, (TYPE)0);
Null = false;
} // end of SetValue
/***********************************************************************/
/* Set Tval to a coerced object. */
/***********************************************************************/
template <class TYPE>
void TYPVAL<TYPE>::SetValue(short i) {Tval = (TYPE)i; Null = false;}
template <class TYPE>
void TYPVAL<TYPE>::SetValue(int n) {Tval = (TYPE)n; Null = false;}
template <class TYPE>
void TYPVAL<TYPE>::SetValue(longlong n) {Tval = (TYPE)n; Null = false;}
template <class TYPE>
void TYPVAL<TYPE>::SetValue(double f) {Tval = (TYPE)f; Null = false;}
/***********************************************************************/
/* STRING SetValue: get the character representation of an integer. */
/***********************************************************************/
void TYPVAL<PSZ>::SetValue(int n)
{
char buf[16];
PGLOBAL& g = Global;
int k = sprintf(buf, "%d", n);
if (k > Len) {
sprintf(g->Message, MSG(VALSTR_TOO_LONG), buf, Len);
longjmp(g->jumper[g->jump_level], 138);
} else
SetValue_psz(buf);
Null = false;
} // end of SetValue
/***********************************************************************/
/* STRING SetValue: get the character representation of a short int. */
/***********************************************************************/
void TYPVAL<PSZ>::SetValue(short i)
{
SetValue((int)i);
Tval = GetTypedValue(blk, n);
Null = false;
} // end of SetValue
/***********************************************************************/
/* STRING SetValue: get the character representation of a big integer.*/
/***********************************************************************/
void TYPVAL<PSZ>::SetValue(longlong n)
{
char buf[24];
PGLOBAL& g = Global;
int k = sprintf(buf, "%lld", n);
if (k > Len) {
sprintf(g->Message, MSG(VALSTR_TOO_LONG), buf, Len);
longjmp(g->jumper[g->jump_level], 138);
} else
SetValue_psz(buf);
Null = false;
} // end of SetValue
/***********************************************************************/
/* STRING SetValue: get the character representation of a double. */
/***********************************************************************/
void TYPVAL<PSZ>::SetValue(double f)
{
char *p, buf[32];
PGLOBAL& g = Global;
int k = sprintf(buf, "%lf", f);
int TYPVAL<int>::GetTypedValue(PVBLK blk, int n)
{return blk->GetIntValue(n);}
for (p = buf + k - 1; p >= buf; p--)
if (*p == '0') {
*p = 0;
k--;
} else
break;
short TYPVAL<short>::GetTypedValue(PVBLK blk, int n)
{return blk->GetShortValue(n);}
if (k > Len) {
sprintf(g->Message, MSG(VALSTR_TOO_LONG), buf, Len);
longjmp(g->jumper[g->jump_level], 138);
} else
SetValue_psz(buf);
longlong TYPVAL<longlong>::GetTypedValue(PVBLK blk, int n)
{return blk->GetBigintValue(n);}
Null = false;
} // end of SetValue
double TYPVAL<double>::GetTypedValue(PVBLK blk, int n)
{return blk->GetFloatValue(n);}
/***********************************************************************/
/* TYPVAL SetBinValue: with bytes extracted from a line. */
......@@ -747,12 +652,6 @@ void TYPVAL<TYPE>::SetBinValue(void *p)
Null = false;
} // end of SetBinValue
void TYPVAL<PSZ>::SetBinValue(void *p)
{
SetValue_char((char *)p, Len);
Null = false;
} // end of SetBinValue
/***********************************************************************/
/* GetBinValue: fill a buffer with the internal binary value. */
/* This function checks whether the buffer length is enough and */
......@@ -778,20 +677,6 @@ bool TYPVAL<TYPE>::GetBinValue(void *buf, int buflen, bool go)
return false;
} // end of GetBinValue
bool TYPVAL<PSZ>::GetBinValue(void *buf, int buflen, bool go)
{
int len = (Null) ? 0 : strlen(Tval);
if (len > buflen)
return true;
else if (go) {
memset(buf, ' ', buflen);
memcpy(buf, Tval, len);
} // endif go
return false;
} // end of GetBinValue
/***********************************************************************/
/* TYPVAL ShowValue: get string representation of a typed value. */
/***********************************************************************/
......@@ -802,11 +687,6 @@ char *TYPVAL<TYPE>::ShowValue(char *buf, int len)
return buf;
} // end of ShowValue
char *TYPVAL<PSZ>::ShowValue(char *buf, int len)
{
return Tval;
} // end of ShowValue
char *TYPVAL<double>::ShowValue(char *buf, int len)
{
// TODO: use snprintf to avoid possible overflow
......@@ -824,11 +704,6 @@ char *TYPVAL<TYPE>::GetCharString(char *p)
return p;
} // end of GetCharString
char *TYPVAL<PSZ>::GetCharString(char *p)
{
return Tval;
} // end of GetCharString
char *TYPVAL<double>::GetCharString(char *p)
{
sprintf(p, Fmt, Prec, Tval);
......@@ -845,12 +720,6 @@ char *TYPVAL<TYPE>::GetShortString(char *p, int n)
return p;
} // end of GetShortString
char *TYPVAL<PSZ>::GetShortString(char *p, int n)
{
sprintf(p, "%*hd", n, (short)(Null ? 0 : atoi(Tval)));
return p;
} // end of GetShortString
/***********************************************************************/
/* TYPVAL GetIntString: get int representation of a typed value. */
/***********************************************************************/
......@@ -861,12 +730,6 @@ char *TYPVAL<TYPE>::GetIntString(char *p, int n)
return p;
} // end of GetIntString
char *TYPVAL<PSZ>::GetIntString(char *p, int n)
{
sprintf(p, "%*ld", n, (Null) ? 0 : atol(Tval));
return p;
} // end of GetIntString
/***********************************************************************/
/* TYPVAL GetBigintString: get big int representation of a TYPE value.*/
/***********************************************************************/
......@@ -877,12 +740,6 @@ char *TYPVAL<TYPE>::GetBigintString(char *p, int n)
return p;
} // end of GetBigintString
char *TYPVAL<PSZ>::GetBigintString(char *p, int n)
{
sprintf(p, "%*lld", n, (Null) ? 0 : atoll(Tval));
return p;
} // end of GetBigintString
/***********************************************************************/
/* TYPVAL GetFloatString: get double representation of a typed value. */
/***********************************************************************/
......@@ -893,12 +750,6 @@ char *TYPVAL<TYPE>::GetFloatString(char *p, int n, int prec)
return p;
} // end of GetFloatString
char *TYPVAL<PSZ>::GetFloatString(char *p, int n, int prec)
{
sprintf(p, "%*.*lf", n, (prec < 0) ? 2 : prec, Null ? 0 : atof(Tval));
return p;
} // end of GetFloatString
/***********************************************************************/
/* TYPVAL compare value with another Value. */
/***********************************************************************/
......@@ -912,7 +763,7 @@ bool TYPVAL<TYPE>::IsEqual(PVAL vp, bool chktype)
else if (Null || vp->IsNull())
return false;
else
return (Tval == GetTypedValue(vp, (TYPE)0));
return (Tval == GetTypedValue(vp));
} // end of IsEqual
......@@ -944,14 +795,6 @@ bool TYPVAL<TYPE>::SetConstFormat(PGLOBAL g, FORMAT& fmt)
return false;
} // end of SetConstFormat
bool TYPVAL<PSZ>::SetConstFormat(PGLOBAL g, FORMAT& fmt)
{
fmt.Type[0] = 'C';
fmt.Length = Len;
fmt.Prec = 0;
return false;
} // end of SetConstFormat
/***********************************************************************/
/* Make file output of a typed object. */
/***********************************************************************/
......@@ -983,6 +826,284 @@ void TYPVAL<TYPE>::Print(PGLOBAL g, char *ps, uint z)
} /* end of Print */
/* -------------------------- Class STRING --------------------------- */
/***********************************************************************/
/* STRING public constructor from a constant string. */
/***********************************************************************/
TYPVAL<PSZ>::TYPVAL(PSZ s) : VALUE(TYPE_STRING)
{
Strp = s;
Len = strlen(s);
Clen = Len;
Ci = false;
} // end of STRING constructor
/***********************************************************************/
/* STRING public constructor from char. */
/***********************************************************************/
TYPVAL<PSZ>::TYPVAL(PGLOBAL g, PSZ s, int n, int c)
: VALUE(TYPE_STRING)
{
assert(Type == TYPE_STRING && (g || s));
Len = (g) ? n : strlen(s);
if (g && !s) {
Strp = (char *)PlugSubAlloc(g, NULL, Len + 1);
Strp[Len] = '\0';
} else
Strp = s;
Clen = Len;
Ci = (c != 0);
} // end of STRING constructor
/***********************************************************************/
/* STRING SetValue: copy the value of another Value object. */
/***********************************************************************/
bool TYPVAL<PSZ>::SetValue_pval(PVAL valp, bool chktype)
{
if (chktype && (valp->GetType() != Type || valp->GetSize() > Len))
return true;
char buf[32];
if (!(Null = valp->IsNull() && Nullable))
strncpy(Strp, valp->GetCharString(buf), Len);
else
Reset();
return false;
} // end of SetValue_pval
/***********************************************************************/
/* STRING SetValue: fill string with chars extracted from a line. */
/***********************************************************************/
void TYPVAL<PSZ>::SetValue_char(char *p, int n)
{
n = min(n, Len);
strncpy(Strp, p, n);
for (p = Strp + n - 1; (*p == ' ' || *p == '\0') && p >= Strp; p--) ;
*(++p) = '\0';
if (trace)
htrc(" Setting string to: '%s'\n", Strp);
Null = false;
} // end of SetValue_char
/***********************************************************************/
/* STRING SetValue: fill string with another string. */
/***********************************************************************/
void TYPVAL<PSZ>::SetValue_psz(PSZ s)
{
strncpy(Strp, s, Len);
Null = false;
} // end of SetValue_psz
/***********************************************************************/
/* STRING SetValue: fill string with a string extracted from a block. */
/***********************************************************************/
void TYPVAL<PSZ>::SetValue_pvblk(PVBLK blk, int n)
{
strncpy(Strp, blk->GetCharValue(n), Len);
} // end of SetValue_pvblk
/***********************************************************************/
/* STRING SetValue: get the character representation of an integer. */
/***********************************************************************/
void TYPVAL<PSZ>::SetValue(int n)
{
char buf[16];
PGLOBAL& g = Global;
int k = sprintf(buf, "%d", n);
if (k > Len) {
sprintf(g->Message, MSG(VALSTR_TOO_LONG), buf, Len);
longjmp(g->jumper[g->jump_level], 138);
} else
SetValue_psz(buf);
Null = false;
} // end of SetValue
/***********************************************************************/
/* STRING SetValue: get the character representation of a short int. */
/***********************************************************************/
void TYPVAL<PSZ>::SetValue(short i)
{
SetValue((int)i);
Null = false;
} // end of SetValue
/***********************************************************************/
/* STRING SetValue: get the character representation of a big integer.*/
/***********************************************************************/
void TYPVAL<PSZ>::SetValue(longlong n)
{
char buf[24];
PGLOBAL& g = Global;
int k = sprintf(buf, "%lld", n);
if (k > Len) {
sprintf(g->Message, MSG(VALSTR_TOO_LONG), buf, Len);
longjmp(g->jumper[g->jump_level], 138);
} else
SetValue_psz(buf);
Null = false;
} // end of SetValue
/***********************************************************************/
/* STRING SetValue: get the character representation of a double. */
/***********************************************************************/
void TYPVAL<PSZ>::SetValue(double f)
{
char *p, buf[32];
PGLOBAL& g = Global;
int k = sprintf(buf, "%lf", f);
for (p = buf + k - 1; p >= buf; p--)
if (*p == '0') {
*p = 0;
k--;
} else
break;
if (k > Len) {
sprintf(g->Message, MSG(VALSTR_TOO_LONG), buf, Len);
longjmp(g->jumper[g->jump_level], 138);
} else
SetValue_psz(buf);
Null = false;
} // end of SetValue
/***********************************************************************/
/* STRING SetBinValue: fill string with chars extracted from a line. */
/***********************************************************************/
void TYPVAL<PSZ>::SetBinValue(void *p)
{
SetValue_char((char *)p, Len);
Null = false;
} // end of SetBinValue
/***********************************************************************/
/* GetBinValue: fill a buffer with the internal binary value. */
/* This function checks whether the buffer length is enough and */
/* returns true if not. Actual filling occurs only if go is true. */
/* Currently used by WriteColumn of binary files. */
/***********************************************************************/
bool TYPVAL<PSZ>::GetBinValue(void *buf, int buflen, bool go)
{
int len = (Null) ? 0 : strlen(Strp);
if (len > buflen)
return true;
else if (go) {
memset(buf, ' ', buflen);
memcpy(buf, Strp, len);
} // endif go
return false;
} // end of GetBinValue
/***********************************************************************/
/* STRING ShowValue: get string representation of a char value. */
/***********************************************************************/
char *TYPVAL<PSZ>::ShowValue(char *buf, int len)
{
return Strp;
} // end of ShowValue
/***********************************************************************/
/* STRING GetCharString: get string representation of a char value. */
/***********************************************************************/
char *TYPVAL<PSZ>::GetCharString(char *p)
{
return Strp;
} // end of GetCharString
/***********************************************************************/
/* STRING GetShortString: get short representation of a char value. */
/***********************************************************************/
char *TYPVAL<PSZ>::GetShortString(char *p, int n)
{
sprintf(p, "%*hd", n, (short)(Null ? 0 : atoi(Strp)));
return p;
} // end of GetShortString
/***********************************************************************/
/* STRING GetIntString: get int representation of a char value. */
/***********************************************************************/
char *TYPVAL<PSZ>::GetIntString(char *p, int n)
{
sprintf(p, "%*ld", n, (Null) ? 0 : atol(Strp));
return p;
} // end of GetIntString
/***********************************************************************/
/* STRING GetBigintString: get big int representation of a char value.*/
/***********************************************************************/
char *TYPVAL<PSZ>::GetBigintString(char *p, int n)
{
sprintf(p, "%*lld", n, (Null) ? 0 : atoll(Strp));
return p;
} // end of GetBigintString
/***********************************************************************/
/* STRING GetFloatString: get double representation of a char value. */
/***********************************************************************/
char *TYPVAL<PSZ>::GetFloatString(char *p, int n, int prec)
{
sprintf(p, "%*.*lf", n, (prec < 0) ? 2 : prec, Null ? 0 : atof(Strp));
return p;
} // end of GetFloatString
/***********************************************************************/
/* STRING compare value with another Value. */
/***********************************************************************/
bool TYPVAL<PSZ>::IsEqual(PVAL vp, bool chktype)
{
if (this == vp)
return true;
else if (chktype && Type != vp->GetType())
return false;
else if (Null || vp->IsNull())
return false;
else if (Ci || vp->IsCi())
return !stricmp(Strp, vp->GetCharValue());
else // (!Ci)
return !strcmp(Strp, vp->GetCharValue());
} // end of IsEqual
/***********************************************************************/
/* FormatValue: This function set vp (a STRING value) to the string */
/* constructed from its own value formated using the fmt format. */
/* This function assumes that the format matches the value type. */
/***********************************************************************/
bool TYPVAL<PSZ>::FormatValue(PVAL vp, char *fmt)
{
char *buf = (char*)vp->GetTo_Val(); // Should be big enough
int n = sprintf(buf, fmt, Strp);
return (n > vp->GetValLen());
} // end of FormatValue
/***********************************************************************/
/* STRING SetFormat function (used to set SELECT output format). */
/***********************************************************************/
bool TYPVAL<PSZ>::SetConstFormat(PGLOBAL g, FORMAT& fmt)
{
fmt.Type[0] = 'C';
fmt.Length = Len;
fmt.Prec = 0;
return false;
} // end of SetConstFormat
/* -------------------------- Class DTVAL ---------------------------- */
/***********************************************************************/
......
......@@ -123,10 +123,8 @@ class DllExport VALUE : public BLOCK {
const char *Xfmt;
bool Nullable; // True if value can be null
bool Null; // True if value is null
bool Ci; // true if case insensitive
int Type; // The value type
int Clen; // Internal value length
int Len;
int Prec;
}; // end of class VALUE
......@@ -139,7 +137,6 @@ class DllExport TYPVAL : public VALUE {
// Constructors
TYPVAL(TYPE n, int type);
TYPVAL(TYPE n, int prec, int type);
TYPVAL(PGLOBAL g, PSZ s, int n, int c, int type);
// Implementation
virtual bool IsTypeNum(void) {return true;}
......@@ -159,10 +156,10 @@ class DllExport TYPVAL : public VALUE {
virtual bool SetValue_pval(PVAL valp, bool chktype);
virtual void SetValue_char(char *p, int n);
virtual void SetValue_psz(PSZ s);
virtual void SetValue(short i);
virtual void SetValue(int n);
virtual void SetValue(longlong n);
virtual void SetValue(double f);
virtual void SetValue(short i) {Tval = (TYPE)i; Null = false;}
virtual void SetValue(int n) {Tval = (TYPE)n; Null = false;}
virtual void SetValue(longlong n) {Tval = (TYPE)n; Null = false;}
virtual void SetValue(double f) {Tval = (TYPE)f; Null = false;}
virtual void SetValue_pvblk(PVBLK blk, int n);
virtual void SetBinValue(void *p);
virtual bool GetBinValue(void *buf, int buflen, bool go);
......@@ -183,51 +180,72 @@ class DllExport TYPVAL : public VALUE {
TYPVAL(void) : VALUE(TYPE_ERROR) {}
// Specialized functions
template <class T>
T GetTypedValue(PVAL vp, T t) {return vp->GetIntValue();}
PSZ GetTypedValue(PVAL vp, PSZ t)
{char buf[32]; return strncpy(Tval, vp->GetCharString(buf), Len);}
short GetTypedValue(PVAL vp, short t) {return vp->GetShortValue();}
longlong GetTypedValue(PVAL vp, longlong t) {return vp->GetBigintValue();}
double GetTypedValue(PVAL vp, double t) {return vp->GetFloatValue();}
template <class T>
T GetTypedValue(PVBLK blk, int n, T t)
{return blk->GetIntValue(n);}
PSZ GetTypedValue(PVBLK blk, int n, PSZ t)
{return strncpy(Tval, blk->GetCharValue(n), Len);}
short GetTypedValue(PVBLK blk, int n, short t)
{return blk->GetShortValue(n);}
longlong GetTypedValue(PVBLK blk, int n, longlong t)
{return blk->GetBigintValue(n);}
double GetTypedValue(PVBLK blk, int n, double t)
{return blk->GetFloatValue(n);}
template <class T>
T GetTypedValue(PSZ s, T n) {return atol(s);}
PSZ GetTypedValue(PSZ s, PSZ n) {return strncpy(Tval, s, Len);}
short GetTypedValue(PSZ s, short n) {return atoi(s);}
longlong GetTypedValue(PSZ s, longlong n) {return atoll(s);}
double GetTypedValue(PSZ s, double n) {return atof(s);}
TYPE GetTypedValue(PVAL vp);
TYPE GetTypedValue(PVBLK blk, int n);
TYPE GetTypedValue(PSZ s);
// Members
TYPE Tval;
}; // end of class TYPVAL
/***********************************************************************/
/* Specific STRING functions. */
/* Specific STRING class. */
/***********************************************************************/
bool TYPVAL<PSZ>::IsTypeNum(void) {return false;}
bool TYPVAL<PSZ>::IsZero(void) {return *Tval == 0;}
void TYPVAL<PSZ>::Reset(void) {*Tval = 0;}
int TYPVAL<PSZ>::GetValPrec() {return (Ci) ? 1 : 0;}
int TYPVAL<PSZ>::GetSize(void) {return (Tval) ? strlen(Tval) : 0;}
PSZ TYPVAL<PSZ>::GetCharValue(void) {return Tval;}
short TYPVAL<PSZ>::GetShortValue(void) {return (short)atoi(Tval);}
int TYPVAL<PSZ>::GetIntValue(void) {return atol(Tval);}
longlong TYPVAL<PSZ>::GetBigintValue(void) {return atoll(Tval);}
double TYPVAL<PSZ>::GetFloatValue(void) {return atof(Tval);}
void *TYPVAL<PSZ>::GetTo_Val(void) {return Tval;}
template <>
class DllExport TYPVAL<PSZ>: public VALUE {
public:
// Constructors
TYPVAL(PSZ s);
TYPVAL(PGLOBAL g, PSZ s, int n, int c);
// Implementation
virtual bool IsTypeNum(void) {return false;}
virtual bool IsZero(void) {return *Strp == 0;}
virtual void Reset(void) {*Strp = 0;}
virtual int GetValLen(void) {return Len;};
virtual int GetValPrec() {return (Ci) ? 1 : 0;}
virtual int GetSize(void) {return (Strp) ? strlen(Strp) : 0;}
virtual PSZ GetCharValue(void) {return Strp;}
virtual short GetShortValue(void) {return (short)atoi(Strp);}
virtual int GetIntValue(void) {return atol(Strp);}
virtual longlong GetBigintValue(void) {return atoll(Strp);}
virtual double GetFloatValue(void) {return atof(Strp);}
virtual void *GetTo_Val(void) {return Strp;}
// Methods
virtual bool SetValue_pval(PVAL valp, bool chktype);
virtual void SetValue_char(char *p, int n);
virtual void SetValue_psz(PSZ s);
virtual void SetValue_pvblk(PVBLK blk, int n);
virtual void SetValue(short i);
virtual void SetValue(int n);
virtual void SetValue(longlong n);
virtual void SetValue(double f);
virtual void SetBinValue(void *p);
virtual bool GetBinValue(void *buf, int buflen, bool go);
virtual char *ShowValue(char *buf, int);
virtual char *GetCharString(char *p);
virtual char *GetShortString(char *p, int n);
virtual char *GetIntString(char *p, int n);
virtual char *GetBigintString(char *p, int n);
virtual char *GetFloatString(char *p, int n, int prec = -1);
virtual bool IsEqual(PVAL vp, bool chktype);
virtual bool FormatValue(PVAL vp, char *fmt);
virtual bool SetConstFormat(PGLOBAL, FORMAT&);
// Specialized functions
template <class T>
T GetValue_as(T type) {return Strp;}
int GetValue_as(int type) {return atol(Strp);}
short GetValue_as(short type) {return (short)atoi(Strp);}
longlong GetValue_as(longlong type) {return atoll(Strp);}
double GetValue_as(double type) {return atof(Strp);}
// Members
PSZ Strp;
bool Ci; // true if case insensitive
int Len;
}; // end of class TYPVAL<PSZ>
/***********************************************************************/
/* Class DTVAL: represents a time stamp value. */
......@@ -274,6 +292,7 @@ class DllExport DTVAL : public TYPVAL<int> {
PDTP Pdtp; // To the DATPAR structure
char *Sdate; // Utility char buffer
int DefYear; // Used by ExtractDate
int Len; // Used by CHAR scalar function
}; // end of class DTVAL
#endif // __VALUE__H__
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