StandardTypeDescriptor.h

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/tuple/StandardTypeDescriptor.h#18 $
00003 // Fennel is a library of data storage and processing components.
00004 // Copyright (C) 2005-2009 The Eigenbase Project
00005 // Copyright (C) 2003-2009 SQLstream, Inc.
00006 // Copyright (C) 2005-2009 LucidEra, Inc.
00007 // Portions Copyright (C) 1999-2009 John V. Sichi
00008 //
00009 // This program is free software; you can redistribute it and/or modify it
00010 // under the terms of the GNU General Public License as published by the Free
00011 // Software Foundation; either version 2 of the License, or (at your option)
00012 // any later version approved by The Eigenbase Project.
00013 //
00014 // This program is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with this program; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 */
00023 
00024 #ifndef Fennel_StandardTypeDescriptor_Included
00025 #define Fennel_StandardTypeDescriptor_Included
00026 
00027 #include "fennel/tuple/StoredTypeDescriptor.h"
00028 #include "fennel/tuple/StoredTypeDescriptorFactory.h"
00029 
00030 FENNEL_BEGIN_NAMESPACE
00031 
00043 enum StandardTypeDescriptorOrdinal
00044 {
00045     STANDARD_TYPE_MIN = 1,
00046     STANDARD_TYPE_INT_8 = 1,
00047     STANDARD_TYPE_UINT_8 = 2,
00048     STANDARD_TYPE_INT_16 = 3,
00049     STANDARD_TYPE_UINT_16 = 4,
00050     STANDARD_TYPE_INT_32 = 5,
00051     STANDARD_TYPE_UINT_32 = 6,
00052     STANDARD_TYPE_INT_64 = 7,
00053     STANDARD_TYPE_UINT_64 = 8,
00054     STANDARD_TYPE_BOOL = 9,
00055     STANDARD_TYPE_REAL = 10,
00056     STANDARD_TYPE_DOUBLE = 11,
00057     STANDARD_TYPE_CHAR = 12,
00058     STANDARD_TYPE_VARCHAR = 13,
00059     STANDARD_TYPE_BINARY = 14,
00060     STANDARD_TYPE_VARBINARY = 15,
00061     STANDARD_TYPE_END_NO_UNICODE = 16,
00062     STANDARD_TYPE_UNICODE_CHAR = 16,
00063     STANDARD_TYPE_UNICODE_VARCHAR = 17,
00064     STANDARD_TYPE_END,
00065 
00069     STANDARD_TYPE_RECORDNUM = STANDARD_TYPE_INT_64,
00070 
00071     EXTENSION_TYPE_MIN = 1000,
00072 };
00073 
00078 class FENNEL_TUPLE_EXPORT StandardTypeDescriptor
00079 {
00080 public:
00081     static inline char const * const
00082     toString(StandardTypeDescriptorOrdinal st)
00083     {
00084         switch (st) {
00085         case STANDARD_TYPE_INT_8:
00086             return "s1";             // signed, 1 byte
00087         case STANDARD_TYPE_UINT_8:
00088             return "u1";             // unsigned, 1 byte
00089         case STANDARD_TYPE_INT_16:
00090             return "s2";
00091         case STANDARD_TYPE_UINT_16:
00092             return "u2";
00093         case STANDARD_TYPE_INT_32:
00094             return "s4";
00095         case STANDARD_TYPE_UINT_32:
00096             return "u4";
00097         case STANDARD_TYPE_INT_64:
00098             return "s8";
00099         case STANDARD_TYPE_UINT_64:
00100             return "u8";
00101         case STANDARD_TYPE_BOOL:
00102             return "bo";
00103         case STANDARD_TYPE_REAL:     // float
00104             return "r";
00105         case STANDARD_TYPE_DOUBLE:
00106             return "d";
00107         case STANDARD_TYPE_CHAR:
00108             return "c";
00109         case STANDARD_TYPE_VARCHAR:
00110             return "vc";
00111         case STANDARD_TYPE_BINARY:
00112             return "b";
00113         case STANDARD_TYPE_VARBINARY:
00114             return "vb";
00115         case STANDARD_TYPE_UNICODE_CHAR:
00116             return "U";
00117         case STANDARD_TYPE_UNICODE_VARCHAR:
00118             return "vU";
00119         default:
00120             permAssert(false);
00121         }
00122     }
00123 
00124     static inline StandardTypeDescriptorOrdinal
00125     fromString(char const * const str)
00126     {
00127         // A bit ugly, but rather fast.
00128         switch (*str) {
00129         case 's':
00130             switch (*(str + 1)) {
00131             case '1':
00132                 return STANDARD_TYPE_INT_8;
00133             case '2':
00134                 return STANDARD_TYPE_INT_16;
00135             case '4':
00136                 return STANDARD_TYPE_INT_32;
00137             case '8':
00138                 return STANDARD_TYPE_INT_64;
00139             default:
00140                 break;
00141             }
00142             break;
00143         case 'u':
00144             switch (*(str + 1)) {
00145             case '1':
00146                 return STANDARD_TYPE_UINT_8;
00147             case '2':
00148                 return STANDARD_TYPE_UINT_16;
00149             case '4':
00150                 return STANDARD_TYPE_UINT_32;
00151             case '8':
00152                 return STANDARD_TYPE_UINT_64;
00153             default:
00154                 break;
00155             }
00156             break;
00157         case 'r':
00158             return STANDARD_TYPE_REAL;
00159         case 'd':
00160             return STANDARD_TYPE_DOUBLE;
00161         case 'c':
00162             return STANDARD_TYPE_CHAR;
00163         case 'U':
00164             return STANDARD_TYPE_UNICODE_CHAR;
00165         case 'v':
00166             switch (*(str + 1)) {
00167             case 'c':
00168                 return STANDARD_TYPE_VARCHAR;
00169             case 'b':
00170                 return STANDARD_TYPE_VARBINARY;
00171             case 'U':
00172                 return STANDARD_TYPE_UNICODE_VARCHAR;
00173             default:
00174                 break;
00175             }
00176         case 'b':
00177             switch (*(str + 1)) {
00178             case 'o':
00179                 return STANDARD_TYPE_BOOL;
00180             case 0:         // string null terminator
00181                 return STANDARD_TYPE_BINARY;
00182             default:
00183                 break;
00184             }
00185         }
00186 
00187         permAssert(false);
00188     }
00189 
00190     static inline bool
00191     isNative(StandardTypeDescriptorOrdinal st)
00192     {
00193         if (st <= STANDARD_TYPE_DOUBLE) {
00194             return true;
00195         }
00196         return false;
00197     }
00198 
00199     // Useful for instructions like +, -, etc.
00200     static inline bool
00201     isNativeNotBool(StandardTypeDescriptorOrdinal st)
00202     {
00203         if (st <= STANDARD_TYPE_DOUBLE && st != STANDARD_TYPE_BOOL) {
00204             return true;
00205         }
00206         return false;
00207     }
00208 
00213     static inline bool
00214     isIntegralNative(StandardTypeDescriptorOrdinal st)
00215     {
00216         if (st <= STANDARD_TYPE_BOOL) {
00217             return true;
00218         }
00219         return false;
00220     }
00221 
00226     static inline bool
00227     isExact(StandardTypeDescriptorOrdinal st)
00228     {
00229         if (st <= STANDARD_TYPE_UINT_64) {
00230             return true;
00231         }
00232         return false;
00233     }
00234 
00235 
00236     static inline bool
00237     isApprox(StandardTypeDescriptorOrdinal st)
00238     {
00239         if (st == STANDARD_TYPE_REAL ||
00240             st == STANDARD_TYPE_DOUBLE) {
00241             return true;
00242         }
00243         return false;
00244     }
00245 
00246     static inline bool
00247     isArray(StandardTypeDescriptorOrdinal st)
00248     {
00249         if (st >= STANDARD_TYPE_CHAR &&
00250             st <= STANDARD_TYPE_UNICODE_VARCHAR) {
00251             return true;
00252         }
00253         return false;
00254     }
00255 
00256     static inline bool
00257     isVariableLenArray(StandardTypeDescriptorOrdinal st)
00258     {
00259         if (st == STANDARD_TYPE_VARCHAR ||
00260             st == STANDARD_TYPE_VARBINARY ||
00261             st == STANDARD_TYPE_UNICODE_VARCHAR) {
00262             return true;
00263         }
00264         return false;
00265     }
00266 
00267     static inline bool
00268     isFixedLenArray(StandardTypeDescriptorOrdinal st)
00269     {
00270         if (st == STANDARD_TYPE_CHAR ||
00271             st == STANDARD_TYPE_BINARY ||
00272             st == STANDARD_TYPE_UNICODE_CHAR) {
00273             return true;
00274         }
00275         return false;
00276     }
00277 
00278     static inline bool
00279     isTextArray(StandardTypeDescriptorOrdinal st)
00280     {
00281         if (st == STANDARD_TYPE_CHAR ||
00282             st == STANDARD_TYPE_VARCHAR ||
00283             st == STANDARD_TYPE_UNICODE_CHAR ||
00284             st == STANDARD_TYPE_UNICODE_VARCHAR) {
00285             return true;
00286         }
00287         return false;
00288     }
00289 
00290     static inline bool
00291     isBinaryArray(StandardTypeDescriptorOrdinal st)
00292     {
00293         if (st == STANDARD_TYPE_VARBINARY ||
00294             st == STANDARD_TYPE_BINARY) {
00295             return true;
00296         }
00297         return false;
00298     }
00299 
00300 private:
00301     explicit
00302     StandardTypeDescriptor();
00303 };
00304 
00305 
00311 class FENNEL_TUPLE_EXPORT StandardTypeDescriptorFactory
00312     : public StoredTypeDescriptorFactory
00313 {
00314 public:
00315     explicit StandardTypeDescriptorFactory();
00316     virtual StoredTypeDescriptor const &newDataType(
00317         StoredTypeDescriptor::Ordinal iTypeOrdinal) const;
00318 };
00319 
00320 FENNEL_END_NAMESPACE
00321 
00322 #endif
00323 
00324 // End StandardTypeDescriptor.h

Generated on Mon Jun 22 04:00:21 2009 for Fennel by  doxygen 1.5.1