Generated on for Gecode by doxygen 1.17.0
int-type.hpp
Go to the documentation of this file.
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Christian Schulte <schulte@gecode.dev>
5 *
6 * Copyright:
7 * Christian Schulte, 2008
8 *
9 * This file is part of Gecode, the generic constraint
10 * development environment:
11 * http://www.gecode.dev
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining
14 * a copy of this software and associated documentation files (the
15 * "Software"), to deal in the Software without restriction, including
16 * without limitation the rights to use, copy, modify, merge, publish,
17 * distribute, sublicense, and/or sell copies of the Software, and to
18 * permit persons to whom the Software is furnished to do so, subject to
19 * the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be
22 * included in all copies or substantial portions of the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 *
32 */
33
34#include <climits>
35#include <cstddef>
36#include <cstdint>
37#include <limits>
38#include <type_traits>
39
40namespace Gecode { namespace Support {
41
50#ifdef UINTPTR_MAX
51 using uptrint_t = std::uintptr_t;
52#else
53 using uptrint_t = std::make_unsigned_t<ptrdiff_t>;
54 static_assert(std::numeric_limits<uptrint_t>::digits >= sizeof(void*)*CHAR_BIT,
55 "Pointer encoding requires a pointer-wide integer");
56#endif
57
59 enum IntType {
60 IT_CHAR = 0,
61 IT_SHRT = 1,
62 IT_INT = 2
63 };
64
66 IntType u_type(unsigned int n);
68 IntType s_type(signed int n);
69
71 template<class IntType>
72 class IntTypeTraits {};
73
75 template<>
76 class IntTypeTraits<signed char> {
77 public:
79 typedef unsigned char utype;
81 typedef signed char stype;
83 static const signed char min = SCHAR_MIN;
85 static const signed char max = SCHAR_MAX;
87 static const IntType description = IT_CHAR;
88 };
89
90 template<>
91 class IntTypeTraits<unsigned char> {
92 public:
94 typedef unsigned char utype;
96 typedef signed char stype;
98 static const unsigned char min = 0;
100 static const unsigned char max = UCHAR_MAX;
103 };
104
105 template<>
106 class IntTypeTraits<signed short int> {
107 public:
109 typedef unsigned short int utype;
111 typedef signed short int stype;
113 static const signed short int min = SHRT_MIN;
115 static const signed short int max = SHRT_MAX;
118 };
119
120 template<>
121 class IntTypeTraits<unsigned short int> {
122 public:
124 typedef unsigned short int utype;
126 typedef signed short int stype;
128 static const unsigned short int min = 0;
130 static const unsigned short int max = USHRT_MAX;
133 };
134
135 template<>
136 class IntTypeTraits<signed int> {
137 public:
139 typedef unsigned int utype;
141 typedef signed int stype;
143 static const signed int min = INT_MIN;
145 static const signed int max = INT_MAX;
147 static const IntType description = IT_INT;
148 };
149
150 template<>
151 class IntTypeTraits<unsigned int> {
152 public:
154 typedef unsigned int utype;
156 typedef signed int stype;
158 static const unsigned int min = 0;
160 static const unsigned int max = UINT_MAX;
162 static const IntType description = IT_INT;
163 };
164
165
167 u_type(unsigned int n) {
168 if (n < UCHAR_MAX)
169 return IT_CHAR;
170 else if (n < USHRT_MAX)
171 return IT_SHRT;
172 else
173 return IT_INT;
174 }
175
177 s_type(int n) {
178 if ((n > SCHAR_MIN) && (n < SCHAR_MAX))
179 return IT_CHAR;
180 else if ((n > SHRT_MIN) && (n < SHRT_MAX))
181 return IT_SHRT;
182 else
183 return IT_INT;
184 }
185
186}}
187
188// STATISTICS: support-any
signed char stype
Corresponding signed type.
Definition int-type.hpp:81
static const signed char max
Maximal value.
Definition int-type.hpp:85
static const signed char min
Minimal value.
Definition int-type.hpp:83
unsigned char utype
Corresponding unsigned type.
Definition int-type.hpp:79
static const IntType description
Description of type.
Definition int-type.hpp:87
static const signed int max
Maximal value.
Definition int-type.hpp:145
static const IntType description
Description of type.
Definition int-type.hpp:147
signed int stype
Corresponding signed type.
Definition int-type.hpp:141
static const signed int min
Minimal value.
Definition int-type.hpp:143
unsigned int utype
Corresponding unsigned type.
Definition int-type.hpp:139
static const signed short int max
Maximal value.
Definition int-type.hpp:115
static const IntType description
Description of type.
Definition int-type.hpp:117
signed short int stype
Corresponding signed type.
Definition int-type.hpp:111
unsigned short int utype
Corresponding unsigned type.
Definition int-type.hpp:109
static const signed short int min
Minimal value.
Definition int-type.hpp:113
static const IntType description
Description of type.
Definition int-type.hpp:102
static const unsigned char max
Maximal value.
Definition int-type.hpp:100
static const unsigned char min
Minimal value.
Definition int-type.hpp:98
unsigned char utype
Corresponding unsigned type.
Definition int-type.hpp:94
signed char stype
Corresponding signed type.
Definition int-type.hpp:96
static const unsigned int max
Maximal value.
Definition int-type.hpp:160
signed int stype
Corresponding signed type.
Definition int-type.hpp:156
static const unsigned int min
Minimal value.
Definition int-type.hpp:158
static const IntType description
Description of type.
Definition int-type.hpp:162
unsigned int utype
Corresponding unsigned type.
Definition int-type.hpp:154
static const unsigned short int min
Minimal value.
Definition int-type.hpp:128
unsigned short int utype
Corresponding unsigned type.
Definition int-type.hpp:124
static const IntType description
Description of type.
Definition int-type.hpp:132
static const unsigned short int max
Maximal value.
Definition int-type.hpp:130
signed short int stype
Corresponding signed type.
Definition int-type.hpp:126
Traits to for information about integer types.
Definition int-type.hpp:72
Support algorithms and datastructures
std::make_unsigned_t< ptrdiff_t > uptrint_t
Unsigned integer for pointer encodings.
Definition int-type.hpp:53
IntType u_type(unsigned int n)
Return type required to represent n.
Definition int-type.hpp:167
IntType s_type(signed int n)
Return type required to represent n.
IntType
Description of integer types.
Definition int-type.hpp:59
@ IT_CHAR
char integer type
Definition int-type.hpp:60
@ IT_INT
integer type
Definition int-type.hpp:62
@ IT_SHRT
short integer type
Definition int-type.hpp:61
Gecode toplevel namespace
#define forceinline
Definition config.hpp:144