00001 /* 00002 // $Id: //open/dev/fennel/calculator/NativeInstruction.h#2 $ 00003 // Fennel is a library of data storage and processing components. 00004 // Copyright (C) 2005-2009 The Eigenbase Project 00005 // Copyright (C) 2004-2009 SQLstream, Inc. 00006 // Copyright (C) 2009-2009 LucidEra, Inc. 00007 // 00008 // This program is free software; you can redistribute it and/or modify it 00009 // under the terms of the GNU General Public License as published by the Free 00010 // Software Foundation; either version 2 of the License, or (at your option) 00011 // any later version approved by The Eigenbase Project. 00012 // 00013 // This program is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 // GNU General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU General Public License 00019 // along with this program; if not, write to the Free Software 00020 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 // 00022 // NativeInstruction 00023 // 00024 // Instruction->Native 00025 // 00026 // Template for all native types 00027 */ 00028 #ifndef Fennel_NativeInstruction_Included 00029 #define Fennel_NativeInstruction_Included 00030 00031 #include "boost/lexical_cast.hpp" 00032 #include "fennel/calculator/Instruction.h" 00033 00034 FENNEL_BEGIN_NAMESPACE 00035 00036 using boost::lexical_cast; 00037 00038 template<typename T> class RegisterRef; 00039 00040 // 00041 // NativeInstruction_NotANativeType 00042 // 00043 // Force the use of a (non-pointer) native type. 00044 // Note: You cannot use typedefs like int32_t here or the 00045 // built-in names therefrom won't work. By using the built-in 00046 // type name, you can support the built-in and typedefs 00047 // built on top. Also, signed char is somehow different 00048 // than char. This is not true for short, int, long or 00049 // long long. 00050 // 00051 template <class T> class NativeInstruction_NotANativeType; 00052 template<> class NativeInstruction_NotANativeType<char> {}; 00053 template<> class NativeInstruction_NotANativeType<short> {}; 00054 template<> class NativeInstruction_NotANativeType<int> {}; 00055 template<> class NativeInstruction_NotANativeType<long> {}; 00056 template<> class NativeInstruction_NotANativeType<long long> {}; 00057 template<> class NativeInstruction_NotANativeType<unsigned char> {}; 00058 template<> class NativeInstruction_NotANativeType<unsigned short> {}; 00059 template<> class NativeInstruction_NotANativeType<unsigned int> {}; 00060 template<> class NativeInstruction_NotANativeType<unsigned long> {}; 00061 template<> class NativeInstruction_NotANativeType<unsigned long long> {}; 00062 template<> class NativeInstruction_NotANativeType<signed char> {}; 00063 template<> class NativeInstruction_NotANativeType<float> {}; 00064 template<> class NativeInstruction_NotANativeType<double> {}; 00065 00066 00067 template<typename TMPLT> 00068 class NativeInstruction : public Instruction 00069 { 00070 public: 00071 explicit 00072 NativeInstruction(StandardTypeDescriptorOrdinal nativeType) 00073 : mOp1(), 00074 mOp2(), 00075 mNativeType(nativeType) 00076 { 00077 assert(StandardTypeDescriptor::isNative(nativeType)); 00078 } 00079 explicit 00080 NativeInstruction( 00081 RegisterRef<TMPLT>* op1, 00082 StandardTypeDescriptorOrdinal nativeType) 00083 : mOp1(op1), 00084 mOp2(), 00085 mNativeType(nativeType) 00086 { 00087 assert(StandardTypeDescriptor::isNative(nativeType)); 00088 } 00089 explicit 00090 NativeInstruction( 00091 RegisterRef<TMPLT>* op1, 00092 RegisterRef<TMPLT>* op2, 00093 StandardTypeDescriptorOrdinal nativeType) 00094 : mOp1(op1), 00095 mOp2(op2), 00096 mNativeType(nativeType) 00097 { 00098 assert(StandardTypeDescriptor::isNative(nativeType)); 00099 } 00100 00101 ~NativeInstruction() { 00102 // If (0) to reduce performance impact of template type checking 00103 if (0) { 00104 NativeInstruction_NotANativeType<TMPLT>(); 00105 } 00106 } 00107 00108 protected: 00109 RegisterRef<TMPLT>* mOp1; 00110 RegisterRef<TMPLT>* mOp2; 00111 StandardTypeDescriptorOrdinal mNativeType; 00112 }; 00113 00114 FENNEL_END_NAMESPACE 00115 00116 #endif 00117 00118 // End NativeInstruction.h 00119