Generated on Tue May 22 09:40:17 2018 for Gecode by doxygen 1.6.3

int-type.hpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christian Schulte <schulte@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Christian Schulte, 2008
00008  *
00009  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  *  Permission is hereby granted, free of charge, to any person obtaining
00014  *  a copy of this software and associated documentation files (the
00015  *  "Software"), to deal in the Software without restriction, including
00016  *  without limitation the rights to use, copy, modify, merge, publish,
00017  *  distribute, sublicense, and/or sell copies of the Software, and to
00018  *  permit persons to whom the Software is furnished to do so, subject to
00019  *  the following conditions:
00020  *
00021  *  The above copyright notice and this permission notice shall be
00022  *  included in all copies or substantial portions of the Software.
00023  *
00024  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00029  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00030  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00031  *
00032  */
00033 
00034 #include <climits>
00035 
00036 namespace Gecode { namespace Support {
00037 
00039   enum IntType {
00040     IT_CHAR = 0, 
00041     IT_SHRT = 1, 
00042     IT_INT  = 2  
00043   };
00044 
00046   IntType u_type(unsigned int n);
00048   IntType s_type(signed int n);
00049 
00051   template<class IntType>
00052   class IntTypeTraits {};
00053 
00055   template<>
00056   class IntTypeTraits<signed char> {
00057   public:
00059     typedef unsigned char utype;
00061     typedef signed char stype;
00063     static const signed char min = SCHAR_MIN;
00065     static const signed char max = SCHAR_MAX;
00067     static const IntType description = IT_CHAR;
00068   };
00070   template<>
00071   class IntTypeTraits<unsigned char> {
00072   public:
00074     typedef unsigned char utype;
00076     typedef signed char stype;
00078     static const unsigned char min = 0;
00080     static const unsigned char max = UCHAR_MAX;
00082     static const IntType description = IT_CHAR;
00083   };
00085   template<>
00086   class IntTypeTraits<signed short int> {
00087   public:
00089     typedef unsigned short int utype;
00091     typedef signed short int stype;
00093     static const signed short int min = SHRT_MIN;
00095     static const signed short int max = SHRT_MAX;
00097     static const IntType description = IT_SHRT;
00098   };
00100   template<>
00101   class IntTypeTraits<unsigned short int> {
00102   public:
00104     typedef unsigned short int utype;
00106     typedef signed short int stype;
00108     static const unsigned short int min = 0;
00110     static const unsigned short int max = USHRT_MAX;
00112     static const IntType description = IT_SHRT;
00113   };
00115   template<>
00116   class IntTypeTraits<signed int> {
00117   public:
00119     typedef unsigned int utype;
00121     typedef signed int stype;
00123     static const signed int min = INT_MIN;
00125     static const signed int max = INT_MAX;
00127     static const IntType description = IT_INT;
00128   };
00130   template<>
00131   class IntTypeTraits<unsigned int> {
00132   public:
00134     typedef unsigned int utype;
00136     typedef signed int stype;
00138     static const unsigned int min = 0;
00140     static const unsigned int max = UINT_MAX;
00142     static const IntType description = IT_INT;
00143   };
00144 
00145 
00146   forceinline IntType
00147   u_type(unsigned int n) {
00148     if (n < UCHAR_MAX)
00149       return IT_CHAR;
00150     else if (n < USHRT_MAX)
00151       return IT_SHRT;
00152     else
00153       return IT_INT;
00154   }
00155 
00156   forceinline IntType
00157   s_type(int n) {
00158     if ((n > SCHAR_MIN) && (n < SCHAR_MAX))
00159       return IT_CHAR;
00160     else if ((n > SHRT_MIN) && (n < SHRT_MAX))
00161       return IT_SHRT;
00162     else
00163       return IT_INT;
00164   }
00165 
00166 }}
00167 
00168 // STATISTICS: support-any