Teuchos - Trilinos Tools Package Version of the Day
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 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00038 //
00039 // ***********************************************************************
00040 // @HEADER
00041 
00042 // Kris
00043 // 07.08.03 -- Move into Teuchos package/namespace
00044 
00045 #ifndef _TEUCHOS_ORDINALTRAITS_HPP_
00046 #define _TEUCHOS_ORDINALTRAITS_HPP_
00047 
00052 #include "Teuchos_ConfigDefs.hpp"
00053 #include <limits>
00054 
00068 /* This is the default structure used by OrdinalTraits<T> to produce a compile time
00069    error when the specialization does not exist for type <tt>T</tt>.
00070 */
00071 namespace Teuchos {
00072 
00073 template<class T>
00074 struct UndefinedOrdinalTraits
00075 {
00077   static inline T notDefined() { return T::this_type_is_missing_a_specialization(); }
00078 };
00079   
00080 template<class T>
00081 struct OrdinalTraits {
00082 
00084   static const bool hasMachineParameters = false;
00085     
00087   static inline T zero()                     { return UndefinedOrdinalTraits<T>::notDefined(); }
00088 
00090   static inline T one()                      { return UndefinedOrdinalTraits<T>::notDefined(); }
00091 
00093 
00096   static inline T max()                  { return UndefinedOrdinalTraits<T>::notDefined(); }
00097 
00099   static inline T invalid()                  { return UndefinedOrdinalTraits<T>::notDefined(); }
00100 
00102   static inline std::string name()           { return UndefinedOrdinalTraits<T>::notDefined(); }
00103 };
00104   
00105 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00106 
00107 template<>
00108 struct OrdinalTraits<char> {
00109   static const bool hasMachineParameters = false;
00110   static inline char zero()                   {return(0);}
00111   static inline char one()                    {return(1);}
00112   static inline char invalid()                {return(std::numeric_limits<char>::max());}
00113   static inline char max()                    {return(std::numeric_limits<char>::max()-one());}
00114   static inline std::string name()            {return("char");}
00115 };
00116 
00117 template<>
00118 struct OrdinalTraits<short int> {
00119   static const bool hasMachineParameters = false;
00120   static inline short int zero()              {return(0);}
00121   static inline short int one()               {return(1);}
00122   static inline short int invalid()           {return(-1);}
00123   static inline short int max()               {return(std::numeric_limits<short int>::max());}
00124   static inline std::string name()            {return("short int");}
00125 };
00126 
00127 template<>
00128 struct OrdinalTraits<int> {
00129   static const bool hasMachineParameters = false;
00130   static inline int zero()                   {return(0);}
00131   static inline int one()                    {return(1);}
00132   static inline int invalid()                {return(-1);}
00133   static inline int max()                    {return(std::numeric_limits<int>::max());}
00134   static inline std::string name()           {return("int");}
00135 };
00136 
00137 template<>
00138 struct OrdinalTraits<unsigned int> {
00139   static const bool hasMachineParameters = false;
00140   static inline unsigned int zero()                   {return(0);}
00141   static inline unsigned int one()                    {return(1);}
00142   static inline unsigned int invalid()                {return(std::numeric_limits<unsigned int>::max());}
00143   static inline unsigned int max()                    {return(std::numeric_limits<unsigned int>::max()-1);}
00144   static inline std::string name()           {return("unsigned int");}
00145 };
00146 
00147 template<>
00148 struct OrdinalTraits<long int> {
00149   static const bool hasMachineParameters = false;
00150   static inline long int zero()              {return(static_cast<long int>(0));}
00151   static inline long int one()               {return(static_cast<long int>(1));}
00152   static inline long int invalid()           {return(static_cast<long int>(-1));}
00153   static inline long int max()               {return(std::numeric_limits<long int>::max());}
00154   static inline std::string name()           {return("long int");}
00155 };
00156 
00157 template<>
00158 struct OrdinalTraits<long unsigned int> {
00159   static const bool hasMachineParameters = false;
00160   static inline long unsigned int zero()              {return(static_cast<long unsigned int>(0));}
00161   static inline long unsigned int one()               {return(static_cast<long unsigned int>(1));}
00162   static inline long unsigned int invalid()           {return(std::numeric_limits<long unsigned int>::max());}
00163   static inline long unsigned int max()               {return(std::numeric_limits<long unsigned int>::max()-1);}
00164   static inline std::string name()           {return("long unsigned int");}
00165 };
00166 
00167 #ifdef HAVE_TEUCHOS_LONG_LONG_INT
00168 template<>
00169 struct OrdinalTraits<long long int> {
00170   static const bool hasMachineParameters = false;
00171   static inline long long int zero()          {return(static_cast<long long int>(0));}
00172   static inline long long int one()           {return(static_cast<long long int>(1));}
00173   static inline long long int invalid()       {return(static_cast<long long int>(-1));}
00174   static inline long long int max()           {return(LLONG_MAX);}
00175   static inline std::string name()            {return("long long int");}
00176 };
00177 #endif // HAVE_TEUCHOS_LONG_LONG_INT
00178 
00179 #endif // DOXYGEN_SHOULD_SKIP_THIS
00180 
00181 } // namespace Teuchos
00182 
00183 #endif // _TEUCHOS_ORDINALTRAITS_HPP_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines