Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkNumericTraits.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkNumericTraits.h,v $
00005   Language:  C++
00006   Date:      $Date: 2003/12/15 14:13:19 $
00007   Version:   $Revision: 1.34 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #ifndef __itkNumericTraits_h
00018 #define __itkNumericTraits_h
00019 
00020 #include "itkMacro.h"
00021 #undef min
00022 #undef max
00023 
00024 #include "vcl_limits.h" // for vcl_numeric_limits
00025 
00026 namespace itk
00027 {
00028 
00039 template <class T>
00040 class NumericTraits : public vcl_numeric_limits<T> {
00041 public:
00043   typedef T ValueType; 
00044 
00046   typedef T PrintType; 
00047 
00049   typedef T AbsType; 
00050 
00052   typedef double AccumulateType; 
00053 
00055   static const T Zero;
00056 
00058   static const T One;
00059 
00061   static T NonpositiveMin() { return min(); }
00062 
00064   static bool IsPositive(T val) { return val > Zero; }
00065 
00067   static bool IsNonpositive(T val) { return val <= Zero; }
00068 
00070   static bool IsNegative(T val) { return val < Zero; }
00071 
00073   static bool IsNonnegative(T val) { return val >= Zero; }
00074 };
00075 
00082 template <>
00083 class NumericTraits<bool> : public vcl_numeric_limits<bool> {
00084 public:
00085   typedef bool ValueType;
00086   typedef bool PrintType;
00087   typedef unsigned char AbsType;
00088   typedef unsigned char AccumulateType;
00089   static const bool ITKCommon_EXPORT Zero;
00090   static const bool ITKCommon_EXPORT One;
00091 
00092   static bool NonpositiveMin() { return false; }
00093   static bool IsPositive(bool val) { return val; }
00094   static bool IsNonpositive(bool val) { return !val; }
00095   static bool IsNegative(bool /* val */) { return false; }
00096   static bool IsNonnegative(bool /*val*/) {return true; }
00097 };
00098 
00103 template <>
00104 class NumericTraits<char> : public vcl_numeric_limits<char> {
00105 public:
00106   typedef char ValueType;
00107   typedef int PrintType;
00108   typedef unsigned char AbsType;
00109   typedef short AccumulateType;
00110   typedef double RealType;
00111   static const char ITKCommon_EXPORT Zero;
00112   static const char ITKCommon_EXPORT One;
00113 
00114   static char min() { return char(255) < 0 ? -128 : 0; }
00115   static char max() { return char(255) < 0 ? 127 : 255; }
00116   static char NonpositiveMin() { return min(); }
00117   static bool IsPositive(char val) { return val > Zero; }
00118   static bool IsNonpositive(char val) { return val <= Zero; }
00119   static bool IsNegative(char val) { return val < Zero; }
00120   static bool IsNonnegative(char val) {return val >= Zero; }
00121 };
00122 
00127 template <>
00128 class NumericTraits<signed char> : public vcl_numeric_limits<signed char> {
00129 public:
00130   typedef signed char ValueType;
00131   typedef int PrintType;
00132   typedef unsigned char AbsType;
00133   typedef short AccumulateType;
00134   typedef double RealType;
00135   static const signed char ITKCommon_EXPORT Zero;
00136   static const signed char ITKCommon_EXPORT One;
00137 
00138   static signed char min() { return -128; }
00139   static signed char max() { return  127; }
00140   static signed char NonpositiveMin() { return min(); }
00141   static bool IsPositive(signed char val) { return val > Zero; }
00142   static bool IsNonpositive(signed char val) { return val <= Zero; }
00143   static bool IsNegative(signed char val) { return val < Zero; }
00144   static bool IsNonnegative(signed char val) {return val >= Zero; }
00145 };
00146 
00151 template <>
00152 class NumericTraits<unsigned char> : public vcl_numeric_limits<unsigned char> {
00153 public:
00154   typedef unsigned char ValueType;
00155   typedef int PrintType;
00156   typedef unsigned char AbsType;
00157   typedef unsigned short AccumulateType;
00158   typedef double RealType;
00159   static const unsigned char ITKCommon_EXPORT Zero;
00160   static const unsigned char ITKCommon_EXPORT One;
00161 
00162   static unsigned char NonpositiveMin() { return min(); }
00163   static bool IsPositive(unsigned char val) { return val != Zero; }
00164   static bool IsNonpositive(unsigned char val) { return val == Zero; }
00165   static bool IsNegative(unsigned char /* val */) { return false; }
00166   static bool IsNonnegative(unsigned char /*val */) {return true; }
00167 };
00168 
00172 template <>
00173 class NumericTraits<short> : public vcl_numeric_limits<short> {
00174 public:
00175   typedef short ValueType;
00176   typedef short PrintType;
00177   typedef unsigned short AbsType;
00178   typedef int AccumulateType;
00179   typedef double RealType;
00180   static const short ITKCommon_EXPORT Zero;
00181   static const short ITKCommon_EXPORT One;
00182 
00183   static short NonpositiveMin() { return min(); }
00184   static bool IsPositive(short val) { return val > Zero; }
00185   static bool IsNonpositive(short val) { return val <= Zero; }
00186   static bool IsNegative(short val) { return val < Zero; }
00187   static bool IsNonnegative(short val) {return val >= Zero; }
00188 };
00189 
00194 template <>
00195 class NumericTraits<unsigned short> : public vcl_numeric_limits<unsigned short> {
00196 public:
00197   typedef unsigned short ValueType;
00198   typedef unsigned short PrintType;
00199   typedef unsigned short AbsType;
00200   typedef unsigned int AccumulateType;
00201   typedef double RealType;
00202   static const unsigned short ITKCommon_EXPORT Zero;
00203   static const unsigned short ITKCommon_EXPORT One;
00204 
00205   static unsigned short NonpositiveMin() { return min(); }
00206   static unsigned short IsPositive(unsigned short val) { return val != Zero; }
00207   static bool IsNonpositive(unsigned short val) { return val == Zero; }
00208   static bool IsNegative(unsigned short/* val*/) { return false; }
00209   static bool IsNonnegative(unsigned short /*val*/) {return true; }
00210 };
00211 
00215 template <>
00216 class NumericTraits<int> : public vcl_numeric_limits<int> {
00217 public:
00218   typedef int ValueType;
00219   typedef int PrintType;
00220   typedef unsigned int AbsType;
00221   typedef long AccumulateType;
00222   typedef double RealType;
00223   static const int ITKCommon_EXPORT Zero;
00224   static const int ITKCommon_EXPORT One;
00225 
00226   static int NonpositiveMin() { return min(); }
00227   static bool IsPositive(int val) { return val > Zero; }
00228   static bool IsNonpositive(int val) { return val <= Zero; }
00229   static bool IsNegative(int val) { return val < Zero; }
00230   static bool IsNonnegative(int val) {return val >= Zero; }
00231 };
00232 
00237 template <>
00238 class NumericTraits<unsigned int> : public vcl_numeric_limits<unsigned int> {
00239 public:
00240   typedef unsigned int ValueType;
00241   typedef unsigned int PrintType;
00242   typedef unsigned int AbsType;
00243   typedef unsigned int AccumulateType;
00244   typedef double RealType;
00245   static const unsigned int ITKCommon_EXPORT Zero;
00246   static const unsigned int ITKCommon_EXPORT One;
00247 
00248   static unsigned int min(void) { return 0; }
00249   static unsigned int max(void) { return static_cast<unsigned int>( -1 ); }
00250   static unsigned int NonpositiveMin() { return 0; }
00251   static bool IsPositive(unsigned int val) { return val != Zero; }
00252   static bool IsNonpositive(unsigned int val) { return  val == Zero; }
00253   static bool IsNegative(unsigned int /*val*/) { return false; }
00254   static bool IsNonnegative(unsigned int /*val*/) {return true; }
00255 };
00256 
00261 template <>
00262 class NumericTraits<long> : public vcl_numeric_limits<long> {
00263 public:
00264   typedef long ValueType;
00265   typedef long PrintType;
00266   typedef unsigned long AbsType;
00267   typedef long AccumulateType;
00268   typedef double RealType;
00269   static const long ITKCommon_EXPORT Zero;
00270   static const long ITKCommon_EXPORT One;
00271 
00272   static long NonpositiveMin() { return min(); }
00273   static bool IsPositive(long val) { return val > Zero; }
00274   static bool IsNonpositive(long val) { return val <= Zero; }
00275   static bool IsNegative(long val) { return val < Zero; }
00276   static bool IsNonnegative(long val) {return val >= Zero; }
00277 };
00278 
00283 template <>
00284 class NumericTraits<unsigned long> : public vcl_numeric_limits<unsigned long> {
00285 public:
00286   typedef unsigned long ValueType;
00287   typedef unsigned long PrintType;
00288   typedef unsigned long AbsType;
00289   typedef unsigned long AccumulateType;
00290   typedef double RealType;
00291   static const unsigned long ITKCommon_EXPORT Zero;
00292   static const unsigned long ITKCommon_EXPORT One;
00293 
00294   static unsigned long NonpositiveMin() { return min(); }
00295   static bool IsPositive(unsigned long val) { return val != Zero; }
00296   static bool IsNonpositive(unsigned long val) { return val == Zero; }
00297   static bool IsNegative(unsigned long) { return false; }
00298   static bool IsNonnegative(unsigned long) {return true; }
00299 };
00300 
00305 template <>
00306 class NumericTraits<float> : public vcl_numeric_limits<float> {
00307 public:
00308   typedef float ValueType;
00309   typedef float PrintType;
00310   typedef float AbsType;
00311   typedef double AccumulateType;
00312   typedef double RealType;
00313   static const float ITKCommon_EXPORT Zero;
00314   static const float ITKCommon_EXPORT One;
00315 
00316   static float NonpositiveMin() { return -max(); }
00317   static bool IsPositive(float val) { return val > Zero; }
00318   static bool IsNonpositive(float val) { return val <= Zero; }
00319   static bool IsNegative(float val) { return val < Zero; }
00320   static bool IsNonnegative(float val) {return val >= Zero; }
00321 };
00322 
00327 template <>
00328 class NumericTraits<double> : public vcl_numeric_limits<double> {
00329 public:
00330   typedef double ValueType;
00331   typedef double PrintType;
00332   typedef double AbsType;
00333   typedef double AccumulateType;
00334   typedef double RealType;
00335   static const double ITKCommon_EXPORT Zero;
00336   static const double ITKCommon_EXPORT One;
00337 
00338   static double NonpositiveMin() { return -max(); }
00339   static bool IsPositive(double val) { return val > Zero; }
00340   static bool IsNonpositive(double val) { return val <= Zero; }
00341   static bool IsNegative(double val) { return val < Zero; }
00342   static bool IsNonnegative(double val) {return val >= Zero; }
00343 };
00344 
00349 template <>
00350 class NumericTraits<long double> : public vcl_numeric_limits<long double> {
00351 public:
00352   typedef long double ValueType;
00353   typedef long double PrintType;
00354   typedef long double AbsType;
00355   typedef long double AccumulateType;
00356   typedef long double RealType;
00357   static const long double ITKCommon_EXPORT Zero;
00358   static const long double ITKCommon_EXPORT One;
00359 
00360   static long double NonpositiveMin() { return -max(); }
00361   static bool IsPositive(long double val) { return val > Zero; }
00362   static bool IsNonpositive(long double val) { return val <= Zero; }
00363   static bool IsNegative(long double val) { return val < Zero; }
00364   static bool IsNonnegative(long double val) {return val >= Zero; }
00365 };
00366 
00367 } // end namespace itk
00368 
00369 #endif // __itkNumericTraits_h

Generated at Sun Jan 25 13:19:42 2004 for ITK by doxygen 1.3.3 written by Dimitri van Heesch, © 1997-2000