main page
modules
namespaces
classes
files
Gecode home
Generated on Wed Jan 1 2020 10:37:59 for Gecode by
doxygen
1.8.16
gecode
support
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
36
namespace
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
};
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
};
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
};
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;
112
static
const
IntType
description =
IT_SHRT
;
113
};
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
};
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
146
forceinline
IntType
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
156
forceinline
IntType
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
Gecode::Support::IntTypeTraits< signed char >::utype
unsigned char utype
Corresponding unsigned type.
Definition:
int-type.hpp:59
Gecode::Support::IntTypeTraits< unsigned int >::stype
signed int stype
Corresponding signed type.
Definition:
int-type.hpp:136
Gecode::Support::IT_SHRT
short integer type
Definition:
int-type.hpp:41
Gecode::Support::IntTypeTraits< unsigned int >::utype
unsigned int utype
Corresponding unsigned type.
Definition:
int-type.hpp:134
Gecode::max
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition:
arithmetic.cpp:49
Gecode::Support::IntTypeTraits< signed short int >::stype
signed short int stype
Corresponding signed type.
Definition:
int-type.hpp:91
Gecode::Support::IntTypeTraits< unsigned char >::stype
signed char stype
Corresponding signed type.
Definition:
int-type.hpp:76
Gecode
Gecode toplevel namespace
Gecode::Support::IntTypeTraits< unsigned char >::utype
unsigned char utype
Corresponding unsigned type.
Definition:
int-type.hpp:74
Gecode::Support::u_type
IntType u_type(unsigned int n)
Return type required to represent n.
Definition:
int-type.hpp:147
Gecode::Support::IntTypeTraits< signed int >::utype
unsigned int utype
Corresponding unsigned type.
Definition:
int-type.hpp:119
Gecode::Support::IntTypeTraits
Traits to for information about integer types.
Definition:
int-type.hpp:52
Gecode::Support::IT_CHAR
char integer type
Definition:
int-type.hpp:40
Gecode::Support::IntType
IntType
Description of integer types.
Definition:
int-type.hpp:39
Gecode::Support::IntTypeTraits< signed char >::stype
signed char stype
Corresponding signed type.
Definition:
int-type.hpp:61
Gecode::Support::IntTypeTraits< unsigned short int >::utype
unsigned short int utype
Corresponding unsigned type.
Definition:
int-type.hpp:104
Gecode::Support::IntTypeTraits< signed short int >::utype
unsigned short int utype
Corresponding unsigned type.
Definition:
int-type.hpp:89
Gecode::Support::IntTypeTraits< signed int >::stype
signed int stype
Corresponding signed type.
Definition:
int-type.hpp:121
forceinline
#define forceinline
Definition:
config.hpp:185
Gecode::Support::IntTypeTraits< unsigned short int >::stype
signed short int stype
Corresponding signed type.
Definition:
int-type.hpp:106
Gecode::min
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition:
arithmetic.cpp:67
Gecode::Support::s_type
IntType s_type(signed int n)
Return type required to represent n.
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:234
Gecode::Support::IT_INT
integer type
Definition:
int-type.hpp:42