/usr/include/gecode/kernel/archive.hpp is in libgecode-dev 4.4.0-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Guido Tack <tack@gecode.org>
*
* Copyright:
* Guido Tack, 2011
*
* Last modified:
* $Date: 2011-10-11 19:28:17 +0200 (Tue, 11 Oct 2011) $ by $Author: tack $
* $Revision: 12440 $
*
* 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.
*
*/
namespace Gecode {
/**
* \brief %Archive representation
*
* An Archive is an array of unsigned integers, used as an external
* representation of internal data structures (such as Choice objects).
*/
class Archive {
private:
/// Size of array
int _size;
/// Used size of array
int _n;
/// Array elements
unsigned int* _a;
/// Current position of read iterator
int _pos;
/// Resize to at least \a n + 1 elements
GECODE_KERNEL_EXPORT void resize(int n);
public:
/// Construct empty representation
Archive(void);
/// Destructor
GECODE_KERNEL_EXPORT ~Archive(void);
/// Copy constructor
GECODE_KERNEL_EXPORT Archive(const Archive& e);
/// Assignment operator
GECODE_KERNEL_EXPORT Archive& operator =(const Archive& e);
/// Add \a i to the contents
void put(unsigned int i);
/// Return size
int size(void) const;
/// Return array element \a i
unsigned int operator [](int i) const;
/// Return next element to read
unsigned int get(void);
};
/** Add \a i to the end of \a e
* \relates Archive
*/
Archive&
operator <<(Archive& e, unsigned int i);
/** Add \a i to the end of \a e
* \relates Archive
*/
Archive&
operator <<(Archive& e, int i);
/** Add \a i to the end of \a e
* \relates Archive
*/
Archive&
operator <<(Archive& e, unsigned short i);
/** Add \a i to the end of \a e
* \relates Archive
*/
Archive&
operator <<(Archive& e, short i);
/** Add \a i to the end of \a e
* \relates Archive
*/
Archive&
operator <<(Archive& e, unsigned char i);
/** Add \a i to the end of \a e
* \relates Archive
*/
Archive&
operator <<(Archive& e, char i);
/** Add \a i to the end of \a e
* \relates Archive
*/
Archive&
operator <<(Archive& e, bool i);
/** Add \a d to the end of \a e
* \relates Archive
*/
Archive&
operator <<(Archive& e, float d);
/** Add \a d to the end of \a e
* \relates Archive
*/
Archive&
operator <<(Archive& e, double d);
/** Read next element from \a e into \a i
* \relates Archive
*/
Archive&
operator >>(Archive& e, unsigned int& i);
/** Read next element from \a e into \a i
* \relates Archive
*/
Archive&
operator >>(Archive& e, int& i);
/** Read next element from \a e into \a i
* \relates Archive
*/
Archive&
operator >>(Archive& e, unsigned short& i);
/** Read next element from \a e into \a i
* \relates Archive
*/
Archive&
operator >>(Archive& e, short& i);
/** Read next element from \a e into \a i
* \relates Archive
*/
Archive&
operator >>(Archive& e, unsigned char& i);
/** Read next element from \a e into \a i
* \relates Archive
*/
Archive&
operator >>(Archive& e, char& i);
/** Read next element from \a e into \a i
* \relates Archive
*/
Archive&
operator >>(Archive& e, bool& i);
/** Read next element from \a e into \a d
* \relates Archive
*/
Archive&
operator >>(Archive& e, float& d);
/** Read next element from \a e into \a d
* \relates Archive
*/
Archive&
operator >>(Archive& e, double& d);
/*
* Implementation
*
*/
forceinline
Archive::Archive(void) : _size(0), _n(0), _a(NULL), _pos(0) {}
forceinline void
Archive::put(unsigned int i) {
if (_n==_size)
resize(_n+1);
_a[_n++] = i;
}
forceinline int
Archive::size(void) const { return _n; }
forceinline unsigned int
Archive::operator [](int i) const {
assert(i < _n);
return _a[i];
}
forceinline unsigned int
Archive::get(void) {
assert(_pos < _n);
return _a[_pos++];
}
forceinline Archive&
operator <<(Archive& e, unsigned int i) {
e.put(i);
return e;
}
forceinline Archive&
operator <<(Archive& e, int i) {
e.put(static_cast<unsigned int>(i));
return e;
}
forceinline Archive&
operator <<(Archive& e, unsigned short i) {
e.put(i);
return e;
}
forceinline Archive&
operator <<(Archive& e, short i) {
e.put(static_cast<unsigned int>(i));
return e;
}
forceinline Archive&
operator <<(Archive& e, unsigned char i) {
e.put(i);
return e;
}
forceinline Archive&
operator <<(Archive& e, char i) {
e.put(static_cast<unsigned int>(i));
return e;
}
forceinline Archive&
operator <<(Archive& e, bool i) {
e.put(static_cast<unsigned int>(i));
return e;
}
forceinline Archive&
operator <<(Archive& e, float d) {
for (size_t i=0; i<sizeof(float); i++)
e.put(static_cast<unsigned int>(reinterpret_cast<char*>(&d)[i]));
return e;
}
forceinline Archive&
operator <<(Archive& e, double d) {
for (size_t i=0; i<sizeof(double); i++)
e.put(static_cast<unsigned int>(reinterpret_cast<char*>(&d)[i]));
return e;
}
forceinline Archive&
operator >>(Archive& e, unsigned int& i) {
i = e.get();
return e;
}
forceinline Archive&
operator >>(Archive& e, int& i) {
i = static_cast<int>(e.get());
return e;
}
forceinline Archive&
operator >>(Archive& e, unsigned short& i) {
i = static_cast<unsigned short>(e.get());
return e;
}
forceinline Archive&
operator >>(Archive& e, short& i) {
i = static_cast<short>(e.get());
return e;
}
forceinline Archive&
operator >>(Archive& e, unsigned char& i) {
i = static_cast<unsigned char>(e.get());
return e;
}
forceinline Archive&
operator >>(Archive& e, char& i) {
i = static_cast<char>(e.get());
return e;
}
forceinline Archive&
operator >>(Archive& e, bool& i) {
i = static_cast<bool>(e.get());
return e;
}
forceinline Archive&
operator >>(Archive& e, float& d) {
char* cd = reinterpret_cast<char*>(&d);
for (size_t i=0; i<sizeof(float); i++)
cd[i] = static_cast<char>(e.get());
return e;
}
forceinline Archive&
operator >>(Archive& e, double& d) {
char* cd = reinterpret_cast<char*>(&d);
for (size_t i=0; i<sizeof(double); i++)
cd[i] = static_cast<char>(e.get());
return e;
}
}
// STATISTICS: kernel-branch
|