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

Generated on Thu Sep 7 11:42:31 2006 for VTK by  doxygen 1.4.3-20050530