int-type.hpp
Go to the documentation of this file.
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Christian Schulte <schulte@gecode.org>
*
* Copyright:
* Christian Schulte, 2008
*
* This file is part of Gecode, the generic constraint
* development environment:
* http://www.gecode.org
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include <climits>
namespace Gecode { namespace Support {
enum IntType {
IT_CHAR = 0,
IT_SHRT = 1,
IT_INT = 2
};
IntType u_type(unsigned int n);
IntType s_type(signed int n);
template<class IntType>
class IntTypeTraits {};
template<>
class IntTypeTraits<signed char> {
public:
typedef unsigned char utype;
typedef signed char stype;
static const signed char min = SCHAR_MIN;
static const signed char max = SCHAR_MAX;
static const IntType description = IT_CHAR;
};
template<>
class IntTypeTraits<unsigned char> {
public:
typedef unsigned char utype;
typedef signed char stype;
static const unsigned char min = 0;
static const unsigned char max = UCHAR_MAX;
static const IntType description = IT_CHAR;
};
template<>
class IntTypeTraits<signed short int> {
public:
typedef unsigned short int utype;
typedef signed short int stype;
static const signed short int min = SHRT_MIN;
static const signed short int max = SHRT_MAX;
static const IntType description = IT_SHRT;
};
template<>
class IntTypeTraits<unsigned short int> {
public:
typedef unsigned short int utype;
typedef signed short int stype;
static const unsigned short int min = 0;
static const unsigned short int max = USHRT_MAX;
static const IntType description = IT_SHRT;
};
template<>
class IntTypeTraits<signed int> {
public:
typedef unsigned int utype;
typedef signed int stype;
static const signed int min = INT_MIN;
static const signed int max = INT_MAX;
static const IntType description = IT_INT;
};
template<>
class IntTypeTraits<unsigned int> {
public:
typedef unsigned int utype;
typedef signed int stype;
static const unsigned int min = 0;
static const unsigned int max = UINT_MAX;
static const IntType description = IT_INT;
};
forceinline IntType
u_type(unsigned int n) {
if (n < UCHAR_MAX)
return IT_CHAR;
else if (n < USHRT_MAX)
return IT_SHRT;
else
return IT_INT;
}
forceinline IntType
s_type(int n) {
if ((n > SCHAR_MIN) && (n < SCHAR_MAX))
return IT_CHAR;
else if ((n > SHRT_MIN) && (n < SHRT_MAX))
return IT_SHRT;
else
return IT_INT;
}
}}
// STATISTICS: support-any
Gecode::Support::IntTypeTraits< signed char >::stype
signed char stype
Corresponding signed type.
Definition int-type.hpp:61
Gecode::Support::IntTypeTraits< signed char >::max
static const signed char max
Maximal value.
Definition int-type.hpp:65
Gecode::Support::IntTypeTraits< signed char >::min
static const signed char min
Minimal value.
Definition int-type.hpp:63
Gecode::Support::IntTypeTraits< signed char >::utype
unsigned char utype
Corresponding unsigned type.
Definition int-type.hpp:59
Gecode::Support::IntTypeTraits< signed char >::description
static const IntType description
Description of type.
Definition int-type.hpp:67
Gecode::Support::IntTypeTraits< signed int >::max
static const signed int max
Maximal value.
Definition int-type.hpp:125
Gecode::Support::IntTypeTraits< signed int >::description
static const IntType description
Description of type.
Definition int-type.hpp:127
Gecode::Support::IntTypeTraits< signed int >::stype
signed int stype
Corresponding signed type.
Definition int-type.hpp:121
Gecode::Support::IntTypeTraits< signed int >::min
static const signed int min
Minimal value.
Definition int-type.hpp:123
Gecode::Support::IntTypeTraits< signed int >::utype
unsigned int utype
Corresponding unsigned type.
Definition int-type.hpp:119
Gecode::Support::IntTypeTraits< signed short int >::max
static const signed short int max
Maximal value.
Definition int-type.hpp:95
Gecode::Support::IntTypeTraits< signed short int >::description
static const IntType description
Description of type.
Definition int-type.hpp:97
Gecode::Support::IntTypeTraits< signed short int >::stype
signed short int stype
Corresponding signed type.
Definition int-type.hpp:91
Gecode::Support::IntTypeTraits< signed short int >::utype
unsigned short int utype
Corresponding unsigned type.
Definition int-type.hpp:89
Gecode::Support::IntTypeTraits< signed short int >::min
static const signed short int min
Minimal value.
Definition int-type.hpp:93
Gecode::Support::IntTypeTraits< unsigned char >::description
static const IntType description
Description of type.
Definition int-type.hpp:82
Gecode::Support::IntTypeTraits< unsigned char >::max
static const unsigned char max
Maximal value.
Definition int-type.hpp:80
Gecode::Support::IntTypeTraits< unsigned char >::min
static const unsigned char min
Minimal value.
Definition int-type.hpp:78
Gecode::Support::IntTypeTraits< unsigned char >::utype
unsigned char utype
Corresponding unsigned type.
Definition int-type.hpp:74
Gecode::Support::IntTypeTraits< unsigned char >::stype
signed char stype
Corresponding signed type.
Definition int-type.hpp:76
Gecode::Support::IntTypeTraits< unsigned int >::max
static const unsigned int max
Maximal value.
Definition int-type.hpp:140
Gecode::Support::IntTypeTraits< unsigned int >::stype
signed int stype
Corresponding signed type.
Definition int-type.hpp:136
Gecode::Support::IntTypeTraits< unsigned int >::min
static const unsigned int min
Minimal value.
Definition int-type.hpp:138
Gecode::Support::IntTypeTraits< unsigned int >::description
static const IntType description
Description of type.
Definition int-type.hpp:142
Gecode::Support::IntTypeTraits< unsigned int >::utype
unsigned int utype
Corresponding unsigned type.
Definition int-type.hpp:134
Gecode::Support::IntTypeTraits< unsigned short int >::min
static const unsigned short int min
Minimal value.
Definition int-type.hpp:108
Gecode::Support::IntTypeTraits< unsigned short int >::utype
unsigned short int utype
Corresponding unsigned type.
Definition int-type.hpp:104
Gecode::Support::IntTypeTraits< unsigned short int >::description
static const IntType description
Description of type.
Definition int-type.hpp:112
Gecode::Support::IntTypeTraits< unsigned short int >::max
static const unsigned short int max
Maximal value.
Definition int-type.hpp:110
Gecode::Support::IntTypeTraits< unsigned short int >::stype
signed short int stype
Corresponding signed type.
Definition int-type.hpp:106
Gecode::Support::IntTypeTraits
Traits to for information about integer types.
Definition int-type.hpp:52
Gecode::Support
Support algorithms and datastructures
Gecode::Support::u_type
IntType u_type(unsigned int n)
Return type required to represent n.
Definition int-type.hpp:147
Gecode::Support::s_type
IntType s_type(signed int n)
Return type required to represent n.
Gecode::Support::IntType
IntType
Description of integer types.
Definition int-type.hpp:39
Gecode::Support::IT_CHAR
@ IT_CHAR
char integer type
Definition int-type.hpp:40
Gecode::Support::IT_INT
@ IT_INT
integer type
Definition int-type.hpp:42
Gecode::Support::IT_SHRT
@ IT_SHRT
short integer type
Definition int-type.hpp:41
Gecode
Gecode toplevel namespace
forceinline
#define forceinline
Definition config.hpp:187