main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Jan 28 2020 00:00:00 for Gecode by
doxygen
1.8.17
gecode
kernel
archive.hpp
Go to the documentation of this file.
1
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
/*
3
* Main authors:
4
* Guido Tack <tack@gecode.org>
5
*
6
* Copyright:
7
* Guido Tack, 2011
8
*
9
* Last modified:
10
* $Date: 2016-06-17 15:43:08 +0200 (Fri, 17 Jun 2016) $ by $Author: schulte $
11
* $Revision: 15116 $
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
namespace
Gecode
{
45
class
Archive
{
46
private
:
48
int
_size;
50
int
_n;
52
unsigned
int
* _a;
54
int
_pos;
56
GECODE_KERNEL_EXPORT
void
resize(
int
n
);
57
public
:
59
Archive
(
void
);
61
GECODE_KERNEL_EXPORT
~Archive
(
void
);
63
GECODE_KERNEL_EXPORT
Archive
(
const
Archive
& e);
65
GECODE_KERNEL_EXPORT
Archive
&
operator =
(
const
Archive
& e);
67
void
put
(
unsigned
int
i
);
69
int
size
(
void
)
const
;
71
unsigned
int
operator []
(
int
i
)
const
;
73
unsigned
int
get
(
void
);
74
};
75
79
Archive
&
80
operator <<
(
Archive
& e,
unsigned
int
i
);
84
Archive
&
85
operator <<
(
Archive
& e,
int
i
);
89
Archive
&
90
operator <<
(
Archive
& e,
unsigned
short
i
);
94
Archive
&
95
operator <<
(
Archive
& e,
short
i
);
99
Archive
&
100
operator <<
(
Archive
& e,
unsigned
char
i
);
104
Archive
&
105
operator <<
(
Archive
& e,
char
i
);
109
Archive
&
110
operator <<
(
Archive
& e,
bool
i
);
114
Archive
&
115
operator <<
(
Archive
& e,
float
d
);
119
Archive
&
120
operator <<
(
Archive
& e,
double
d
);
121
125
Archive
&
126
operator >>
(
Archive
& e,
unsigned
int
&
i
);
130
Archive
&
131
operator >>
(
Archive
& e,
int
&
i
);
135
Archive
&
136
operator >>
(
Archive
& e,
unsigned
short
&
i
);
140
Archive
&
141
operator >>
(
Archive
& e,
short
&
i
);
145
Archive
&
146
operator >>
(
Archive
& e,
unsigned
char
&
i
);
150
Archive
&
151
operator >>
(
Archive
& e,
char
&
i
);
155
Archive
&
156
operator >>
(
Archive
& e,
bool
&
i
);
160
Archive
&
161
operator >>
(
Archive
& e,
float
&
d
);
165
Archive
&
166
operator >>
(
Archive
& e,
double
&
d
);
167
168
/*
169
* Implementation
170
*
171
*/
172
173
forceinline
174
Archive::Archive
(
void
) : _size(0), _n(0),
_a
(NULL), _pos(0) {}
175
176
forceinline
void
177
Archive::put
(
unsigned
int
i
) {
178
if
(_n==_size)
179
resize(_n+1);
180
_a[_n++] =
i
;
181
}
182
183
forceinline
int
184
Archive::size
(
void
)
const
{
return
_n; }
185
186
forceinline
unsigned
int
187
Archive::operator []
(
int
i
)
const
{
188
assert(
i
< _n);
189
return
_a[
i
];
190
}
191
192
forceinline
unsigned
int
193
Archive::get
(
void
) {
194
assert(_pos < _n);
195
return
_a[_pos++];
196
}
197
198
forceinline
Archive
&
199
operator <<
(
Archive
& e,
unsigned
int
i
) {
200
e.
put
(
i
);
201
return
e;
202
}
203
forceinline
Archive&
204
operator <<
(
Archive
& e,
int
i
) {
205
e.
put
(
static_cast<
unsigned
int
>
(
i
));
206
return
e;
207
}
208
forceinline
Archive&
209
operator <<
(
Archive
& e,
unsigned
short
i
) {
210
e.
put
(
i
);
211
return
e;
212
}
213
forceinline
Archive&
214
operator <<
(
Archive
& e,
short
i
) {
215
e.
put
(
static_cast<
unsigned
int
>
(
i
));
216
return
e;
217
}
218
forceinline
Archive&
219
operator <<
(
Archive
& e,
unsigned
char
i
) {
220
e.
put
(
i
);
221
return
e;
222
}
223
forceinline
Archive&
224
operator <<
(
Archive
& e,
char
i
) {
225
e.
put
(
static_cast<
unsigned
int
>
(
i
));
226
return
e;
227
}
228
forceinline
Archive&
229
operator <<
(
Archive
& e,
bool
i
) {
230
e.
put
(
static_cast<
unsigned
int
>
(
i
));
231
return
e;
232
}
233
forceinline
Archive&
234
operator <<
(
Archive
& e,
float
d
) {
235
for
(
size_t
i
=0;
i
<
sizeof
(float);
i
++)
236
e.
put
(
static_cast<
unsigned
int
>
(
reinterpret_cast<
char
*
>
(&
d
)[
i
]));
237
return
e;
238
}
239
forceinline
Archive&
240
operator <<
(
Archive
& e,
double
d
) {
241
for
(
size_t
i
=0;
i
<
sizeof
(double);
i
++)
242
e.
put
(
static_cast<
unsigned
int
>
(
reinterpret_cast<
char
*
>
(&
d
)[
i
]));
243
return
e;
244
}
245
246
forceinline
Archive&
247
operator >>
(
Archive
& e,
unsigned
int
&
i
) {
248
i
= e.
get
();
249
return
e;
250
}
251
forceinline
Archive&
252
operator >>
(
Archive
& e,
int
&
i
) {
253
i
=
static_cast<
int
>
(e.
get
());
254
return
e;
255
}
256
forceinline
Archive&
257
operator >>
(
Archive
& e,
unsigned
short
&
i
) {
258
i
=
static_cast<
unsigned
short
>
(e.
get
());
259
return
e;
260
}
261
forceinline
Archive&
262
operator >>
(
Archive
& e,
short
&
i
) {
263
i
=
static_cast<
short
>
(e.
get
());
264
return
e;
265
}
266
forceinline
Archive&
267
operator >>
(
Archive
& e,
unsigned
char
&
i
) {
268
i
=
static_cast<
unsigned
char
>
(e.
get
());
269
return
e;
270
}
271
forceinline
Archive&
272
operator >>
(
Archive
& e,
char
&
i
) {
273
i
=
static_cast<
char
>
(e.
get
());
274
return
e;
275
}
276
forceinline
Archive&
277
operator >>
(
Archive
& e,
bool
&
i
) {
278
i
= (e.
get
() != 0);
279
return
e;
280
}
281
forceinline
Archive&
282
operator >>
(
Archive
& e,
float
&
d
) {
283
char
* cd =
reinterpret_cast<
char
*
>
(&
d
);
284
for
(
size_t
i
=0;
i
<
sizeof
(float);
i
++)
285
cd[
i
] =
static_cast<
char
>
(e.
get
());
286
return
e;
287
}
288
forceinline
Archive&
289
operator >>
(
Archive
& e,
double
&
d
) {
290
char
* cd =
reinterpret_cast<
char
*
>
(&
d
);
291
for
(
size_t
i
=0;
i
<
sizeof
(double);
i
++)
292
cd[
i
] =
static_cast<
char
>
(e.
get
());
293
return
e;
294
}
295
296
}
297
298
// STATISTICS: kernel-branch
Gecode::Archive::operator=
Archive & operator=(const Archive &e)
Assignment operator.
Definition:
archive.cpp:55
forceinline
#define forceinline
Definition:
config.hpp:173
Gecode::Archive::put
void put(unsigned int i)
Add i to the contents.
Definition:
archive.hpp:177
Gecode::operator>>
Archive & operator>>(Archive &e, FloatNumBranch &nl)
Definition:
val-sel.hpp:48
Test::Int::Precede::_a
Single _a(2, 3)
Test::Int::Basic::i
Gecode::IntArgs i(4, 1, 2, 3, 4)
Gecode::Archive
Archive representation
Definition:
archive.hpp:45
Gecode::Archive::~Archive
~Archive(void)
Destructor.
Definition:
archive.cpp:64
Gecode::Archive::operator[]
unsigned int operator[](int i) const
Return array element i.
Definition:
archive.hpp:187
Gecode::Archive::get
unsigned int get(void)
Return next element to read.
Definition:
archive.hpp:193
Gecode
Gecode toplevel namespace
Gecode::Archive::size
int size(void) const
Return size.
Definition:
archive.hpp:184
GECODE_KERNEL_EXPORT
#define GECODE_KERNEL_EXPORT
Definition:
kernel.hh:74
Gecode::Archive::Archive
Archive(void)
Construct empty representation.
Definition:
archive.hpp:174
Test::Int::Distinct::d
Gecode::IntSet d(v, 7)
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:238
Gecode::operator<<
Archive & operator<<(Archive &e, FloatNumBranch nl)
Definition:
val-sel.hpp:43