$extrastylesheet
Olena
User documentation 2.1
An Image Processing Platform
Milena
Getting started
API Reference Manual
All Classes
Examples
Demos
Publications
All
Classes
Namespaces
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
limits.hh
1
// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE)
2
//
3
// This file is part of Olena.
4
//
5
// Olena is free software: you can redistribute it and/or modify it under
6
// the terms of the GNU General Public License as published by the Free
7
// Software Foundation, version 2 of the License.
8
//
9
// Olena is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
// General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Olena. If not, see <http://www.gnu.org/licenses/>.
16
//
17
// As a special exception, you may use this file as part of a free
18
// software project without restriction. Specifically, if other files
19
// instantiate templates or use macros or inline functions from this
20
// file, or you compile this file and link it with other files to produce
21
// an executable, this file does not by itself cause the resulting
22
// executable to be covered by the GNU General Public License. This
23
// exception does not however invalidate any other reasons why the
24
// executable file might be covered by the GNU General Public License.
25
26
#ifndef MLN_VALUE_INTERNAL_LIMITS_HH
27
# define MLN_VALUE_INTERNAL_LIMITS_HH
28
32
33
# if defined(__GNUC__) && __GNUC__ < 3
34
# include <cfloat>
35
# include <climits>
36
# else
37
# include <limits>
38
# endif
39
40
namespace
mln
41
{
42
43
namespace
value
44
{
45
46
namespace
internal
47
{
48
49
template
<
typename
T>
50
struct
limits
51
# if !defined(__GNUC__) || __GNUC__ >= 3
52
: std::numeric_limits<T>
53
{ };
54
# else
55
{
56
static
const
bool
is_specialized =
false
;
57
};
58
59
template
<>
60
struct
limits<
bool
>
61
{
62
static
bool
min
() throw() {
return
false
; }
63
static
bool
max
() throw() {
return
false
; }
64
static
bool
epsilon() throw()
65
{
return
false
; }
66
};
67
68
template
<>
69
struct
limits<char>
70
{
71
static
char
min
() throw() {
return
CHAR_MIN; }
72
static
char
max
() throw() {
return
CHAR_MAX; }
73
static
char
epsilon() throw()
74
{
return
0; }
75
};
76
77
template
<>
78
struct
limits<signed char>
79
{
80
static
signed
char
min
() throw() {
return
SCHAR_MIN; }
81
static
signed
char
max
() throw() {
return
SCHAR_MAX; }
82
static
signed
char
epsilon() throw()
83
{
return
0; }
84
};
85
86
template
<>
87
struct
limits<
unsigned
char>
88
{
89
static
unsigned
char
min
() throw() {
return
0; }
90
static
unsigned
char
max
() throw() {
return
UCHAR_MAX; }
91
static
unsigned
char
epsilon() throw()
92
{
return
0; }
93
};
94
95
template
<>
96
struct
limits<short>
97
{
98
static
short
min
() throw() {
return
SHRT_MIN; }
99
static
short
max
() throw() {
return
SHRT_MAX; }
100
static
short
epsilon() throw()
101
{
return
0; }
102
};
103
104
template
<>
105
struct
limits<
unsigned
short>
106
{
107
static
unsigned
short
min
() throw() {
return
0; }
108
static
unsigned
short
max
() throw() {
return
USHRT_MAX; }
109
static
unsigned
short
epsilon() throw()
110
{
return
0; }
111
};
112
113
template
<>
114
struct
limits<
int
>
115
{
116
static
int
min
() throw() {
return
INT_MIN; }
117
static
int
max
() throw() {
return
INT_MAX; }
118
static
int
epsilon() throw()
119
{
return
0; }
120
};
121
122
template
<>
123
struct
limits<
unsigned
int
>
124
{
125
static
unsigned
int
min
() throw() {
return
0; }
126
static
unsigned
int
max
() throw() {
return
UINT_MAX; }
127
static
unsigned
int
epsilon() throw()
128
{
return
0; }
129
};
130
131
template
<>
132
struct
limits<long>
133
{
134
static
long
min
() throw() {
return
LONG_MIN; }
135
static
long
max
() throw() {
return
LONG_MAX; }
136
static
long
epsilon() throw()
137
{
return
0; }
138
};
139
140
template
<>
141
struct
limits<
unsigned
long>
142
{
143
static
unsigned
long
min
() throw() {
return
0; }
144
static
unsigned
long
max
() throw() {
return
ULONG_MAX; }
145
static
unsigned
long
epsilon() throw()
146
{
return
0; }
147
};
148
149
150
/*
151
** Some pre-ANSI-C99 systems like Linux/GCC 2.95 define
152
** ULONGLONG_MAX, LONGLONG_MIN, LONGLONG_MAX; we use them if they're defined.
153
*/
154
155
# if defined(HAVE_LONG_LONG) && !defined(LONGLONG_MIN)
156
# define LONGLONG_MIN((long long) 0x8000000000000000LL)
157
# define LONGLONG_MAX((long long) 0x7FFFFFFFFFFFFFFFLL)
158
# endif
159
160
161
# if defined(HAVE_LONG_LONG) && !defined(ULONGLONG_MAX)
162
/* First check for ANSI C99 definition: */
163
# ifdef ULLONG_MAX
164
# define ULONGLONG_MAX ULLONG_MAX
165
# else
166
# define ULONGLONG_MAX ((unsigned long long)(~0ULL))
167
# endif
168
169
# endif
/* defined (HAVE_LONG_LONG) && !defined(ULONGLONG_MAX)*/
170
171
172
# if defined(HAVE_LONG_LONG)
173
template
<>
174
struct
limits<long long>
175
{
176
static
long
long
min
() throw() {
return
LONGLONG_MIN; }
177
static
long
long
max
() throw() {
return
LONGLONG_MAX; }
178
static
long
long
epsilon() throw()
179
{
return
0; }
180
};
181
182
template
<>
183
struct
limits<
unsigned
long long>
184
{
185
static
unsigned
long
long
min
() throw() {
return
0; }
186
static
unsigned
long
long
max
() throw() {
return
ULONGLONG_MAX; }
187
static
unsigned
long
long
epsilon() throw()
188
{
return
0; }
189
};
190
# endif
191
192
template
<>
193
struct
limits<
float
>
194
{
195
static
float
min
() throw() {
return
FLT_MIN; }
196
static
float
max
() throw() {
return
FLT_MAX; }
197
static
float
epsilon() throw()
198
{
return
FLT_EPSILON; }
199
};
200
201
template
<>
202
struct
limits<
double
>
203
{
204
static
float
min
() throw() {
return
DBL_MIN; }
205
static
float
max
() throw() {
return
DBL_MAX; }
206
static
float
epsilon() throw()
207
{
return
DBL_EPSILON; }
208
};
209
210
# endif
211
}
// end of namespace mln::value::internal
212
213
}
// end of namespace mln::value
214
215
}
// end of namespace mln
216
217
#endif // ! MLN_VALUE_INTERNAL_LIMITS_HH
mln
value
internal
limits.hh
Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)