main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Mar 24 2020 14:04:04 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
* This file is part of Gecode, the generic constraint
10
* development environment:
11
* http://www.gecode.org
12
*
13
* Permission is hereby granted, free of charge, to any person obtaining
14
* a copy of this software and associated documentation files (the
15
* "Software"), to deal in the Software without restriction, including
16
* without limitation the rights to use, copy, modify, merge, publish,
17
* distribute, sublicense, and/or sell copies of the Software, and to
18
* permit persons to whom the Software is furnished to do so, subject to
19
* the following conditions:
20
*
21
* The above copyright notice and this permission notice shall be
22
* included in all copies or substantial portions of the Software.
23
*
24
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31
*
32
*/
33
34
namespace
Gecode
{
35
42
class
Archive
{
43
private
:
45
int
_size;
47
int
_n;
49
unsigned
int
* _a;
51
int
_pos;
53
GECODE_KERNEL_EXPORT
void
resize(
int
n
);
54
public
:
56
Archive
(
void
);
58
GECODE_KERNEL_EXPORT
~Archive
(
void
);
60
GECODE_KERNEL_EXPORT
Archive
(
const
Archive
& e);
62
GECODE_KERNEL_EXPORT
Archive
&
operator =
(
const
Archive
& e);
64
void
put
(
unsigned
int
i
);
66
int
size
(
void
)
const
;
68
unsigned
int
operator []
(
int
i
)
const
;
70
unsigned
int
get
(
void
);
71
};
72
76
Archive
&
77
operator <<
(
Archive
& e,
unsigned
int
i
);
81
Archive
&
82
operator <<
(
Archive
& e,
int
i
);
86
Archive
&
87
operator <<
(
Archive
& e,
unsigned
short
i
);
91
Archive
&
92
operator <<
(
Archive
& e,
short
i
);
96
Archive
&
97
operator <<
(
Archive
& e,
unsigned
char
i
);
101
Archive
&
102
operator <<
(
Archive
& e,
char
i
);
106
Archive
&
107
operator <<
(
Archive
& e,
bool
i
);
111
Archive
&
112
operator <<
(
Archive
& e,
float
d
);
116
Archive
&
117
operator <<
(
Archive
& e,
double
d
);
118
122
Archive
&
123
operator >>
(
Archive
& e,
unsigned
int
&
i
);
127
Archive
&
128
operator >>
(
Archive
& e,
int
&
i
);
132
Archive
&
133
operator >>
(
Archive
& e,
unsigned
short
&
i
);
137
Archive
&
138
operator >>
(
Archive
& e,
short
&
i
);
142
Archive
&
143
operator >>
(
Archive
& e,
unsigned
char
&
i
);
147
Archive
&
148
operator >>
(
Archive
& e,
char
&
i
);
152
Archive
&
153
operator >>
(
Archive
& e,
bool
&
i
);
157
Archive
&
158
operator >>
(
Archive
& e,
float
&
d
);
162
Archive
&
163
operator >>
(
Archive
& e,
double
&
d
);
164
165
/*
166
* Implementation
167
*
168
*/
169
170
forceinline
171
Archive::Archive
(
void
) : _size(0), _n(0),
_a
(NULL), _pos(0) {}
172
173
forceinline
void
174
Archive::put
(
unsigned
int
i
) {
175
if
(_n==_size)
176
resize(_n+1);
177
_a[_n++] =
i
;
178
}
179
180
forceinline
int
181
Archive::size
(
void
)
const
{
return
_n; }
182
183
forceinline
unsigned
int
184
Archive::operator []
(
int
i
)
const
{
185
assert(
i
< _n);
186
return
_a[
i
];
187
}
188
189
forceinline
unsigned
int
190
Archive::get
(
void
) {
191
assert(_pos < _n);
192
return
_a[_pos++];
193
}
194
195
forceinline
Archive
&
196
operator <<
(
Archive
& e,
unsigned
int
i
) {
197
e.
put
(
i
);
198
return
e;
199
}
200
forceinline
Archive&
201
operator <<
(
Archive
& e,
int
i
) {
202
e.
put
(
static_cast<
unsigned
int
>
(
i
));
203
return
e;
204
}
205
forceinline
Archive&
206
operator <<
(
Archive
& e,
unsigned
short
i
) {
207
e.
put
(
i
);
208
return
e;
209
}
210
forceinline
Archive&
211
operator <<
(
Archive
& e,
short
i
) {
212
e.
put
(
static_cast<
unsigned
int
>
(
i
));
213
return
e;
214
}
215
forceinline
Archive&
216
operator <<
(
Archive
& e,
unsigned
char
i
) {
217
e.
put
(
i
);
218
return
e;
219
}
220
forceinline
Archive&
221
operator <<
(
Archive
& e,
char
i
) {
222
e.
put
(
static_cast<
unsigned
int
>
(
i
));
223
return
e;
224
}
225
forceinline
Archive&
226
operator <<
(
Archive
& e,
bool
i
) {
227
e.
put
(
static_cast<
unsigned
int
>
(
i
));
228
return
e;
229
}
230
forceinline
Archive&
231
operator <<
(
Archive
& e,
float
d
) {
232
for
(
size_t
i
=0;
i
<
sizeof
(float);
i
++)
233
e.
put
(
static_cast<
unsigned
int
>
(
reinterpret_cast<
char
*
>
(&
d
)[
i
]));
234
return
e;
235
}
236
forceinline
Archive&
237
operator <<
(
Archive
& e,
double
d
) {
238
for
(
size_t
i
=0;
i
<
sizeof
(double);
i
++)
239
e.
put
(
static_cast<
unsigned
int
>
(
reinterpret_cast<
char
*
>
(&
d
)[
i
]));
240
return
e;
241
}
242
243
forceinline
Archive&
244
operator >>
(
Archive
& e,
unsigned
int
&
i
) {
245
i
= e.
get
();
246
return
e;
247
}
248
forceinline
Archive&
249
operator >>
(
Archive
& e,
int
&
i
) {
250
i
=
static_cast<
int
>
(e.
get
());
251
return
e;
252
}
253
forceinline
Archive&
254
operator >>
(
Archive
& e,
unsigned
short
&
i
) {
255
i
=
static_cast<
unsigned
short
>
(e.
get
());
256
return
e;
257
}
258
forceinline
Archive&
259
operator >>
(
Archive
& e,
short
&
i
) {
260
i
=
static_cast<
short
>
(e.
get
());
261
return
e;
262
}
263
forceinline
Archive&
264
operator >>
(
Archive
& e,
unsigned
char
&
i
) {
265
i
=
static_cast<
unsigned
char
>
(e.
get
());
266
return
e;
267
}
268
forceinline
Archive&
269
operator >>
(
Archive
& e,
char
&
i
) {
270
i
=
static_cast<
char
>
(e.
get
());
271
return
e;
272
}
273
forceinline
Archive&
274
operator >>
(
Archive
& e,
bool
&
i
) {
275
i
= (e.
get
() != 0);
276
return
e;
277
}
278
forceinline
Archive&
279
operator >>
(
Archive
& e,
float
&
d
) {
280
char
* cd =
reinterpret_cast<
char
*
>
(&
d
);
281
for
(
size_t
i
=0;
i
<
sizeof
(float);
i
++)
282
cd[
i
] =
static_cast<
char
>
(e.
get
());
283
return
e;
284
}
285
forceinline
Archive&
286
operator >>
(
Archive
& e,
double
&
d
) {
287
char
* cd =
reinterpret_cast<
char
*
>
(&
d
);
288
for
(
size_t
i
=0;
i
<
sizeof
(double);
i
++)
289
cd[
i
] =
static_cast<
char
>
(e.
get
());
290
return
e;
291
}
292
293
}
294
295
// STATISTICS: kernel-branch
Gecode::Archive::operator=
Archive & operator=(const Archive &e)
Assignment operator.
Definition:
archive.cpp:51
Gecode::Archive::put
void put(unsigned int i)
Add i to the contents.
Definition:
archive.hpp:174
Gecode::operator>>
Archive & operator>>(Archive &e, FloatNumBranch &nl)
Definition:
val-sel.hpp:44
Test::Int::Precede::_a
Single _a(2, 3)
Gecode::Archive
Archive representation
Definition:
archive.hpp:42
Gecode::Archive::~Archive
~Archive(void)
Destructor.
Definition:
archive.cpp:60
Gecode::Archive::operator[]
unsigned int operator[](int i) const
Return array element i.
Definition:
archive.hpp:184
Gecode::Archive::get
unsigned int get(void)
Return next element to read.
Definition:
archive.hpp:190
Gecode
Gecode toplevel namespace
Gecode::Archive::size
int size(void) const
Return size.
Definition:
archive.hpp:181
GECODE_KERNEL_EXPORT
#define GECODE_KERNEL_EXPORT
Definition:
kernel.hh:70
Gecode::Archive::Archive
Archive(void)
Construct empty representation.
Definition:
archive.hpp:171
Test::Int::Distinct::d
Gecode::IntSet d(v, 7)
forceinline
#define forceinline
Definition:
config.hpp:185
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:234
Test::Int::Basic::i
Gecode::IntArgs i({1, 2, 3, 4})
Gecode::operator<<
Archive & operator<<(Archive &e, FloatNumBranch nl)
Definition:
val-sel.hpp:39