Teuchos - Trilinos Tools Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_OrdinalTraits.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Teuchos: Common Tools Package
4 //
5 // Copyright 2004 NTESS and the Teuchos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 // Kris
11 // 07.08.03 -- Move into Teuchos package/namespace
12 
13 #ifndef _TEUCHOS_ORDINALTRAITS_HPP_
14 #define _TEUCHOS_ORDINALTRAITS_HPP_
15 
20 #include "Teuchos_ConfigDefs.hpp"
21 #include <limits>
22 
36 /* This is the default structure used by OrdinalTraits<T> to produce a compile time
37  error when the specialization does not exist for type <tt>T</tt>.
38 */
39 namespace Teuchos {
40 
41 template<class T>
42 struct UndefinedOrdinalTraits
43 {
45  static inline T notDefined() { return T::this_type_is_missing_a_specialization(); }
46 };
47 
48 template<class T>
49 struct OrdinalTraits {
50 
52  static const bool hasMachineParameters = false;
53 
55  static inline T zero() { return UndefinedOrdinalTraits<T>::notDefined(); }
56 
58  static inline T one() { return UndefinedOrdinalTraits<T>::notDefined(); }
59 
61 
64  static inline T max() { return UndefinedOrdinalTraits<T>::notDefined(); }
65 
67  static inline T invalid() { return UndefinedOrdinalTraits<T>::notDefined(); }
68 
70  static inline std::string name() { return UndefinedOrdinalTraits<T>::notDefined(); }
71 };
72 
73 #ifndef DOXYGEN_SHOULD_SKIP_THIS
74 
75 template<>
76 struct OrdinalTraits<char> {
77  static const bool hasMachineParameters = false;
78  static inline char zero() {return(0);}
79  static inline char one() {return(1);}
80  static inline char invalid() {return(std::numeric_limits<char>::max());}
81  static inline char max() {return(std::numeric_limits<char>::max()-one());}
82  static inline std::string name() {return("char");}
83 };
84 
85 template<>
86 struct OrdinalTraits<short int> {
87  static const bool hasMachineParameters = false;
88  static inline short int zero() {return(0);}
89  static inline short int one() {return(1);}
90  static inline short int invalid() {return(-1);}
91  static inline short int max() {return(std::numeric_limits<short int>::max());}
92  static inline std::string name() {return("short int");}
93 };
94 
95 template<>
96 struct OrdinalTraits<int> {
97  static const bool hasMachineParameters = false;
98  static inline int zero() {return(0);}
99  static inline int one() {return(1);}
100  static inline int invalid() {return(-1);}
101  static inline int max() {return(std::numeric_limits<int>::max());}
102  static inline std::string name() {return("int");}
103 };
104 
105 template<>
106 struct OrdinalTraits<unsigned int> {
107  static const bool hasMachineParameters = false;
108  static inline unsigned int zero() {return(0);}
109  static inline unsigned int one() {return(1);}
110  static inline unsigned int invalid() {return(std::numeric_limits<unsigned int>::max());}
111  static inline unsigned int max() {return(std::numeric_limits<unsigned int>::max()-1);}
112  static inline std::string name() {return("unsigned int");}
113 };
114 
115 template<>
116 struct OrdinalTraits<long int> {
117  static const bool hasMachineParameters = false;
118  static inline long int zero() {return(static_cast<long int>(0));}
119  static inline long int one() {return(static_cast<long int>(1));}
120  static inline long int invalid() {return(static_cast<long int>(-1));}
121  static inline long int max() {return(std::numeric_limits<long int>::max());}
122  static inline std::string name() {return("long int");}
123 };
124 
125 template<>
126 struct OrdinalTraits<long unsigned int> {
127  static const bool hasMachineParameters = false;
128  static inline long unsigned int zero() {return(static_cast<long unsigned int>(0));}
129  static inline long unsigned int one() {return(static_cast<long unsigned int>(1));}
130  static inline long unsigned int invalid() {return(std::numeric_limits<long unsigned int>::max());}
131  static inline long unsigned int max() {return(std::numeric_limits<long unsigned int>::max()-1);}
132  static inline std::string name() {return("long unsigned int");}
133 };
134 
135 template<>
136 struct OrdinalTraits<long long int> {
137  static const bool hasMachineParameters = false;
138  static inline long long int zero() {return(static_cast<long long int>(0));}
139  static inline long long int one() {return(static_cast<long long int>(1));}
140  static inline long long int invalid() {return(static_cast<long long int>(-1));}
141  static inline long long int max() {return(std::numeric_limits<long long int>::max());}
142  static inline std::string name() {return("long long int");}
143 };
144 
145 template<>
146 struct OrdinalTraits<unsigned long long int> {
147  static const bool hasMachineParameters = false;
148  static inline unsigned long long int zero() {return(static_cast<unsigned long long int>(0));}
149  static inline unsigned long long int one() {return(static_cast<unsigned long long int>(1));}
150  static inline unsigned long long int invalid() {return(std::numeric_limits<unsigned long long int>::max());}
151  static inline unsigned long long int max() {return(std::numeric_limits<unsigned long long int>::max()-1);}
152  static inline std::string name() {return("unsigned long long int");}
153 };
154 
155 #ifdef HAVE_TEUCHOS___INT64
156 
157 template<>
158 struct OrdinalTraits<__int64> {
159  static const bool hasMachineParameters = false;
160  static inline __int64 zero() {return(static_cast<__int64>(0));}
161  static inline __int64 one() {return(static_cast<__int64>(1));}
162  static inline __int64 invalid() {return(std::numeric_limits<__int64>::max());}
163  static inline __int64 max() {return(std::numeric_limits<__int64>::max()-1);}
164  static inline std::string name() {return("__int64");}
165 };
166 
167 template<>
168 struct OrdinalTraits<unsigned __int64> {
169  static const bool hasMachineParameters = false;
170  static inline unsigned __int64 zero() {return(static_cast<unsigned __int64>(0));}
171  static inline unsigned __int64 one() {return(static_cast<unsigned __int64>(1));}
172  static inline unsigned __int64 invalid() {return(std::numeric_limits<unsigned __int64>::max());}
173  static inline unsigned __int64 max() {return(std::numeric_limits<unsigned __int64>::max()-1);}
174  static inline std::string name() {return("unsigned __int64");}
175 };
176 
177 #endif // HAVE_TEUCHOS___INT64
178 
179 #endif // DOXYGEN_SHOULD_SKIP_THIS
180 
181 } // namespace Teuchos
182 
183 #endif // _TEUCHOS_ORDINALTRAITS_HPP_
static T one()
Returns representation of one for this ordinal type.
static T zero()
Returns representation of zero for this ordinal type.
static T invalid()
Returns a value designating an invalid number. For signed types, this is typically negative one; for ...
static const bool hasMachineParameters
Allows testing to see if ordinal traits machine parameters are defined.
Teuchos header file which uses auto-configuration information to include necessary C++ headers...
static T max()
Returns a value designating the maximum value accessible by code using OrdinalTraits.
This structure defines some basic traits for the ordinal field type.
static std::string name()
Returns name of this ordinal type.