BinaryDatum.h

Go to the documentation of this file.
00001 
00002 
00003 
00004 // @@TODO: * Proper C++ casting of returned values (with referencing??)
00005 //         * Use function templates for extractFrom or template classes?
00006 //-----------------------------------------------------------------------------
00007 // CVS: $Revision: 2989 $, $Date: 2006-10-12 17:31:45 +0100 (Thu, 12 Oct 2006) $, $Author: rsc $
00008 //-----------------------------------------------------------------------------
00009 #ifndef BINARYDATUM_DEFINED
00010 #define BINARYDATUM_DEFINED
00011 //-----------------------------------------------------------------------------
00013 class BinaryDatum
00014 {
00015 public:
00019   BinaryDatum(unsigned aBufIndex = 0)
00020     : mBufIndex(aBufIndex) { }
00021 
00023   virtual ~BinaryDatum() { }
00024 
00029   virtual double extractDoubleFrom(char* aBufferAry) const = 0;
00030 
00035   virtual unsigned long long extractBigIntFrom(char* aBufferAry) const = 0;
00036 
00038   virtual unsigned getNumBits() const = 0;
00039 
00040 protected:
00042   unsigned mBufIndex;
00043 };
00044 //-----------------------------------------------------------------------------
00046 class SqlFloat : public BinaryDatum
00047 {
00048 public:
00052   SqlFloat(unsigned aBufIndex = 0) : BinaryDatum(aBufIndex) { }
00053 
00055   virtual ~SqlFloat() { }
00056 
00061   virtual double extractDoubleFrom(char* aBufferAry) const
00062   {
00063     return *((double*) (&aBufferAry[mBufIndex]));
00064   }
00065 
00070   virtual unsigned long long extractBigIntFrom(char* aBufferAry) const
00071   {
00072     return static_cast<unsigned long long>(*((double*)
00073                                              (&aBufferAry[mBufIndex])));
00074   }
00075 
00077   virtual unsigned getNumBits() const { return 8; }
00078 
00079 };
00080 //-----------------------------------------------------------------------------
00082 class SqlReal : public BinaryDatum
00083 {
00084 public:
00088   SqlReal(unsigned aBufIndex = 0) : BinaryDatum(aBufIndex) { }
00089 
00091   virtual ~SqlReal() { }
00092 
00097   virtual double extractDoubleFrom(char* aBufferAry) const
00098   {
00099     return *((float*) (&aBufferAry[mBufIndex]));
00100   }
00101 
00106   virtual unsigned long long extractBigIntFrom(char* aBufferAry) const
00107   {
00108     return static_cast<unsigned long long>(*((float*)
00109                                              (&aBufferAry[mBufIndex])));
00110   }
00111 
00113   virtual unsigned getNumBits() const { return 4; }
00114 
00115 };
00116 //-----------------------------------------------------------------------------
00118 class SqlBigInt : public BinaryDatum
00119 {
00120 public:
00124   SqlBigInt(unsigned aBufIndex = 0) : BinaryDatum(aBufIndex) { }
00125 
00127   virtual ~SqlBigInt() { }
00128 
00133   virtual double extractDoubleFrom(char* aBufferAry) const
00134   {
00135     return *((unsigned long long*) (&aBufferAry[mBufIndex]));
00136   }
00137 
00142   virtual unsigned long long extractBigIntFrom(char* aBufferAry) const
00143   {
00144     return *((unsigned long long*) (&aBufferAry[mBufIndex]));
00145   }
00146 
00148   virtual unsigned getNumBits() const { return 8; }
00149 
00150 };
00151 //-----------------------------------------------------------------------------
00153 class SqlInt : public BinaryDatum
00154 {
00155 public:
00159   SqlInt(unsigned aBufIndex = 0) : BinaryDatum(aBufIndex) { }
00160 
00162   virtual ~SqlInt() { }
00163 
00168   virtual double extractDoubleFrom(char* aBufferAry) const
00169   {
00170     return *((int*) (&aBufferAry[mBufIndex]));
00171   }
00172 
00177   virtual unsigned long long extractBigIntFrom(char* aBufferAry) const
00178   {
00179     return *((int*) (&aBufferAry[mBufIndex]));
00180   }
00181 
00183   virtual unsigned getNumBits() const { return 4; }
00184 
00185 };
00186 //-----------------------------------------------------------------------------
00188 class SqlSmallInt : public BinaryDatum
00189 {
00190 public:
00194   SqlSmallInt(unsigned aBufIndex = 0) : BinaryDatum(aBufIndex) { }
00195 
00197   virtual ~SqlSmallInt() { }
00198 
00203   virtual double extractDoubleFrom(char* aBufferAry) const
00204   {
00205     return *((short*) (&aBufferAry[mBufIndex]));
00206   }
00207 
00212   virtual unsigned long long extractBigIntFrom(char* aBufferAry) const
00213   {
00214     return *((short*) (&aBufferAry[mBufIndex]));
00215   }
00216 
00218   virtual unsigned getNumBits() const { return 2; }
00219 
00220 };
00221 //-----------------------------------------------------------------------------
00223 class SqlTinyInt : public BinaryDatum
00224 {
00225 public:
00229   SqlTinyInt(unsigned aBufIndex = 0) : BinaryDatum(aBufIndex) { }
00230 
00232   virtual ~SqlTinyInt() { }
00233 
00238   virtual double extractDoubleFrom(char* aBufferAry) const
00239   {
00240     return *((char*) (&aBufferAry[mBufIndex]));
00241   }
00242 
00247   virtual unsigned long long extractBigIntFrom(char* aBufferAry) const
00248   {
00249     return *((char*) (&aBufferAry[mBufIndex]));
00250   }
00251 
00253   virtual unsigned getNumBits() const { return 1; }
00254 
00255 };
00256 //-----------------------------------------------------------------------------
00257 #endif
Generated on Mon Oct 4 10:39:55 2010 for Matching.kdevelop by  doxygen 1.6.3