Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

vtkTypeTraits.h

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

Generated on Mon Jan 21 23:07:18 2008 for VTK by  doxygen 1.4.3-20050530