Generated on Sat Feb 7 2015 02:01:31 for Gecode by doxygen 1.8.9.1
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  * Last modified:
10  * $Date: 2010-01-26 13:22:47 +0100 (Tue, 26 Jan 2010) $ by $Author: schulte $
11  * $Revision: 10238 $
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
38 #include <climits>
39 
40 namespace Gecode { namespace Support {
41 
43  enum IntType {
44  IT_CHAR = 0,
45  IT_SHRT = 1,
46  IT_INT = 2
47  };
48 
50  IntType u_type(unsigned int n);
52  IntType s_type(signed int n);
53 
55  template<class IntType>
56  class IntTypeTraits {};
57 
59  template<>
60  class IntTypeTraits<signed char> {
61  public:
63  typedef unsigned char utype;
65  typedef signed char stype;
67  static const signed char min = SCHAR_MIN;
69  static const signed char max = SCHAR_MAX;
71  static const IntType description = IT_CHAR;
72  };
74  template<>
75  class IntTypeTraits<unsigned char> {
76  public:
78  typedef unsigned char utype;
80  typedef signed char stype;
82  static const unsigned char min = 0;
84  static const unsigned char max = UCHAR_MAX;
86  static const IntType description = IT_CHAR;
87  };
89  template<>
90  class IntTypeTraits<signed short int> {
91  public:
93  typedef unsigned short int utype;
95  typedef signed short int stype;
97  static const signed short int min = SHRT_MIN;
99  static const signed short int max = SHRT_MAX;
101  static const IntType description = IT_SHRT;
102  };
104  template<>
105  class IntTypeTraits<unsigned short int> {
106  public:
108  typedef unsigned short int utype;
110  typedef signed short int stype;
112  static const unsigned short int min = 0;
114  static const unsigned short int max = USHRT_MAX;
116  static const IntType description = IT_SHRT;
117  };
119  template<>
120  class IntTypeTraits<signed int> {
121  public:
123  typedef unsigned int utype;
125  typedef signed int stype;
127  static const signed int min = INT_MIN;
129  static const signed int max = INT_MAX;
131  static const IntType description = IT_INT;
132  };
134  template<>
135  class IntTypeTraits<unsigned int> {
136  public:
138  typedef unsigned int utype;
140  typedef signed int stype;
142  static const unsigned int min = 0;
144  static const unsigned int max = UINT_MAX;
146  static const IntType description = IT_INT;
147  };
148 
149 
151  u_type(unsigned int n) {
152  if (n < UCHAR_MAX)
153  return IT_CHAR;
154  else if (n < USHRT_MAX)
155  return IT_SHRT;
156  else
157  return IT_INT;
158  }
159 
161  s_type(int n) {
162  if ((n > SCHAR_MIN) && (n < SCHAR_MAX))
163  return IT_CHAR;
164  else if ((n > SHRT_MIN) && (n < SHRT_MAX))
165  return IT_SHRT;
166  else
167  return IT_INT;
168  }
169 
170 }}
171 
172 // STATISTICS: support-any
signed char stype
Corresponding signed type.
Definition: int-type.hpp:80
unsigned short int utype
Corresponding unsigned type.
Definition: int-type.hpp:108
signed char stype
Corresponding signed type.
Definition: int-type.hpp:65
unsigned short int utype
Corresponding unsigned type.
Definition: int-type.hpp:93
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:57
IntType u_type(unsigned int n)
Return type required to represent n.
Definition: int-type.hpp:151
unsigned int utype
Corresponding unsigned type.
Definition: int-type.hpp:123
IntType s_type(signed int n)
Return type required to represent n.
char integer type
Definition: int-type.hpp:44
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
signed short int stype
Corresponding signed type.
Definition: int-type.hpp:110
unsigned char utype
Corresponding unsigned type.
Definition: int-type.hpp:78
Traits to for information about integer types.
Definition: int-type.hpp:56
signed int stype
Corresponding signed type.
Definition: int-type.hpp:140
unsigned int utype
Corresponding unsigned type.
Definition: int-type.hpp:138
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:75
unsigned char utype
Corresponding unsigned type.
Definition: int-type.hpp:63
signed int stype
Corresponding signed type.
Definition: int-type.hpp:125
#define forceinline
Definition: config.hpp:132
signed short int stype
Corresponding signed type.
Definition: int-type.hpp:95
Gecode toplevel namespace
IntType
Description of integer types.
Definition: int-type.hpp:43
short integer type
Definition: int-type.hpp:45