numericTraits.h

Go to the documentation of this file.
00001 
00017 #ifndef _DLR_NUMERICTRAITS_H_
00018 #define _DLR_NUMERICTRAITS_H_
00019 
00020 #include <dlrCommon/exception.h>
00021 
00022 namespace dlr {
00023 
00024   namespace numeric {
00025     
00032     template <class Type>
00033     class NumericTraits {
00034     public:
00035       /* ==================== Public typedefs ==================== */
00036 
00043       typedef Type ProductType;
00044 
00051       typedef Type SumType;
00052 
00058       typedef Type TextOutputType;
00059 
00060       /* ==================== Public methods ==================== */
00061 
00072       inline bool
00073       isIntegral() {
00074         DLR_THROW3(NotImplementedException, "NumericTraits::isIntegral()",
00075                    "In order to use isIntegral, NumericTraits must be "
00076                    "specialized for each type.");
00077         return true; // Appease the compiler.
00078       }
00079 
00080     };
00081 
00086     template <>
00087     class NumericTraits<char> {
00088     public:
00089       /* ==================== Public typedefs ==================== */
00090 
00096       typedef int ProductType;
00097 
00103       typedef int SumType;
00104 
00117       typedef int TextOutputType;
00118 
00119       /* ==================== Public methods ==================== */
00120 
00128       inline bool
00129       isIntegral() {return true;}
00130     
00131     };
00132 
00133   
00138     template <>
00139     class NumericTraits<unsigned char> {
00140     public:
00141       /* ==================== Public typedefs ==================== */
00142 
00148       typedef unsigned int ProductType;
00149 
00155       typedef unsigned int SumType;
00156 
00161       typedef int TextOutputType;
00162 
00163       /* ==================== Public methods ==================== */
00164     
00172       inline bool
00173       isIntegral() {return true;}
00174     
00175     };
00176 
00177   
00182     template <>
00183     class NumericTraits<short> {
00184     public:
00185       /* ==================== Public typedefs ==================== */
00186 
00192       typedef int ProductType;
00193 
00199       typedef int SumType;
00200 
00205       typedef short TextOutputType;
00206 
00207       /* ==================== Public methods ==================== */
00208 
00216       inline bool
00217       isIntegral() {return true;}
00218     
00219     };
00220 
00225     template <>
00226     class NumericTraits<int> {
00227     public:
00228       /* ==================== Public typedefs ==================== */
00229 
00234       typedef long ProductType;
00235 
00240       typedef long SumType;
00241 
00246       typedef int TextOutputType;
00247 
00248       /* ==================== Public methods ==================== */
00249 
00257       inline bool
00258       isIntegral() {return true;}
00259     
00260     };
00261 
00262   
00267     template <>
00268     class NumericTraits<long> {
00269     public:
00270       /* ==================== Public typedefs ==================== */
00271 
00277       typedef long ProductType;
00278 
00284       typedef long SumType;
00285 
00290       typedef long TextOutputType;
00291 
00292       /* ==================== Public methods ==================== */
00293 
00301       inline bool
00302       isIntegral() {return true;}
00303     
00304     };
00305 
00310     template <>
00311     class NumericTraits<float> {
00312     public:
00313       /* ==================== Public typedefs ==================== */
00314 
00319       typedef float ProductType;
00320 
00325       typedef float SumType;
00326 
00331       typedef float TextOutputType;
00332 
00333       /* ==================== Public methods ==================== */
00334 
00342       inline bool
00343       isIntegral() {return false;}
00344     
00345     };
00346 
00351     template <>
00352     class NumericTraits<double> {
00353     public:
00354       /* ==================== Public typedefs ==================== */
00355 
00360       typedef double ProductType;
00361 
00366       typedef double SumType;
00367 
00372       typedef double TextOutputType;
00373 
00374       /* ==================== Public methods ==================== */
00375 
00383       inline bool
00384       isIntegral() {return false;}
00385     
00386     };
00387 
00388   } // namespace numeric
00389 
00390 } // namespace dlr
00391 
00392 
00393 /* ======= Declarations to maintain compatibility with legacy code. ======= */
00394 
00395 namespace dlr {
00396 
00397   using numeric::NumericTraits;
00398 
00399 } // namespace dlr
00400 
00401 #endif // #ifndef _DLR_NUMERICTRAITS_H_

Generated on Wed Nov 25 00:42:42 2009 for dlrUtilities Utility Library by  doxygen 1.5.8