VTK
|
00001 /*========================================================================= 00002 00003 Program: ParaView 00004 Module: vtkTypeTraits.h 00005 00006 Copyright (c) Kitware, Inc. 00007 All rights reserved. 00008 See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00025 #ifndef __vtkTypeTraits_h 00026 #define __vtkTypeTraits_h 00027 00028 #include "vtkSystemIncludes.h" 00029 00030 // Forward-declare template. There is no primary template. 00031 template <class T> struct vtkTypeTraits; 00032 00033 // Define a macro to simplify trait definitions. 00034 #define VTK_TYPE_TRAITS(type, macro, isSigned, name, print, format) \ 00035 VTK_TEMPLATE_SPECIALIZE struct vtkTypeTraits< type > \ 00036 { \ 00037 /* The type itself. */ \ 00038 typedef type ValueType; \ 00039 \ 00040 /* the value defined for this type in vtkType */ \ 00041 enum { VTK_TYPE_ID = VTK_##macro }; \ 00042 static int VTKTypeID() { return VTK_##macro; } \ 00043 \ 00044 /* The smallest possible value represented by the type. */ \ 00045 static type Min() { return VTK_##macro##_MIN; } \ 00046 \ 00047 /* The largest possible value represented by the type. */ \ 00048 static type Max() { return VTK_##macro##_MAX; } \ 00049 \ 00050 /* Whether the type is signed. */ \ 00051 static int IsSigned() { return isSigned; } \ 00052 \ 00053 /* An "alias" type that is the same size and signedness. */ \ 00054 typedef vtkType##name SizedType; \ 00055 \ 00056 /* A name for the type indicating its size and signedness. */ \ 00057 static const char* SizedName() { return #name; } \ 00058 \ 00059 /* A type to use for printing or parsing values in strings. */ \ 00060 typedef print PrintType; \ 00061 \ 00062 /* A format for parsing values from strings. Use with PrintType. */ \ 00063 static const char* ParseFormat() { return format; } \ 00064 } 00065 00066 // Define traits for floating-point types. 00067 #define VTK_TYPE_NAME_FLOAT float 00068 #define VTK_TYPE_NAME_DOUBLE double 00069 #define VTK_TYPE_SIZED_FLOAT FLOAT32 00070 #define VTK_TYPE_SIZED_DOUBLE FLOAT64 00071 VTK_TYPE_TRAITS(float, FLOAT, 1, Float32, float, "%f"); 00072 VTK_TYPE_TRAITS(double, DOUBLE, 1, Float64, double, "%lf"); 00073 00074 // Define traits for char types. 00075 // Note the print type is short because not all platforms support formating integers with char. 00076 #define VTK_TYPE_NAME_CHAR char 00077 #if VTK_TYPE_CHAR_IS_SIGNED 00078 # define VTK_TYPE_SIZED_CHAR INT8 00079 VTK_TYPE_TRAITS(char, CHAR, 1, Int8, short, "%hd"); 00080 #else 00081 # define VTK_TYPE_SIZED_CHAR UINT8 00082 VTK_TYPE_TRAITS(char, CHAR, 0, UInt8, unsigned short, "%hu"); 00083 #endif 00084 #define VTK_TYPE_NAME_SIGNED_CHAR signed char 00085 #define VTK_TYPE_NAME_UNSIGNED_CHAR unsigned char 00086 #define VTK_TYPE_SIZED_SIGNED_CHAR INT8 00087 #define VTK_TYPE_SIZED_UNSIGNED_CHAR UINT8 00088 VTK_TYPE_TRAITS(signed char, SIGNED_CHAR, 1, Int8, short, "%hd"); 00089 VTK_TYPE_TRAITS(unsigned char, UNSIGNED_CHAR, 0, UInt8, unsigned short, "%hu"); 00090 00091 // Define traits for short types. 00092 #define VTK_TYPE_NAME_SHORT short 00093 #define VTK_TYPE_NAME_UNSIGNED_SHORT unsigned short 00094 #define VTK_TYPE_SIZED_SHORT INT16 00095 #define VTK_TYPE_SIZED_UNSIGNED_SHORT UINT16 00096 VTK_TYPE_TRAITS(short, SHORT, 1, Int16, short, "%hd"); 00097 VTK_TYPE_TRAITS(unsigned short, UNSIGNED_SHORT, 0, UInt16, unsigned short, 00098 "%hu"); 00099 00100 // Define traits for int types. 00101 #define VTK_TYPE_NAME_INT int 00102 #define VTK_TYPE_NAME_UNSIGNED_INT unsigned int 00103 #define VTK_TYPE_SIZED_INT INT32 00104 #define VTK_TYPE_SIZED_UNSIGNED_INT UINT32 00105 VTK_TYPE_TRAITS(int, INT, 1, Int32, int, "%d"); 00106 VTK_TYPE_TRAITS(unsigned int, UNSIGNED_INT, 0, UInt32, unsigned int, "%u"); 00107 00108 // Define traits for long types. 00109 #define VTK_TYPE_NAME_LONG long 00110 #define VTK_TYPE_NAME_UNSIGNED_LONG unsigned long 00111 #if VTK_SIZEOF_LONG == 4 00112 # define VTK_TYPE_SIZED_LONG INT32 00113 # define VTK_TYPE_SIZED_UNSIGNED_LONG UINT32 00114 VTK_TYPE_TRAITS(long, LONG, 1, Int32, long, "%ld"); 00115 VTK_TYPE_TRAITS(unsigned long, UNSIGNED_LONG, 0, UInt32, unsigned long, "%lu"); 00116 #elif VTK_SIZEOF_LONG == 8 00117 # define VTK_TYPE_SIZED_LONG INT64 00118 # define VTK_TYPE_SIZED_UNSIGNED_LONG UINT64 00119 VTK_TYPE_TRAITS(long, LONG, 1, Int64, long, "%ld"); 00120 VTK_TYPE_TRAITS(unsigned long, UNSIGNED_LONG, 0, UInt64, unsigned long, "%lu"); 00121 #else 00122 # error "Type long is not 4 or 8 bytes in size." 00123 #endif 00124 00125 // Define traits for long long types if they are enabled. 00126 #if defined(VTK_TYPE_USE_LONG_LONG) 00127 # define VTK_TYPE_NAME_LONG_LONG long long 00128 # define VTK_TYPE_NAME_UNSIGNED_LONG_LONG unsigned long long 00129 # if VTK_SIZEOF_LONG_LONG == 8 00130 # define VTK_TYPE_SIZED_LONG_LONG INT64 00131 # define VTK_TYPE_SIZED_UNSIGNED_LONG_LONG UINT64 00132 # if defined(_MSC_VER) && _MSC_VER < 1400 00133 # define VTK_TYPE_LONG_LONG_FORMAT "%I64" 00134 # else 00135 # define VTK_TYPE_LONG_LONG_FORMAT "%ll" 00136 # endif 00137 VTK_TYPE_TRAITS(long long, LONG_LONG, 1, Int64, long long, 00138 VTK_TYPE_LONG_LONG_FORMAT "d"); 00139 VTK_TYPE_TRAITS(unsigned long long, UNSIGNED_LONG_LONG, 0, UInt64, 00140 unsigned long long, VTK_TYPE_LONG_LONG_FORMAT "u"); 00141 # undef VTK_TYPE_LONG_LONG_FORMAT 00142 # else 00143 # error "Type long long is not 8 bytes in size." 00144 # endif 00145 #endif 00146 00147 // Define traits for __int64 types if they are enabled. 00148 #if defined(VTK_TYPE_USE___INT64) 00149 # define VTK_TYPE_NAME___INT64 __int64 00150 # define VTK_TYPE_NAME_UNSIGNED___INT64 unsigned __int64 00151 # if VTK_SIZEOF___INT64 == 8 00152 # define VTK_TYPE_SIZED___INT64 INT64 00153 # define VTK_TYPE_SIZED_UNSIGNED___INT64 UINT64 00154 VTK_TYPE_TRAITS(__int64, __INT64, 1, Int64, __int64, "%I64d"); 00155 VTK_TYPE_TRAITS(unsigned __int64, UNSIGNED___INT64, 0, UInt64, 00156 unsigned __int64, "%I64u"); 00157 # else 00158 # error "Type __int64 is not 8 bytes in size." 00159 # endif 00160 #endif 00161 00162 // Define traits for vtkIdType. The template specialization is 00163 // already defined for the corresponding native type. 00164 #define VTK_TYPE_NAME_ID_TYPE vtkIdType 00165 #if defined(VTK_USE_64BIT_IDS) 00166 # define VTK_TYPE_SIZED_ID_TYPE INT64 00167 #else 00168 # define VTK_TYPE_SIZED_ID_TYPE INT32 00169 #endif 00170 00171 #undef VTK_TYPE_TRAITS 00172 00173 #endif 00174 // VTK-HeaderTest-Exclude: vtkTypeTraits.h