Generated on Thu Jan 16 2025 00:00:00 for Gecode by doxygen 1.14.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.org>
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.org
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
36namespace Gecode { namespace Support {
37
39 enum IntType {
40 IT_CHAR = 0,
41 IT_SHRT = 1,
42 IT_INT = 2
43 };
44
46 IntType u_type(unsigned int n);
48 IntType s_type(signed int n);
49
51 template<class IntType>
52 class IntTypeTraits {};
53
55 template<>
56 class IntTypeTraits<signed char> {
57 public:
59 typedef unsigned char utype;
61 typedef signed char stype;
63 static const signed char min = SCHAR_MIN;
65 static const signed char max = SCHAR_MAX;
67 static const IntType description = IT_CHAR;
68 };
69
70 template<>
71 class IntTypeTraits<unsigned char> {
72 public:
74 typedef unsigned char utype;
76 typedef signed char stype;
78 static const unsigned char min = 0;
80 static const unsigned char max = UCHAR_MAX;
82 static const IntType description = IT_CHAR;
83 };
84
85 template<>
86 class IntTypeTraits<signed short int> {
87 public:
89 typedef unsigned short int utype;
91 typedef signed short int stype;
93 static const signed short int min = SHRT_MIN;
95 static const signed short int max = SHRT_MAX;
97 static const IntType description = IT_SHRT;
98 };
99
100 template<>
101 class IntTypeTraits<unsigned short int> {
102 public:
104 typedef unsigned short int utype;
106 typedef signed short int stype;
108 static const unsigned short int min = 0;
110 static const unsigned short int max = USHRT_MAX;
113 };
114
115 template<>
116 class IntTypeTraits<signed int> {
117 public:
119 typedef unsigned int utype;
121 typedef signed int stype;
123 static const signed int min = INT_MIN;
125 static const signed int max = INT_MAX;
127 static const IntType description = IT_INT;
128 };
129
130 template<>
131 class IntTypeTraits<unsigned int> {
132 public:
134 typedef unsigned int utype;
136 typedef signed int stype;
138 static const unsigned int min = 0;
140 static const unsigned int max = UINT_MAX;
142 static const IntType description = IT_INT;
143 };
144
145
147 u_type(unsigned int n) {
148 if (n < UCHAR_MAX)
149 return IT_CHAR;
150 else if (n < USHRT_MAX)
151 return IT_SHRT;
152 else
153 return IT_INT;
154 }
155
157 s_type(int n) {
158 if ((n > SCHAR_MIN) && (n < SCHAR_MAX))
159 return IT_CHAR;
160 else if ((n > SHRT_MIN) && (n < SHRT_MAX))
161 return IT_SHRT;
162 else
163 return IT_INT;
164 }
165
166}}
167
168// STATISTICS: support-any
signed char stype
Corresponding signed type.
Definition int-type.hpp:61
static const signed char max
Maximal value.
Definition int-type.hpp:65
static const signed char min
Minimal value.
Definition int-type.hpp:63
unsigned char utype
Corresponding unsigned type.
Definition int-type.hpp:59
static const IntType description
Description of type.
Definition int-type.hpp:67
static const signed int max
Maximal value.
Definition int-type.hpp:125
static const IntType description
Description of type.
Definition int-type.hpp:127
signed int stype
Corresponding signed type.
Definition int-type.hpp:121
static const signed int min
Minimal value.
Definition int-type.hpp:123
unsigned int utype
Corresponding unsigned type.
Definition int-type.hpp:119
static const signed short int max
Maximal value.
Definition int-type.hpp:95
static const IntType description
Description of type.
Definition int-type.hpp:97
signed short int stype
Corresponding signed type.
Definition int-type.hpp:91
unsigned short int utype
Corresponding unsigned type.
Definition int-type.hpp:89
static const signed short int min
Minimal value.
Definition int-type.hpp:93
static const IntType description
Description of type.
Definition int-type.hpp:82
static const unsigned char max
Maximal value.
Definition int-type.hpp:80
static const unsigned char min
Minimal value.
Definition int-type.hpp:78
unsigned char utype
Corresponding unsigned type.
Definition int-type.hpp:74
signed char stype
Corresponding signed type.
Definition int-type.hpp:76
static const unsigned int max
Maximal value.
Definition int-type.hpp:140
signed int stype
Corresponding signed type.
Definition int-type.hpp:136
static const unsigned int min
Minimal value.
Definition int-type.hpp:138
static const IntType description
Description of type.
Definition int-type.hpp:142
unsigned int utype
Corresponding unsigned type.
Definition int-type.hpp:134
static const unsigned short int min
Minimal value.
Definition int-type.hpp:108
unsigned short int utype
Corresponding unsigned type.
Definition int-type.hpp:104
static const IntType description
Description of type.
Definition int-type.hpp:112
static const unsigned short int max
Maximal value.
Definition int-type.hpp:110
signed short int stype
Corresponding signed type.
Definition int-type.hpp:106
Traits to for information about integer types.
Definition int-type.hpp:52
Support algorithms and datastructures
IntType u_type(unsigned int n)
Return type required to represent n.
Definition int-type.hpp:147
IntType s_type(signed int n)
Return type required to represent n.
IntType
Description of integer types.
Definition int-type.hpp:39
@ IT_CHAR
char integer type
Definition int-type.hpp:40
@ IT_INT
integer type
Definition int-type.hpp:42
@ IT_SHRT
short integer type
Definition int-type.hpp:41
Gecode toplevel namespace
#define forceinline
Definition config.hpp:194