Teuchos_OrdinalTraits.hpp

Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //                    Teuchos: Common Tools Package
00005 //                 Copyright (2004) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 // Kris
00030 // 07.08.03 -- Move into Teuchos package/namespace
00031 
00032 #ifndef _TEUCHOS_ORDINALTRAITS_HPP_
00033 #define _TEUCHOS_ORDINALTRAITS_HPP_
00034 
00039 #include "Teuchos_ConfigDefs.hpp"
00040 #include <limits>
00041 
00055 /* This is the default structure used by OrdinalTraits<T> to produce a compile time
00056    error when the specialization does not exist for type <tt>T</tt>.
00057 */
00058 namespace Teuchos {
00059 
00060 template<class T>
00061 struct UndefinedOrdinalTraits
00062 {
00064   static inline T notDefined() { return T::this_type_is_missing_a_specialization(); }
00065 };
00066   
00067 template<class T>
00068 struct OrdinalTraits {
00069 
00071   static const bool hasMachineParameters = false;
00072     
00074   static inline T zero()                     { return UndefinedOrdinalTraits<T>::notDefined(); }
00075 
00077   static inline T one()                      { return UndefinedOrdinalTraits<T>::notDefined(); }
00078 
00080 
00083   static inline T max()                  { return UndefinedOrdinalTraits<T>::notDefined(); }
00084 
00086   static inline T invalid()                  { return UndefinedOrdinalTraits<T>::notDefined(); }
00087 
00089   static inline std::string name()           { return UndefinedOrdinalTraits<T>::notDefined(); }
00090 };
00091   
00092 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00093 
00094 template<>
00095 struct OrdinalTraits<char> {
00096   static const bool hasMachineParameters = false;
00097   static inline char zero()                   {return(0);}
00098   static inline char one()                    {return(1);}
00099   static inline char invalid()                {return(-1);}
00100   static inline char max()                    {return(std::numeric_limits<char>::max());}
00101   static inline std::string name()            {return("char");}
00102 };
00103 
00104 template<>
00105 struct OrdinalTraits<short int> {
00106   static const bool hasMachineParameters = false;
00107   static inline short int zero()              {return(0);}
00108   static inline short int one()               {return(1);}
00109   static inline short int invalid()           {return(-1);}
00110   static inline short int max()               {return(std::numeric_limits<short int>::max());}
00111   static inline std::string name()            {return("short int");}
00112 };
00113 
00114 template<>
00115 struct OrdinalTraits<int> {
00116   static const bool hasMachineParameters = false;
00117   static inline int zero()                   {return(0);}
00118   static inline int one()                    {return(1);}
00119   static inline int invalid()                {return(-1);}
00120   static inline int max()                    {return(std::numeric_limits<int>::max());}
00121   static inline std::string name()           {return("int");}
00122 };
00123 
00124 template<>
00125 struct OrdinalTraits<unsigned int> {
00126   static const bool hasMachineParameters = false;
00127   static inline unsigned int zero()                   {return(0);}
00128   static inline unsigned int one()                    {return(1);}
00129   static inline unsigned int invalid()                {return(std::numeric_limits<unsigned int>::max());}
00130   static inline unsigned int max()                    {return(std::numeric_limits<unsigned int>::max()-1);}
00131   static inline std::string name()           {return("unsigned int");}
00132 };
00133 
00134 template<>
00135 struct OrdinalTraits<long int> {
00136   static const bool hasMachineParameters = false;
00137   static inline long int zero()              {return(static_cast<long int>(0));}
00138   static inline long int one()               {return(static_cast<long int>(1));}
00139   static inline long int invalid()           {return(static_cast<long int>(-1));}
00140   static inline long int max()               {return(std::numeric_limits<long int>::max());}
00141   static inline std::string name()           {return("long int");}
00142 };
00143 
00144 template<>
00145 struct OrdinalTraits<long unsigned int> {
00146   static const bool hasMachineParameters = false;
00147   static inline long unsigned int zero()              {return(static_cast<long unsigned int>(0));}
00148   static inline long unsigned int one()               {return(static_cast<long unsigned int>(1));}
00149   static inline long unsigned int invalid()           {return(std::numeric_limits<long unsigned int>::max());}
00150   static inline long unsigned int max()               {return(std::numeric_limits<long unsigned int>::max()-1);}
00151   static inline std::string name()           {return("long unsigned int");}
00152 };
00153 
00154 #ifdef HAVE_TEUCHOS_LONG_LONG_INT
00155 template<>
00156 struct OrdinalTraits<long long int> {
00157   static const bool hasMachineParameters = false;
00158   static inline long long int zero()          {return(static_cast<long long int>(0));}
00159   static inline long long int one()           {return(static_cast<long long int>(1));}
00160   static inline long long int invalid()       {return(static_cast<long long int>(-1));}
00161   static inline long long int max()           {return(LLONG_MAX);}
00162   static inline std::string name()            {return("long long int");}
00163 };
00164 #endif // HAVE_TEUCHOS_LONG_LONG_INT
00165 
00166 #endif // DOXYGEN_SHOULD_SKIP_THIS
00167 
00168 } // namespace Teuchos
00169 
00170 #endif // _TEUCHOS_ORDINALTRAITS_HPP_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Tue Oct 20 10:14:00 2009 for Teuchos Package Browser (Single Doxygen Collection) by  doxygen 1.6.1