[2615] | 1 | #include "sopnamsp.h"
|
---|
[2475] | 2 | #include "machdefs.h"
|
---|
| 3 | #include <stdio.h>
|
---|
[3619] | 4 | #include <stdlib.h>
|
---|
| 5 | #include <string.h>
|
---|
[2475] | 6 | #include <sys/types.h>
|
---|
| 7 | #include <time.h>
|
---|
| 8 | #include "ppfbinstream.h"
|
---|
| 9 | #include "pexceptions.h"
|
---|
| 10 | #include <iostream>
|
---|
| 11 |
|
---|
| 12 |
|
---|
[2482] | 13 | // strptime n'est pas defini sous Linux avec g++ avant gcc 3.x - Reza Mars 2000
|
---|
[3525] | 14 | #if defined(Linux) && defined(__GNUG__) && (__GNUC__ < 3)
|
---|
[2475] | 15 | extern "C" {
|
---|
| 16 | char *strptime(const char *buf, const char *format, struct tm *tm);
|
---|
| 17 | }
|
---|
| 18 | #endif
|
---|
| 19 |
|
---|
| 20 | #define MAXTAGLEN_V2 255
|
---|
| 21 |
|
---|
| 22 |
|
---|
[3750] | 23 | static inline void bswap16(void* p)
|
---|
| 24 | {
|
---|
| 25 | uint_8* p8 = (uint_8*)p;
|
---|
| 26 | uint_8 tmp1 = *(p8);
|
---|
| 27 | uint_8 tmp = *(p8+1);
|
---|
| 28 | *(p8) = ((tmp >> (7*8)) & 0x000000FF) |
|
---|
| 29 | ((tmp >> (5*8)) & 0x0000FF00) |
|
---|
| 30 | ((tmp >> (3*8)) & 0x00FF0000) |
|
---|
| 31 | ((tmp >> (1*8)) & 0xFF000000) |
|
---|
| 32 | ((tmp & 0xFF000000) << (1*8)) |
|
---|
| 33 | ((tmp & 0x00FF0000) << (3*8)) |
|
---|
| 34 | ((tmp & 0x0000FF00) << (5*8)) |
|
---|
| 35 | ((tmp & 0x000000FF) << (7*8));
|
---|
| 36 | *(p8+1) = ((tmp1 >> (7*8)) & 0x000000FF) |
|
---|
| 37 | ((tmp1 >> (5*8)) & 0x0000FF00) |
|
---|
| 38 | ((tmp1 >> (3*8)) & 0x00FF0000) |
|
---|
| 39 | ((tmp1 >> (1*8)) & 0xFF000000) |
|
---|
| 40 | ((tmp1 & 0xFF000000) << (1*8)) |
|
---|
| 41 | ((tmp1 & 0x00FF0000) << (3*8)) |
|
---|
| 42 | ((tmp1 & 0x0000FF00) << (5*8)) |
|
---|
| 43 | ((tmp1 & 0x000000FF) << (7*8));
|
---|
| 44 | }
|
---|
| 45 |
|
---|
[2475] | 46 | static inline void bswap8(void* p)
|
---|
| 47 | {
|
---|
| 48 | uint_8 tmp = *(uint_8*)p;
|
---|
| 49 | *(uint_8*)p = ((tmp >> (7*8)) & 0x000000FF) |
|
---|
| 50 | ((tmp >> (5*8)) & 0x0000FF00) |
|
---|
| 51 | ((tmp >> (3*8)) & 0x00FF0000) |
|
---|
| 52 | ((tmp >> (1*8)) & 0xFF000000) |
|
---|
| 53 | ((tmp & 0xFF000000) << (1*8)) |
|
---|
| 54 | ((tmp & 0x00FF0000) << (3*8)) |
|
---|
| 55 | ((tmp & 0x0000FF00) << (5*8)) |
|
---|
| 56 | ((tmp & 0x000000FF) << (7*8));
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | static inline void bswap4(void* p)
|
---|
| 60 | {
|
---|
| 61 | uint_4 tmp = *(uint_4*)p;
|
---|
| 62 | *(uint_4*)p = ((tmp >> 24) & 0x000000FF) |
|
---|
| 63 | ((tmp >> 8) & 0x0000FF00) |
|
---|
| 64 | ((tmp & 0x0000FF00) << 8) |
|
---|
| 65 | ((tmp & 0x000000FF) << 24);
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | static inline void bswap2(void* p)
|
---|
| 69 | {
|
---|
| 70 | uint_2 tmp = *(uint_2*)p;
|
---|
| 71 | *(uint_2*)p = ((tmp >> 8) & 0x00FF) |
|
---|
| 72 | ((tmp & 0x00FF) << 8);
|
---|
| 73 | }
|
---|
| 74 |
|
---|
[3750] | 75 | // Convertit la taille de donnees (2 (int_2), 4 (int_4, r_4), 8 (r_8) ...) en taille codee dans le tag
|
---|
| 76 | static inline unsigned char datasize2tagsize( unsigned char sz)
|
---|
| 77 | {
|
---|
| 78 | // Taille permises 1,2,4,8,16
|
---|
| 79 | // Pour les tailles <= 8, c'est directement la taille
|
---|
| 80 | if (sz<=8) return sz;
|
---|
| 81 | else {
|
---|
| 82 | if (sz==16) return 10;
|
---|
| 83 | else return 0; // signale une erreur
|
---|
| 84 | }
|
---|
| 85 | }
|
---|
| 86 | // Convertit la taille codee dans le tag en taille de donnees (2 (int_2), 4 (int_4, r_4), 8 (r_8) ...) en
|
---|
| 87 | static inline unsigned char tagsize2datasize( unsigned char sz)
|
---|
| 88 | {
|
---|
| 89 | // Taille permises 1,2,4,8,16
|
---|
| 90 | // Pour les tailles <= 8, c'est directement la taille
|
---|
| 91 | if (sz<=8) return sz;
|
---|
| 92 | else {
|
---|
| 93 | if (sz==10) return 10;
|
---|
| 94 | else return 0; // signale une erreur
|
---|
| 95 | }
|
---|
| 96 | }
|
---|
| 97 |
|
---|
[2477] | 98 | //-------------------------------------------------------------------------
|
---|
| 99 | //---------------------- Classe PPFBinaryIOStream ------------------------
|
---|
| 100 | //-------------------------------------------------------------------------
|
---|
[2475] | 101 |
|
---|
[2805] | 102 | /*!
|
---|
| 103 | \class SOPHYA::PPFBinaryIOStream
|
---|
| 104 | \ingroup BaseTools
|
---|
| 105 | Base class for SOPHYA PPF input / output stream
|
---|
| 106 | */
|
---|
[2477] | 107 |
|
---|
[2805] | 108 |
|
---|
[2477] | 109 | PPFBinaryIOStream::PPFBinaryIOStream()
|
---|
| 110 | {
|
---|
| 111 | version = 0; // PPersist(In/Out) version
|
---|
| 112 | // creationdate = time(NULL); // Date de creation du fichier
|
---|
| 113 | _nbpostag = 0; // Nb de tag de positionnement
|
---|
| 114 | _nbobjs = 0; // Nb total d'objets
|
---|
| 115 | _nbtlobjs = 0; // Nb d'objets de niveau 1
|
---|
[2482] | 116 | _nbrefs = 0; // Nb de reference d'objets
|
---|
| 117 | _maxnestlevel = 0; // Niveau maximum d'objets emboites
|
---|
[2477] | 118 | }
|
---|
| 119 |
|
---|
| 120 | PPFBinaryIOStream::~PPFBinaryIOStream()
|
---|
| 121 | {
|
---|
| 122 | }
|
---|
| 123 |
|
---|
[2805] | 124 | //! Return the creation date/time of the associated stream as a string
|
---|
[2477] | 125 | string
|
---|
| 126 | PPFBinaryIOStream::CreationDateStr()
|
---|
| 127 | {
|
---|
| 128 | time_t cdt = CreationDate();
|
---|
| 129 | string cdate = ctime(&cdt);
|
---|
| 130 | return(cdate);
|
---|
| 131 | }
|
---|
| 132 |
|
---|
[2805] | 133 | //! Return a string with information about the stream (creation-date, version ...)
|
---|
[2477] | 134 | string
|
---|
| 135 | PPFBinaryIOStream::InfoString()
|
---|
| 136 | {
|
---|
| 137 | string rs;
|
---|
| 138 | char buff[256];
|
---|
| 139 | sprintf(buff,"PPFStream Version= %d CreationDate= ", Version());
|
---|
| 140 | rs += buff;
|
---|
| 141 | rs += CreationDateStr();
|
---|
[2482] | 142 | sprintf(buff,"\n NbObjs= %ld NbTopLevObjs= %ld NbRefs= %ld MaxNest= %d ",
|
---|
| 143 | (long)NbObjects(), (long)NbTopLevelObjects(),
|
---|
| 144 | (long)NbReferences(), MaxNestedObjsLevel());
|
---|
[2477] | 145 | rs += buff;
|
---|
| 146 | sprintf(buff,"\n NbPosTag= %ld NbNameTag= %ld ", (long)NbPosTags(),
|
---|
| 147 | (long)NbNameTags());
|
---|
| 148 | rs += buff;
|
---|
| 149 | return rs;
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 |
|
---|
[2805] | 153 | //! Return the name tag number \b itag
|
---|
[2477] | 154 | string
|
---|
| 155 | PPFBinaryIOStream::GetTagName(int itag)
|
---|
| 156 | {
|
---|
| 157 | if (itag<0 || itag >= (int)tags.size()) return "";
|
---|
| 158 | map<string, int_8>::iterator i = tags.begin();
|
---|
| 159 | for (int j=0; j<itag; j++) i++;
|
---|
| 160 | return((*i).first);
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 |
|
---|
[2805] | 164 | //! Return a reference to a vector<string> containing all name-tags associated with the stream
|
---|
[2477] | 165 | static vector<string> * ret_tag_names = NULL;
|
---|
| 166 | vector<string> const &
|
---|
| 167 | PPFBinaryIOStream::GetNameTags()
|
---|
| 168 | {
|
---|
| 169 | if (ret_tag_names) delete ret_tag_names;
|
---|
| 170 | ret_tag_names = new vector<string> ;
|
---|
| 171 | map<string, int_8>::iterator i;
|
---|
| 172 | for(i=tags.begin(); i!=tags.end(); i++) ret_tag_names->push_back((*i).first);
|
---|
| 173 | return(*ret_tag_names);
|
---|
| 174 | }
|
---|
| 175 |
|
---|
| 176 | //-------------------------------------------------------------------------
|
---|
| 177 | //-------------------- Classe PPFBinaryInputStream -----------------------
|
---|
| 178 | //-------------------------------------------------------------------------
|
---|
| 179 |
|
---|
[2805] | 180 | /*!
|
---|
| 181 | \class SOPHYA::PPFBinaryInputStream
|
---|
| 182 | \ingroup BaseTools
|
---|
| 183 | PPF Input stream implementing read operations
|
---|
| 184 | */
|
---|
| 185 |
|
---|
| 186 | /*! Constructor from a RawInOutStream pointer
|
---|
| 187 | \param is : pointer to RawInOutStream
|
---|
| 188 | \param ad : if true, the RawInOutStream \b is is deleted by the destructor
|
---|
| 189 | \param scan : if true, try to read the name-tags table from the end of the input stream
|
---|
| 190 | */
|
---|
[2476] | 191 | PPFBinaryInputStream::PPFBinaryInputStream(RawInOutStream * is, bool ad, bool scan)
|
---|
[2475] | 192 | {
|
---|
[2476] | 193 | s = is;
|
---|
| 194 | _ads = ad;
|
---|
| 195 | Init(scan);
|
---|
[2475] | 196 | }
|
---|
| 197 |
|
---|
[2805] | 198 | /*! Constructor
|
---|
| 199 | \param flnm : input file name
|
---|
| 200 | \param scan : if true, try to read the name-tags table from the end of the input stream
|
---|
| 201 | */
|
---|
[2475] | 202 | PPFBinaryInputStream::PPFBinaryInputStream(string const& flnm, bool scan)
|
---|
| 203 | //
|
---|
| 204 | // Constructeur. Ouvre le fichier.
|
---|
| 205 | //--
|
---|
| 206 | {
|
---|
| 207 | s = new RawInFileStream(flnm.c_str());
|
---|
[2476] | 208 | _ads = true;
|
---|
| 209 | Init(scan);
|
---|
| 210 | }
|
---|
[2475] | 211 |
|
---|
[2476] | 212 | PPFBinaryInputStream::~PPFBinaryInputStream()
|
---|
| 213 | {
|
---|
| 214 | if (_ads && (s!=NULL) ) delete s;
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 | void
|
---|
| 218 | PPFBinaryInputStream::Init(bool scan)
|
---|
| 219 | {
|
---|
[2475] | 220 | // Read and check header
|
---|
| 221 |
|
---|
| 222 | char rbuf[36];
|
---|
| 223 | GetRawBytes(rbuf, 32);
|
---|
| 224 | if (strncmp(rbuf,"SOS-SOPHYA-PPersistFile", 23) != 0) {
|
---|
| 225 | throw FileFormatExc("PPFBinaryInputStream::PPFBinaryInputStream bad header");
|
---|
| 226 | }
|
---|
| 227 | rbuf[32] = '\0';
|
---|
| 228 | version = atoi(rbuf+25);
|
---|
| 229 | if (version < 2) {
|
---|
[2476] | 230 | cerr << "PPFBinaryInputStream::PPFBinaryInputStream(" << FileName() << ") Version(=" << version
|
---|
[2475] | 231 | << ") < 2 not supported !" << endl;
|
---|
| 232 | throw FileFormatExc("PPFBinaryInputStream::PPFBinaryInputStream() - Unsupported (Old) Version");
|
---|
| 233 | }
|
---|
| 234 | // read endianness
|
---|
| 235 | GetRawBytes(rbuf, 32);
|
---|
| 236 | if (strncmp(rbuf,"BIG-ENDIAN",10) == 0)
|
---|
| 237 | bigEndian = true;
|
---|
| 238 | else if (strncmp(rbuf,"LITTLE-ENDIAN",13) == 0)
|
---|
| 239 | bigEndian = false;
|
---|
| 240 | else {
|
---|
| 241 | throw FileFormatExc("PPFBinaryInputStream::PPFBinaryInputStream bad header - endianness");
|
---|
| 242 | }
|
---|
| 243 |
|
---|
| 244 | // read creation date
|
---|
| 245 | GetRawBytes(rbuf, 32);
|
---|
| 246 | rbuf[32] = '\0';
|
---|
| 247 | struct tm tm;
|
---|
| 248 | strptime(rbuf,"%d/%m/%Y %H:%M:%S GMT",&tm);
|
---|
| 249 | /* #else
|
---|
| 250 | sscanf(rbuf,"%2d/%2d/%4d %2d:%2d:%2d GMT",&tm.tm_mday,&tm.tm_mon,&tm.tm_year,
|
---|
| 251 | &tm.tm_hour,&tm.tm_min,&tm.tm_sec);
|
---|
[2482] | 252 | tm.tm_mon --; tm.tm_year -= 1900;
|
---|
| 253 | #endif */
|
---|
[2475] | 254 |
|
---|
| 255 | creationdate = mktime(&tm);
|
---|
| 256 | seqread = true; // To flag non sequential reads
|
---|
[2476] | 257 | if (scan && s->isSeekable()) {
|
---|
| 258 | if (Version() >= 3) ReadNameTagTable();
|
---|
| 259 | else ReadNameTagTableV2();
|
---|
| 260 | }
|
---|
[2475] | 261 | }
|
---|
| 262 |
|
---|
| 263 |
|
---|
| 264 | void
|
---|
[2476] | 265 | PPFBinaryInputStream::ReadNameTagTable()
|
---|
[2475] | 266 | {
|
---|
[2476] | 267 | unsigned char ppstype;
|
---|
| 268 | int_8 debut;
|
---|
| 269 | debut = s->tellg();
|
---|
| 270 |
|
---|
| 271 | s->seekg(-(sizeof(int_8)+1), ios::end);
|
---|
[2477] | 272 | // Lecture position NameTagTable et tag EOF
|
---|
| 273 | int_8 pos;
|
---|
| 274 | GetRawI8(pos);
|
---|
[2481] | 275 | GetRawUByte(ppstype);
|
---|
[2476] | 276 | if (ppstype != PPS_EOF)
|
---|
| 277 | throw FileFormatExc("PPFBinaryInputStream::ReadNameTagTable() Corrupted file, no EOF tag at end of file");
|
---|
| 278 |
|
---|
| 279 | // On se positionne au debut du NameTagTable
|
---|
| 280 | s->seekg(pos);
|
---|
[2481] | 281 | GetRawUByte(ppstype);
|
---|
[2476] | 282 | if (ppstype != PPS_NAMETAG_TABLE)
|
---|
| 283 | throw FileFormatExc("PPFBinaryInputStream::ReadNameTagTable() Corrupted file PPS_NAMETAG_TABLE not found");
|
---|
[2477] | 284 | // Lecture nb de PosTag et nb d'objets dans le flot
|
---|
[2482] | 285 | int_8 stats[8] = {0,0,0,0,0,0,0,0};
|
---|
| 286 | GetI8s(stats, 8);
|
---|
| 287 | _nbpostag = stats[0];
|
---|
| 288 | _nbobjs = stats[1];
|
---|
| 289 | _nbtlobjs = stats[2];
|
---|
| 290 | _nbrefs = stats[3];
|
---|
| 291 | _maxnestlevel = stats[4];
|
---|
| 292 |
|
---|
[2476] | 293 | uint_8 ttsz,it;
|
---|
[2477] | 294 | // Lecture nombre de NameTag
|
---|
[2482] | 295 | GetRawU8(ttsz);
|
---|
[2477] | 296 | if (ttsz > 0) {
|
---|
| 297 | for(it=0; it<ttsz; it++) {
|
---|
| 298 | int_8 tpos;
|
---|
| 299 | string tname;
|
---|
[2482] | 300 | GetRawI8(tpos);
|
---|
[2477] | 301 | GetStr(tname);
|
---|
| 302 | tags[tname] = tpos;
|
---|
| 303 | }
|
---|
[2476] | 304 | }
|
---|
| 305 | // On revient au debut du float, juste apres l'entete
|
---|
| 306 | s->seekg(debut);
|
---|
| 307 | }
|
---|
| 308 |
|
---|
| 309 | void
|
---|
| 310 | PPFBinaryInputStream::ReadNameTagTableV2()
|
---|
| 311 | {
|
---|
[2475] | 312 | // On cherche la liste des tags, a la fin du fichier
|
---|
| 313 |
|
---|
| 314 | unsigned char ppstype;
|
---|
| 315 | int_8 debut;
|
---|
| 316 | debut = s->tellg();
|
---|
| 317 |
|
---|
| 318 | s->seekg(-(sizeof(int_8)+1), ios::end);
|
---|
| 319 |
|
---|
[2481] | 320 | GetRawUByte(ppstype);
|
---|
[2475] | 321 | if (ppstype != PPS_EOF)
|
---|
[2476] | 322 | throw FileFormatExc("PPFBinaryInputStream::ReadNameTagTableV2() Corrupted file, no eof entry at end of file");
|
---|
[2475] | 323 |
|
---|
| 324 | int_8 pos;
|
---|
| 325 | GetRawI8(pos);
|
---|
| 326 | if (pos < 0) { // no tags
|
---|
| 327 | s->seekg(debut);
|
---|
| 328 | return;
|
---|
| 329 | }
|
---|
| 330 |
|
---|
| 331 | char buffer[MAXTAGLEN_V2+1];
|
---|
| 332 | s->seekg(pos);
|
---|
| 333 | while (true) {
|
---|
[2481] | 334 | GetRawUByte(ppstype);
|
---|
[2475] | 335 | if (ppstype == PPS_EOF) break;
|
---|
| 336 |
|
---|
| 337 | if (ppstype != PPS_NAMETAG_TABLE)
|
---|
[2476] | 338 | throw FileFormatExc("PPFBinaryInputStream::ReadNameTagTableV2() Corrupted file, bad tag entry");
|
---|
[2475] | 339 |
|
---|
| 340 | GetRawI8(pos);
|
---|
| 341 | int_4 len;
|
---|
| 342 | GetRawI4(len);
|
---|
| 343 | if (len > MAXTAGLEN_V2)
|
---|
[2476] | 344 | throw FileFormatExc("PPFBinaryInputStream::ReadNameTagTableV2() Corrupted file, tag name too long");
|
---|
[2475] | 345 | GetRawBytes(buffer, len);
|
---|
| 346 | buffer[len] = '\0';
|
---|
| 347 |
|
---|
| 348 | tags[buffer] = pos;
|
---|
| 349 | }
|
---|
| 350 | s->seekg(debut);
|
---|
| 351 | }
|
---|
| 352 |
|
---|
| 353 |
|
---|
| 354 | bool
|
---|
| 355 | PPFBinaryInputStream::GotoPositionTag(int_8 pos)
|
---|
| 356 | {
|
---|
| 357 | s->seekg(pos);
|
---|
[2481] | 358 | unsigned char ppstag;
|
---|
| 359 | GetRawUByte(ppstag);
|
---|
| 360 | if (ppstag != PPS_POSTAG_MARK)
|
---|
| 361 | throw FileFormatExc("PPFBinaryInputStream::GotoPositionTag() - PPS_POSTAG_MARK not found!");
|
---|
[2475] | 362 | int_8 tpos;
|
---|
| 363 | GetRawI8(tpos);
|
---|
| 364 | if (tpos != pos)
|
---|
| 365 | throw FileFormatExc("PPFBinaryInputStream::GotoPositionTag() - Wrong tag position!");
|
---|
| 366 | return true;
|
---|
| 367 | }
|
---|
| 368 |
|
---|
| 369 | bool
|
---|
| 370 | PPFBinaryInputStream::GotoNameTag(string const& name)
|
---|
| 371 | {
|
---|
| 372 | map<string, int_8>::iterator i = tags.find(name);
|
---|
| 373 | if (i == tags.end())
|
---|
| 374 | return false;
|
---|
| 375 | // throw NotFoundExc("PPFBinaryInputStream::GotoNameTag tag not found");
|
---|
| 376 | s->seekg((*i).second);
|
---|
| 377 | seqread = false;
|
---|
| 378 | // objList.clear(); $CHECK$ EA 171199 Ne pas faire ? Reza 03/2000 ?
|
---|
| 379 | return(true);
|
---|
| 380 | }
|
---|
| 381 |
|
---|
| 382 |
|
---|
| 383 | bool
|
---|
| 384 | PPFBinaryInputStream::GotoNameTagNum(int itag)
|
---|
| 385 | {
|
---|
| 386 | if (itag<0 || itag >= (int)tags.size()) return false;
|
---|
| 387 | map<string, int_8>::iterator i = tags.begin();
|
---|
| 388 | for (int j=0; j<itag; j++) i++;
|
---|
| 389 | s->seekg((*i).second);
|
---|
| 390 | seqread = false;
|
---|
| 391 | // objList.clear(); $CHECK$ EA 171199 Ne pas faire ? Reza 03/2000 ?
|
---|
| 392 | return(true);
|
---|
| 393 | }
|
---|
| 394 |
|
---|
| 395 |
|
---|
| 396 | bool
|
---|
| 397 | PPFBinaryInputStream::SkipToNextObject()
|
---|
| 398 | {
|
---|
[2477] | 399 | if (! s->isSeekable()) return false;
|
---|
| 400 | unsigned char ppstag=0;
|
---|
| 401 | // int kss;
|
---|
| 402 | while ((ppstag != PPS_OBJECT) && (ppstag != PPS_REFERENCE) && (ppstag != PPS_EOF)) {
|
---|
| 403 | // kss++;
|
---|
| 404 | GetRawUByte(ppstag);
|
---|
| 405 | // cout << " DBG--SkipToNextObject(" << kss << ")" << (int)ppstag << ","
|
---|
| 406 | // << (int)PPS_OBJECT << " fpos=" << s->tellg() << endl;
|
---|
| 407 | if ((ppstag != PPS_OBJECT) && (ppstag != PPS_REFERENCE) && (ppstag != PPS_EOF))
|
---|
| 408 | SkipItem(false, ppstag);
|
---|
| 409 | }
|
---|
| 410 | s->seekg(-1, ios::cur);
|
---|
| 411 | if (ppstag == PPS_OBJECT) return true;
|
---|
| 412 | else return false;
|
---|
| 413 |
|
---|
[2475] | 414 | }
|
---|
| 415 |
|
---|
| 416 | bool
|
---|
[2476] | 417 | PPFBinaryInputStream::SkipNextItem()
|
---|
[2475] | 418 | {
|
---|
[2477] | 419 | if (! s->isSeekable()) return false;
|
---|
| 420 | SkipItem();
|
---|
[2475] | 421 | return true;
|
---|
| 422 | }
|
---|
| 423 |
|
---|
[2476] | 424 | char
|
---|
[2485] | 425 | PPFBinaryInputStream::NextItemTag(short & datasz, size_t & asz)
|
---|
[2476] | 426 | {
|
---|
[2477] | 427 | int_8 cpos;
|
---|
| 428 | cpos = s->tellg();
|
---|
| 429 |
|
---|
| 430 | unsigned char ppstag=0;
|
---|
| 431 | unsigned char ppst1,ppst2,ppst3,ppst30;
|
---|
| 432 | GetRawUByte(ppstag);
|
---|
| 433 | ppst1 = ppstag&0x0f; // bits 0123
|
---|
| 434 | ppst2 = ppstag&0x30; // bits 45
|
---|
| 435 | ppst3 = ppstag&0xc0; // bits 67
|
---|
| 436 | ppst30 = ppstag&0xc1; // bits 0 67
|
---|
| 437 |
|
---|
[2476] | 438 | datasz = 0;
|
---|
[2477] | 439 | asz = 0;
|
---|
| 440 |
|
---|
| 441 | int_4 i4;
|
---|
| 442 | uint_8 ui8;
|
---|
| 443 |
|
---|
| 444 | if ((ppst2 == 0) && (ppst3 == 0) ) {
|
---|
| 445 | switch (ppst1) {
|
---|
| 446 | case PPS_STRING :
|
---|
| 447 | GetRawI4(i4);
|
---|
| 448 | datasz = 1;
|
---|
| 449 | asz = i4;
|
---|
| 450 | break;
|
---|
| 451 |
|
---|
| 452 | case PPS_NULL :
|
---|
| 453 | case PPS_OBJECT :
|
---|
| 454 | case PPS_REFERENCE :
|
---|
| 455 | case PPS_NAMETAG_MARK :
|
---|
| 456 | case PPS_POSTAG_MARK :
|
---|
| 457 | case PPS_ENDOBJECT :
|
---|
| 458 | case PPS_POSTAG_TABLE :
|
---|
| 459 | case PPS_NAMETAG_TABLE :
|
---|
| 460 | case PPS_EOF :
|
---|
| 461 | datasz = 0;
|
---|
| 462 | asz = 0;
|
---|
| 463 | break;
|
---|
| 464 |
|
---|
| 465 | default :
|
---|
| 466 | throw FileFormatExc("PPFBinaryInputStream::NextItemTag() - Unexpected tag value !");
|
---|
| 467 | break;
|
---|
| 468 | }
|
---|
| 469 | }
|
---|
| 470 | else {
|
---|
| 471 | int_4 dsize = ppst1;
|
---|
| 472 | if (ppst30 == PPS_DATATYPE_COMPLEX) {
|
---|
| 473 | dsize--;
|
---|
| 474 | }
|
---|
| 475 | switch (ppst2) {
|
---|
| 476 | case PPS_SIMPLE :
|
---|
| 477 | datasz = dsize;
|
---|
| 478 | asz = 1;
|
---|
| 479 | break;
|
---|
| 480 |
|
---|
| 481 | case PPS_SIMPLE_ARRAY4 :
|
---|
| 482 | GetRawI4(i4);
|
---|
| 483 | datasz = dsize;
|
---|
| 484 | asz = i4;
|
---|
| 485 | break;
|
---|
| 486 |
|
---|
| 487 | case PPS_SIMPLE_ARRAY8 :
|
---|
| 488 | GetRawU8(ui8);
|
---|
| 489 | datasz = dsize;
|
---|
[2481] | 490 | asz = ui8;
|
---|
[2477] | 491 | break;
|
---|
| 492 | }
|
---|
| 493 | }
|
---|
| 494 |
|
---|
| 495 | s->seekg(cpos,ios::beg);
|
---|
| 496 | return(ppstag);
|
---|
[2476] | 497 | }
|
---|
| 498 |
|
---|
| 499 | void
|
---|
[2477] | 500 | PPFBinaryInputStream::SkipItem(bool fgrdt, unsigned char itag)
|
---|
[2476] | 501 | {
|
---|
[2477] | 502 | unsigned char ppstag=0;
|
---|
| 503 | unsigned char ppst1,ppst2,ppst3,ppst30;
|
---|
| 504 | uint_8 ui8;
|
---|
| 505 | int_4 i4;
|
---|
| 506 | int_8 i8;
|
---|
| 507 |
|
---|
| 508 | if (fgrdt) GetRawUByte(ppstag);
|
---|
| 509 | else ppstag = itag;
|
---|
| 510 |
|
---|
| 511 | ppst1 = ppstag&0x0f; // bits 0123
|
---|
| 512 | ppst2 = ppstag&0x30; // bits 45
|
---|
| 513 | ppst3 = ppstag&0xc0; // bits 67
|
---|
| 514 | ppst30 = ppstag&0xc1; // bits 0 67
|
---|
| 515 | if ((ppst2 == 0) && (ppst3 == 0) ) {
|
---|
| 516 | switch (ppst1) {
|
---|
| 517 | case PPS_NULL :
|
---|
| 518 | case PPS_NAMETAG_MARK :
|
---|
| 519 | break;
|
---|
| 520 |
|
---|
| 521 | case PPS_STRING :
|
---|
| 522 | GetRawI4(i4);
|
---|
| 523 | s->seekg(i4,ios::cur);
|
---|
| 524 | break;
|
---|
| 525 |
|
---|
| 526 | case PPS_OBJECT :
|
---|
| 527 | GetRawU8(ui8);
|
---|
| 528 | GetRawU8(ui8);
|
---|
| 529 | break;
|
---|
| 530 |
|
---|
| 531 | case PPS_REFERENCE :
|
---|
| 532 | GetRawU8(ui8);
|
---|
| 533 | GetRawI8(i8);
|
---|
| 534 | break;
|
---|
| 535 |
|
---|
| 536 | case PPS_POSTAG_MARK :
|
---|
| 537 | GetRawI8(i8);
|
---|
| 538 | break;
|
---|
| 539 |
|
---|
| 540 | case PPS_ENDOBJECT :
|
---|
| 541 | GetRawU8(ui8);
|
---|
| 542 | break;
|
---|
| 543 |
|
---|
| 544 | case PPS_POSTAG_TABLE :
|
---|
| 545 | GetRawI4(i4);
|
---|
| 546 | // for(int kkt=0; kkt<i4; kkt++) GetRawI8(i8);
|
---|
| 547 | s->seekg((int_8)i4*8,ios::cur);
|
---|
| 548 | break;
|
---|
| 549 |
|
---|
| 550 | case PPS_NAMETAG_TABLE :
|
---|
| 551 | if (Version() < 3) {
|
---|
| 552 | GetRawI8(i8);
|
---|
| 553 | GetRawI4(i4);
|
---|
| 554 | s->seekg(i4,ios::cur);
|
---|
| 555 | }
|
---|
| 556 | else {
|
---|
| 557 | GetI8(i8); // nb pos tag
|
---|
| 558 | GetI8(i8); // nb d'objets
|
---|
| 559 | GetI8(i8); // nb objets toplevel
|
---|
| 560 | GetU8(ui8); // nb de nametag
|
---|
[3572] | 561 | for(uint_8 kt=0; kt<ui8; kt++) {
|
---|
[2477] | 562 | GetRawI4(i4);
|
---|
| 563 | s->seekg(i4,ios::cur);
|
---|
| 564 | }
|
---|
| 565 | GetI8(i8); // position debut NameTagTable
|
---|
| 566 | }
|
---|
| 567 | break;
|
---|
| 568 |
|
---|
| 569 |
|
---|
| 570 | case PPS_EOF :
|
---|
| 571 | if (Version() < 3) GetRawI8(i8);
|
---|
| 572 | break;
|
---|
| 573 |
|
---|
| 574 | default :
|
---|
| 575 | cerr << "PPFBinaryInputStream::SkipItem() ERROR : Unexpected tag value "
|
---|
| 576 | << hex << ppstag << " At position" << s->tellg() << dec << endl;
|
---|
| 577 | throw FileFormatExc("PPFBinaryInputStream::SkipItem() - Unexpected tag value !");
|
---|
| 578 | }
|
---|
| 579 | }
|
---|
| 580 | else {
|
---|
| 581 | string dtype = "???? x";
|
---|
| 582 | int_4 dsize = ppst1;
|
---|
| 583 | int_8 dsizeskip = dsize;
|
---|
| 584 | if (ppst30 == PPS_DATATYPE_COMPLEX) {
|
---|
| 585 | dsize--;
|
---|
| 586 | dsizeskip = 2*dsize;
|
---|
| 587 | }
|
---|
| 588 |
|
---|
| 589 | switch (ppst2) {
|
---|
| 590 | case PPS_SIMPLE :
|
---|
| 591 | s->seekg(dsizeskip, ios::cur);
|
---|
| 592 | break;
|
---|
| 593 |
|
---|
| 594 | case PPS_SIMPLE_ARRAY4 :
|
---|
| 595 | GetRawI4(i4);
|
---|
| 596 | s->seekg(dsizeskip*(int_8)i4, ios::cur);
|
---|
| 597 | break;
|
---|
| 598 |
|
---|
| 599 | case PPS_SIMPLE_ARRAY8 :
|
---|
| 600 | GetRawU8(ui8);
|
---|
| 601 | s->seekg(dsizeskip*ui8, ios::cur);
|
---|
| 602 | break;
|
---|
| 603 | }
|
---|
| 604 | }
|
---|
| 605 | return;
|
---|
[2476] | 606 | }
|
---|
| 607 |
|
---|
[2475] | 608 | //++
|
---|
| 609 | // void PPFBinaryInputStream::GetByte(char& c)
|
---|
| 610 | // void PPFBinaryInputStream::GetBytes(void* ptr, size_t bytes)
|
---|
| 611 | // void PPFBinaryInputStream::GetR4 (r_4& result)
|
---|
| 612 | // void PPFBinaryInputStream::GetR4s (r_4* tab, size_t n)
|
---|
| 613 | // void PPFBinaryInputStream::GetR8 (r_8& result)
|
---|
| 614 | // void PPFBinaryInputStream::GetR8s (r_8* tab, size_t n)
|
---|
| 615 | // void PPFBinaryInputStream::GetI2 (int_2& result)
|
---|
| 616 | // void PPFBinaryInputStream::GetI2s (int_2* tab, size_t n)
|
---|
| 617 | // void PPFBinaryInputStream::GetU2 (uint_2& result)
|
---|
| 618 | // void PPFBinaryInputStream::GetU2s (uint_2* tab, size_t n)
|
---|
| 619 | // void PPFBinaryInputStream::GetI4 (int_4& result)
|
---|
| 620 | // void PPFBinaryInputStream::GetI4s (int_4* tab, size_t n)
|
---|
| 621 | // void PPFBinaryInputStream::GetU4 (uint_4& result)
|
---|
| 622 | // void PPFBinaryInputStream::GetU4s (uint_4* tab, size_t n)
|
---|
| 623 | // void PPFBinaryInputStream::GetI8 (int_8& result)
|
---|
| 624 | // void PPFBinaryInputStream::GetI8s (int_8* tab, size_t n)
|
---|
| 625 | // void PPFBinaryInputStream::GetU8 (uint_8& result)
|
---|
| 626 | // void PPFBinaryInputStream::GetU8s (uint_8* tab, size_t n)
|
---|
| 627 | // Lecture de données portables depuis le fichier PPersist. Pour chaque type
|
---|
| 628 | // de données, on peut lire une valeur, ou un tableau de valeurs.
|
---|
| 629 | // void PPFBinaryInputStream::GetLine(char* ptr, size_t len)
|
---|
| 630 | // Lecture d'une ligne de texte depuis le fichier PPersist.
|
---|
| 631 | //--
|
---|
| 632 |
|
---|
| 633 |
|
---|
| 634 | void
|
---|
| 635 | PPFBinaryInputStream::GetTypeTag(unsigned char& c)
|
---|
| 636 | {
|
---|
| 637 | int_8 tpos;
|
---|
| 638 | c = PPS_NAMETAG_MARK;
|
---|
| 639 | while ( (c == PPS_NAMETAG_MARK) || (c == PPS_POSTAG_MARK) ) {
|
---|
| 640 | GetRawUByte(c);
|
---|
| 641 | if (c == PPS_POSTAG_MARK) GetRawI8(tpos);
|
---|
| 642 | }
|
---|
| 643 | // while (c == PPS_NAMETAG_MARK) { Il ne faut plus faire ca !
|
---|
| 644 | // objList.clear(); $CHECK$ Reza 03/2000
|
---|
| 645 | // GetRawByte(c);
|
---|
| 646 | // }
|
---|
| 647 | }
|
---|
| 648 |
|
---|
| 649 |
|
---|
| 650 | void
|
---|
| 651 | PPFBinaryInputStream::GetRawByte(char& c)
|
---|
| 652 | {
|
---|
| 653 | GetRawBytes(&c, 1);
|
---|
| 654 | }
|
---|
| 655 |
|
---|
| 656 | void
|
---|
| 657 | PPFBinaryInputStream::GetRawUByte(unsigned char& c)
|
---|
| 658 | {
|
---|
| 659 | GetRawBytes(&c, 1);
|
---|
| 660 | }
|
---|
| 661 |
|
---|
| 662 | void
|
---|
| 663 | PPFBinaryInputStream::GetRawBytes(void* ptr, size_t bytes)
|
---|
| 664 | {
|
---|
| 665 | s->read((char*)ptr, bytes);
|
---|
| 666 | }
|
---|
| 667 |
|
---|
| 668 | void
|
---|
| 669 | PPFBinaryInputStream::GetRawI2 (int_2& result)
|
---|
| 670 | {
|
---|
| 671 | GetRawBytes(&result, sizeof(int_2));
|
---|
| 672 | if (bigEndian != IS_BIG_ENDIAN)
|
---|
| 673 | bswap2(&result);
|
---|
| 674 | }
|
---|
| 675 |
|
---|
| 676 | void
|
---|
| 677 | PPFBinaryInputStream::GetRawI4 (int_4& result)
|
---|
| 678 | {
|
---|
| 679 | GetRawBytes(&result, sizeof(int_4));
|
---|
| 680 | if (bigEndian != IS_BIG_ENDIAN)
|
---|
| 681 | bswap4(&result);
|
---|
| 682 | }
|
---|
| 683 |
|
---|
| 684 | void
|
---|
| 685 | PPFBinaryInputStream::GetRawI8 (int_8& result)
|
---|
| 686 | {
|
---|
| 687 | GetRawBytes(&result, sizeof(int_8));
|
---|
| 688 | if (bigEndian != IS_BIG_ENDIAN)
|
---|
| 689 | bswap8(&result);
|
---|
| 690 | }
|
---|
| 691 |
|
---|
| 692 | void
|
---|
| 693 | PPFBinaryInputStream::GetRawU8 (uint_8& result)
|
---|
| 694 | {
|
---|
| 695 | GetRawBytes(&result, sizeof(uint_8));
|
---|
| 696 | if (bigEndian != IS_BIG_ENDIAN)
|
---|
| 697 | bswap8(&result);
|
---|
| 698 | }
|
---|
| 699 |
|
---|
| 700 | void
|
---|
[3750] | 701 | PPFBinaryInputStream::CheckTag(unsigned char datasz, unsigned char datatype)
|
---|
[2475] | 702 | // datatype = PPS_DATATYPE_CHAR or PPS_DATATYPE_FLOAT or PPS_DATATYPE_INTEGER or PPS_DATATYPE_UNSIGNED
|
---|
| 703 | {
|
---|
| 704 | unsigned char ppstype;
|
---|
| 705 | GetTypeTag(ppstype);
|
---|
[3750] | 706 | if (ppstype != PPS_SIMPLE + datasize2tagsize(datasz) + datatype)
|
---|
[2475] | 707 | throw FileFormatExc("PPFBinaryInputStream::CheckTag bad type in ppersist file");
|
---|
| 708 | }
|
---|
| 709 |
|
---|
| 710 | void
|
---|
[3750] | 711 | PPFBinaryInputStream::CheckArrayTag(unsigned char datasz, size_t sz, unsigned char datatype)
|
---|
[2475] | 712 | // datatype = PPS_DATATYPE_CHAR or PPS_DATATYPE_FLOAT or PPS_DATATYPE_INTEGER or PPS_DATATYPE_UNSIGNED
|
---|
| 713 | {
|
---|
| 714 | unsigned char ppstype;
|
---|
| 715 | GetTypeTag(ppstype);
|
---|
| 716 | size_t filesz;
|
---|
| 717 | if (sz <= 0x7fffffff) {
|
---|
[3750] | 718 | if (ppstype != PPS_SIMPLE_ARRAY4 + datasize2tagsize(datasz) + datatype)
|
---|
[2475] | 719 | throw FileFormatExc("PPFBinaryInputStream::CheckArrayTag bad type in ppersist file");
|
---|
| 720 | int_4 ff;
|
---|
| 721 | GetRawI4(ff); filesz=ff;
|
---|
| 722 | } else {
|
---|
[3750] | 723 | if (ppstype != PPS_SIMPLE_ARRAY8 + datasize2tagsize(datasz) + datatype)
|
---|
[2475] | 724 | throw FileFormatExc("PPFBinaryInputStream::CheckArrayTag bad type in ppersist file");
|
---|
| 725 | uint_8 ff;
|
---|
| 726 | GetRawU8(ff); filesz=ff;
|
---|
| 727 | }
|
---|
| 728 | if (filesz != sz)
|
---|
| 729 | throw FileFormatExc("PPFBinaryInputStream::CheckArrayTag bad array size in ppersist file");
|
---|
| 730 | }
|
---|
| 731 |
|
---|
| 732 | void
|
---|
| 733 | PPFBinaryInputStream::GetByte(char& c)
|
---|
| 734 | {
|
---|
| 735 | CheckTag(1,PPS_DATATYPE_CHAR);
|
---|
| 736 | GetRawBytes(&c, 1);
|
---|
| 737 | }
|
---|
| 738 |
|
---|
| 739 | void
|
---|
| 740 | PPFBinaryInputStream::GetBytes(void* ptr, size_t bytes)
|
---|
| 741 | {
|
---|
| 742 | CheckArrayTag(1, bytes, PPS_DATATYPE_CHAR);
|
---|
| 743 | GetRawBytes(ptr, bytes);
|
---|
| 744 | }
|
---|
[3750] | 745 |
|
---|
[2475] | 746 | void
|
---|
| 747 | PPFBinaryInputStream::GetR4 (r_4& result)
|
---|
| 748 | {
|
---|
| 749 | CheckTag(4,PPS_DATATYPE_FLOAT);
|
---|
| 750 | GetRawBytes(&result, sizeof(r_4));
|
---|
| 751 | if (bigEndian != IS_BIG_ENDIAN)
|
---|
| 752 | bswap4(&result);
|
---|
| 753 | }
|
---|
| 754 |
|
---|
| 755 |
|
---|
| 756 | void
|
---|
| 757 | PPFBinaryInputStream::GetR4s (r_4* tab, size_t n)
|
---|
| 758 | {
|
---|
| 759 | CheckArrayTag(4,n,PPS_DATATYPE_FLOAT);
|
---|
| 760 | GetRawBytes(tab, n*sizeof(r_4));
|
---|
| 761 | if (bigEndian == IS_BIG_ENDIAN) return;
|
---|
| 762 |
|
---|
[3750] | 763 | for (size_t i=0; i<n; i++) bswap4(tab+i);
|
---|
[2475] | 764 |
|
---|
| 765 | return;
|
---|
| 766 | }
|
---|
| 767 |
|
---|
| 768 | void
|
---|
| 769 | PPFBinaryInputStream::GetR8 (r_8& result)
|
---|
| 770 | {
|
---|
| 771 | CheckTag(8,PPS_DATATYPE_FLOAT);
|
---|
| 772 | GetRawBytes(&result, sizeof(r_8));
|
---|
| 773 | if (bigEndian != IS_BIG_ENDIAN)
|
---|
| 774 | bswap8(&result);
|
---|
| 775 | }
|
---|
| 776 |
|
---|
| 777 | void
|
---|
| 778 | PPFBinaryInputStream::GetR8s (r_8* tab, size_t n)
|
---|
| 779 | {
|
---|
| 780 | CheckArrayTag(8,n,PPS_DATATYPE_FLOAT);
|
---|
| 781 | GetRawBytes(tab, n*sizeof(r_8));
|
---|
| 782 | if (bigEndian == IS_BIG_ENDIAN) return;
|
---|
| 783 |
|
---|
[3750] | 784 | for (size_t i=0; i<n; i++) bswap8(tab+i);
|
---|
[2475] | 785 |
|
---|
| 786 | return;
|
---|
| 787 | }
|
---|
| 788 |
|
---|
| 789 | void
|
---|
| 790 | PPFBinaryInputStream::GetI1 (int_1& result)
|
---|
| 791 | {
|
---|
| 792 | CheckTag(1,PPS_DATATYPE_INTEGER);
|
---|
| 793 | GetRawBytes(&result, sizeof(int_1));
|
---|
| 794 | }
|
---|
| 795 |
|
---|
| 796 | void
|
---|
| 797 | PPFBinaryInputStream::GetI1s (int_1* tab, size_t n)
|
---|
| 798 | {
|
---|
| 799 | CheckArrayTag(1,n,PPS_DATATYPE_INTEGER);
|
---|
| 800 | GetRawBytes(tab, n*sizeof(int_1));
|
---|
| 801 | }
|
---|
| 802 |
|
---|
| 803 | void
|
---|
| 804 | PPFBinaryInputStream::GetU1 (uint_1& result)
|
---|
| 805 | {
|
---|
| 806 | CheckTag(1,PPS_DATATYPE_UNSIGNED);
|
---|
| 807 | GetRawBytes(&result, sizeof(uint_1));
|
---|
| 808 | }
|
---|
| 809 |
|
---|
| 810 | void
|
---|
| 811 | PPFBinaryInputStream::GetU1s (uint_1* tab, size_t n)
|
---|
| 812 | {
|
---|
| 813 | CheckArrayTag(1,n,PPS_DATATYPE_UNSIGNED);
|
---|
| 814 | GetRawBytes(tab, n*sizeof(uint_1));
|
---|
| 815 | }
|
---|
| 816 |
|
---|
| 817 | void
|
---|
| 818 | PPFBinaryInputStream::GetI2 (int_2& result)
|
---|
| 819 | {
|
---|
| 820 | CheckTag(2,PPS_DATATYPE_INTEGER);
|
---|
| 821 | GetRawBytes(&result, sizeof(int_2));
|
---|
| 822 | if (bigEndian != IS_BIG_ENDIAN)
|
---|
| 823 | bswap2(&result);
|
---|
| 824 | }
|
---|
| 825 |
|
---|
| 826 | void
|
---|
| 827 | PPFBinaryInputStream::GetI2s (int_2* tab, size_t n)
|
---|
| 828 | {
|
---|
| 829 | CheckArrayTag(2,n,PPS_DATATYPE_INTEGER);
|
---|
| 830 | GetRawBytes(tab, n*sizeof(int_2));
|
---|
| 831 | if (bigEndian == IS_BIG_ENDIAN) return;
|
---|
| 832 |
|
---|
[3750] | 833 | for (size_t i=0; i<n; i++) bswap2(tab+i);
|
---|
[2475] | 834 |
|
---|
| 835 | return;
|
---|
| 836 | }
|
---|
| 837 |
|
---|
| 838 | void
|
---|
| 839 | PPFBinaryInputStream::GetU2 (uint_2& result)
|
---|
| 840 | {
|
---|
| 841 | CheckTag(2,PPS_DATATYPE_UNSIGNED);
|
---|
| 842 | GetRawBytes(&result, sizeof(uint_2));
|
---|
| 843 | if (bigEndian != IS_BIG_ENDIAN)
|
---|
| 844 | bswap2(&result);
|
---|
| 845 | }
|
---|
| 846 |
|
---|
| 847 | void
|
---|
| 848 | PPFBinaryInputStream::GetU2s (uint_2* tab, size_t n)
|
---|
| 849 | {
|
---|
| 850 | CheckArrayTag(2,n,PPS_DATATYPE_UNSIGNED);
|
---|
| 851 | GetRawBytes(tab, n*sizeof(uint_2));
|
---|
| 852 | if (bigEndian == IS_BIG_ENDIAN) return;
|
---|
| 853 |
|
---|
[3750] | 854 | for (size_t i=0; i<n; i++) bswap2(tab+i);
|
---|
[2475] | 855 |
|
---|
| 856 | return;
|
---|
| 857 | }
|
---|
| 858 |
|
---|
| 859 | void
|
---|
| 860 | PPFBinaryInputStream::GetI4 (int_4& result)
|
---|
| 861 | {
|
---|
| 862 | CheckTag(4,PPS_DATATYPE_INTEGER);
|
---|
| 863 | GetRawBytes(&result, sizeof(int_4));
|
---|
| 864 | if (bigEndian != IS_BIG_ENDIAN)
|
---|
| 865 | bswap4(&result);
|
---|
| 866 | }
|
---|
| 867 |
|
---|
| 868 | void
|
---|
| 869 | PPFBinaryInputStream::GetI4s (int_4* tab, size_t n)
|
---|
| 870 | {
|
---|
| 871 | CheckArrayTag(4,n,PPS_DATATYPE_INTEGER);
|
---|
| 872 | GetRawBytes(tab, n*sizeof(int_4));
|
---|
| 873 | if (bigEndian == IS_BIG_ENDIAN) return;
|
---|
| 874 |
|
---|
[3750] | 875 | for (size_t i=0; i<n; i++) bswap4(tab+i);
|
---|
[2475] | 876 |
|
---|
| 877 | return;
|
---|
| 878 | }
|
---|
| 879 |
|
---|
| 880 | void
|
---|
| 881 | PPFBinaryInputStream::GetU4 (uint_4& result)
|
---|
| 882 | {
|
---|
| 883 | CheckTag(4,PPS_DATATYPE_UNSIGNED);
|
---|
| 884 | GetRawBytes(&result, sizeof(uint_4));
|
---|
| 885 | if (bigEndian != IS_BIG_ENDIAN)
|
---|
| 886 | bswap4(&result);
|
---|
| 887 | }
|
---|
| 888 |
|
---|
| 889 | void
|
---|
| 890 | PPFBinaryInputStream::GetU4s (uint_4* tab, size_t n)
|
---|
| 891 | {
|
---|
| 892 | CheckArrayTag(4,n,PPS_DATATYPE_UNSIGNED);
|
---|
| 893 | GetRawBytes(tab, n*sizeof(uint_4));
|
---|
| 894 | if (bigEndian == IS_BIG_ENDIAN) return;
|
---|
| 895 |
|
---|
[3750] | 896 | for (size_t i=0; i<n; i++) bswap4(tab+i);
|
---|
[2475] | 897 |
|
---|
| 898 | return;
|
---|
| 899 | }
|
---|
| 900 |
|
---|
| 901 |
|
---|
| 902 | void
|
---|
| 903 | PPFBinaryInputStream::GetI8 (int_8& result)
|
---|
| 904 | {
|
---|
| 905 | CheckTag(8,PPS_DATATYPE_INTEGER);
|
---|
| 906 | GetRawBytes(&result, sizeof(int_8));
|
---|
| 907 | if (bigEndian != IS_BIG_ENDIAN)
|
---|
| 908 | bswap8(&result);
|
---|
| 909 | }
|
---|
| 910 |
|
---|
| 911 | void
|
---|
| 912 | PPFBinaryInputStream::GetI8s (int_8* tab, size_t n)
|
---|
| 913 | {
|
---|
| 914 | CheckArrayTag(8,n,PPS_DATATYPE_INTEGER);
|
---|
| 915 | GetRawBytes(tab, n*sizeof(int_8));
|
---|
| 916 | if (bigEndian == IS_BIG_ENDIAN) return;
|
---|
| 917 |
|
---|
[3750] | 918 | for (size_t i=0; i<n; i++) bswap8(tab+i);
|
---|
[2475] | 919 |
|
---|
| 920 | return;
|
---|
| 921 | }
|
---|
| 922 |
|
---|
| 923 | void
|
---|
| 924 | PPFBinaryInputStream::GetU8 (uint_8& result)
|
---|
| 925 | {
|
---|
| 926 | CheckTag(8,PPS_DATATYPE_UNSIGNED);
|
---|
| 927 | GetRawBytes(&result, sizeof(uint_8));
|
---|
| 928 | if (bigEndian != IS_BIG_ENDIAN)
|
---|
| 929 | bswap8(&result);
|
---|
| 930 | }
|
---|
| 931 |
|
---|
| 932 | void
|
---|
| 933 | PPFBinaryInputStream::GetU8s (uint_8* tab, size_t n)
|
---|
| 934 | {
|
---|
| 935 | CheckArrayTag(8,n,PPS_DATATYPE_UNSIGNED);
|
---|
| 936 | GetRawBytes(tab, n*sizeof(uint_8));
|
---|
| 937 | if (bigEndian == IS_BIG_ENDIAN) return;
|
---|
| 938 |
|
---|
[3750] | 939 | for (size_t i=0; i<n; i++) bswap8(tab+i);
|
---|
[2475] | 940 |
|
---|
| 941 | return;
|
---|
| 942 | }
|
---|
| 943 |
|
---|
| 944 |
|
---|
| 945 | void
|
---|
| 946 | PPFBinaryInputStream::GetLine(char* ptr, size_t len)
|
---|
| 947 | {
|
---|
| 948 | string str;
|
---|
| 949 | GetStr(str);
|
---|
| 950 | strncpy(ptr, str.c_str(), len);
|
---|
| 951 | ptr[len] = '\0';
|
---|
| 952 | }
|
---|
| 953 |
|
---|
| 954 | void
|
---|
| 955 | PPFBinaryInputStream::GetStr(string& str)
|
---|
| 956 | {
|
---|
| 957 | unsigned char ppstype;
|
---|
| 958 | GetTypeTag(ppstype);
|
---|
| 959 | if (ppstype != PPS_STRING)
|
---|
| 960 | throw FileFormatExc("PPFBinaryInputStream::GetStr bad type in ppersist file");
|
---|
| 961 | int_4 len;
|
---|
| 962 | GetRawI4(len);
|
---|
| 963 | char * buff = new char[len+1];
|
---|
| 964 | GetRawBytes(buff, len);
|
---|
| 965 | buff[len] = '\0';
|
---|
| 966 | str = buff;
|
---|
| 967 | delete[] buff;
|
---|
| 968 | }
|
---|
| 969 |
|
---|
| 970 | void
|
---|
| 971 | PPFBinaryInputStream::GetZ4 (complex<r_4>& result)
|
---|
| 972 | {
|
---|
| 973 | CheckTag(4,PPS_DATATYPE_COMPLEX);
|
---|
| 974 | r_4 reim[2];
|
---|
| 975 | GetRawBytes(reim, 2*sizeof(r_4));
|
---|
| 976 | if (bigEndian != IS_BIG_ENDIAN) {
|
---|
| 977 | bswap4(reim);
|
---|
| 978 | bswap4(reim+1);
|
---|
| 979 | }
|
---|
| 980 | result = complex<r_4>(reim[0], reim[1]);
|
---|
| 981 | }
|
---|
| 982 |
|
---|
| 983 | void
|
---|
| 984 | PPFBinaryInputStream::GetZ4s (complex<r_4>* tab, size_t n)
|
---|
| 985 | {
|
---|
| 986 | CheckArrayTag(4,n,PPS_DATATYPE_COMPLEX);
|
---|
| 987 | GetRawBytes(tab, n*2*sizeof(r_4));
|
---|
| 988 | if (bigEndian == IS_BIG_ENDIAN) return;
|
---|
| 989 |
|
---|
| 990 | r_4 * p = (r_4 *)tab;
|
---|
[3750] | 991 | for (size_t i=0; i<n; i++) {
|
---|
[2475] | 992 | bswap4(p); p++;
|
---|
| 993 | bswap4(p); p++;
|
---|
| 994 | }
|
---|
| 995 | return;
|
---|
| 996 | }
|
---|
| 997 |
|
---|
| 998 | void
|
---|
| 999 | PPFBinaryInputStream::GetZ8 (complex<r_8>& result)
|
---|
| 1000 | {
|
---|
| 1001 | CheckTag(8,PPS_DATATYPE_COMPLEX);
|
---|
| 1002 | r_8 reim[2];
|
---|
| 1003 | GetRawBytes(reim, 2*sizeof(r_8));
|
---|
| 1004 | if (bigEndian != IS_BIG_ENDIAN) {
|
---|
| 1005 | bswap8(reim);
|
---|
| 1006 | bswap8(reim+1);
|
---|
| 1007 | }
|
---|
| 1008 | result = complex<r_8>(reim[0], reim[1]);
|
---|
| 1009 | }
|
---|
| 1010 |
|
---|
| 1011 | void
|
---|
| 1012 | PPFBinaryInputStream::GetZ8s (complex<r_8>* tab, size_t n)
|
---|
| 1013 | {
|
---|
| 1014 | CheckArrayTag(8,n,PPS_DATATYPE_COMPLEX);
|
---|
| 1015 | GetRawBytes(tab, n*2*sizeof(r_8));
|
---|
| 1016 | if (bigEndian == IS_BIG_ENDIAN) return;
|
---|
| 1017 |
|
---|
| 1018 | r_8 * p = (r_8 *)tab;
|
---|
[3750] | 1019 | for (size_t i=0; i<n; i++) {
|
---|
[2475] | 1020 | bswap8(p); p++;
|
---|
| 1021 | bswap8(p); p++;
|
---|
| 1022 | }
|
---|
| 1023 | return;
|
---|
| 1024 | }
|
---|
| 1025 |
|
---|
[3750] | 1026 | // Support pour les long double (128 bits floating point numbers)
|
---|
| 1027 | #ifdef SO_LDBLE128
|
---|
| 1028 | void
|
---|
| 1029 | PPFBinaryInputStream::GetR16 (r_16& result)
|
---|
| 1030 | {
|
---|
| 1031 | CheckTag(16,PPS_DATATYPE_FLOAT);
|
---|
| 1032 | GetRawBytes(&result, sizeof(r_16));
|
---|
| 1033 | if (bigEndian != IS_BIG_ENDIAN)
|
---|
| 1034 | bswap16(&result);
|
---|
| 1035 | }
|
---|
[2475] | 1036 |
|
---|
| 1037 | void
|
---|
[3750] | 1038 | PPFBinaryInputStream::GetR16s (r_16* tab, size_t n)
|
---|
| 1039 | {
|
---|
| 1040 | CheckArrayTag(16,n,PPS_DATATYPE_FLOAT);
|
---|
| 1041 | GetRawBytes(tab, n*sizeof(r_16));
|
---|
| 1042 | if (bigEndian == IS_BIG_ENDIAN) return;
|
---|
| 1043 |
|
---|
| 1044 | for (size_t i=0; i<n; i++) bswap16(tab+i);
|
---|
| 1045 |
|
---|
| 1046 | return;
|
---|
| 1047 | }
|
---|
| 1048 |
|
---|
| 1049 | void
|
---|
| 1050 | PPFBinaryInputStream::GetZ16 (complex<r_16>& result)
|
---|
| 1051 | {
|
---|
| 1052 | CheckTag(16,PPS_DATATYPE_COMPLEX);
|
---|
| 1053 | r_16 reim[2];
|
---|
| 1054 | GetRawBytes(reim, 2*sizeof(r_16));
|
---|
| 1055 | if (bigEndian != IS_BIG_ENDIAN) {
|
---|
| 1056 | bswap16(reim);
|
---|
| 1057 | bswap16(reim+1);
|
---|
| 1058 | }
|
---|
| 1059 | result = complex<r_16>(reim[0], reim[1]);
|
---|
| 1060 | }
|
---|
| 1061 |
|
---|
| 1062 | void
|
---|
| 1063 | PPFBinaryInputStream::GetZ16s (complex<r_16>* tab, size_t n)
|
---|
| 1064 | {
|
---|
| 1065 | CheckArrayTag(16,n,PPS_DATATYPE_COMPLEX);
|
---|
| 1066 | GetRawBytes(tab, n*2*sizeof(r_16));
|
---|
| 1067 | if (bigEndian == IS_BIG_ENDIAN) return;
|
---|
| 1068 |
|
---|
| 1069 | r_16 * p = (r_16 *)tab;
|
---|
| 1070 | for (size_t i=0; i<n; i++) {
|
---|
| 1071 | bswap16(p); p++;
|
---|
| 1072 | bswap16(p); p++;
|
---|
| 1073 | }
|
---|
| 1074 | return;
|
---|
| 1075 | }
|
---|
| 1076 | #endif
|
---|
| 1077 |
|
---|
| 1078 | void
|
---|
[2475] | 1079 | PPFBinaryInputStream::GetPosTagTable(int_8* ptab, size_t sz)
|
---|
| 1080 | {
|
---|
| 1081 | unsigned char ppstype;
|
---|
| 1082 | GetTypeTag(ppstype);
|
---|
| 1083 | if (ppstype != PPS_POSTAG_TABLE)
|
---|
| 1084 | throw FileFormatExc("PPFBinaryInputStream::GetPosTagTable bad type in ppersist stream");
|
---|
| 1085 | int_4 tsz;
|
---|
| 1086 | GetRawI4(tsz);
|
---|
[3572] | 1087 | if (tsz != (int_4)sz)
|
---|
[2475] | 1088 | throw FileFormatExc("PPFBinaryInputStream::GetPosTagTable Size mismatch ");
|
---|
| 1089 | for(int kk=0; kk<tsz; kk++)
|
---|
| 1090 | GetRawI8(ptab[kk]);
|
---|
| 1091 | return;
|
---|
| 1092 | }
|
---|
| 1093 |
|
---|
| 1094 | void
|
---|
| 1095 | PPFBinaryInputStream::GetPosTagTable(vector<int_8>& ptab)
|
---|
| 1096 | {
|
---|
| 1097 | unsigned char ppstype;
|
---|
| 1098 | GetTypeTag(ppstype);
|
---|
| 1099 | if (ppstype != PPS_POSTAG_TABLE)
|
---|
| 1100 | throw FileFormatExc("PPFBinaryInputStream::GetPosTagTable bad type in ppersist stream");
|
---|
| 1101 | ptab.clear();
|
---|
| 1102 | int_4 tsz;
|
---|
| 1103 | GetRawI4(tsz);
|
---|
| 1104 | int_8 tpos;
|
---|
| 1105 | for(int kk=0; kk<tsz; kk++) {
|
---|
| 1106 | GetRawI8(tpos);
|
---|
| 1107 | ptab.push_back(tpos);
|
---|
| 1108 | }
|
---|
| 1109 | return;
|
---|
| 1110 | }
|
---|
| 1111 |
|
---|
[2805] | 1112 | /*! Scans the streams and prints in text format to standard output (cout) the PPF
|
---|
| 1113 | stream content.
|
---|
| 1114 | \param lev : print level (level of details) = 0,1,2,3
|
---|
| 1115 | */
|
---|
[2475] | 1116 | void
|
---|
| 1117 | PPFBinaryInputStream::AnalyseTags(int lev)
|
---|
| 1118 | {
|
---|
| 1119 | unsigned char ppstag=0;
|
---|
| 1120 | unsigned char ppst1,ppst2,ppst3,ppst30;
|
---|
| 1121 | int_8 cpos,fsize;
|
---|
| 1122 | uint_8 ui8,cid,oid;
|
---|
| 1123 | int_4 i4;
|
---|
| 1124 | int_8 i8;
|
---|
| 1125 | char * buff;
|
---|
| 1126 | string str;
|
---|
[2660] | 1127 | // Pour indenter lors de l'impression
|
---|
| 1128 | #define _MXINDENT_ 10
|
---|
[3572] | 1129 | const char * indents[_MXINDENT_+1] = {""," ", " ", " ", " ", " ",
|
---|
[2660] | 1130 | " ", " ", " ",
|
---|
| 1131 | " ", " "};
|
---|
| 1132 | int idxindent = 0;
|
---|
| 1133 | int idxind = 0;
|
---|
[2475] | 1134 | cout << "\n ---------------------------------------------------------- " << endl;
|
---|
| 1135 | cout << " PPFBinaryInputStream::AnalyseTags(Level= " << lev << ")" << endl;
|
---|
| 1136 |
|
---|
| 1137 |
|
---|
| 1138 | cpos = s->tellg();
|
---|
| 1139 | s->seekg(0,ios::end);
|
---|
| 1140 | fsize = s->tellg();
|
---|
| 1141 | s->seekg(cpos,ios::beg);
|
---|
| 1142 |
|
---|
[2477] | 1143 | cout << " FileName= " << FileName() << endl;
|
---|
[2475] | 1144 | cout << " Version= " << Version() << " FileSize= " << fsize
|
---|
| 1145 | << " Creation Date= " << CreationDateStr() << endl;
|
---|
[2477] | 1146 | cout << " NbPosTag=" << NbPosTags() << " NbNameTag=" << tags.size()
|
---|
| 1147 | << " NbObjs=" << NbObjects() << " NbTopLevObjs=" << NbTopLevelObjects()
|
---|
[2482] | 1148 | << " NbRefs=" << NbReferences() << " MaxNest=" << MaxNestedObjsLevel()
|
---|
[2477] | 1149 | << endl << endl;
|
---|
| 1150 |
|
---|
[2475] | 1151 | uint_8 totntags = 0;
|
---|
| 1152 | bool eofok = false;
|
---|
| 1153 |
|
---|
| 1154 | while ( (ppstag != PPS_EOF) && (cpos < fsize) ) {
|
---|
| 1155 | cpos = s->tellg();
|
---|
| 1156 | GetRawUByte(ppstag);
|
---|
| 1157 | totntags++;
|
---|
| 1158 |
|
---|
| 1159 | ppst1 = ppstag&0x0f; // bits 0123
|
---|
| 1160 | ppst2 = ppstag&0x30; // bits 45
|
---|
| 1161 | ppst3 = ppstag&0xc0; // bits 67
|
---|
| 1162 | ppst30 = ppstag&0xc1; // bits 0 67
|
---|
| 1163 | if ((ppst2 == 0) && (ppst3 == 0) ) {
|
---|
| 1164 | switch (ppst1) {
|
---|
| 1165 |
|
---|
| 1166 | case PPS_NULL :
|
---|
[2660] | 1167 | if (lev > 1) cout << indents[idxindent]
|
---|
| 1168 | << "<PPS_NULL> tag at position " << hex << cpos << dec << endl;
|
---|
[2475] | 1169 | break;
|
---|
| 1170 |
|
---|
| 1171 | case PPS_STRING :
|
---|
| 1172 | GetRawI4(i4);
|
---|
[2660] | 1173 | if (lev > 1) cout << indents[idxindent]
|
---|
| 1174 | << "<PPS_STRING> tag at position " << hex << cpos << dec
|
---|
[2475] | 1175 | << " Length=" << i4 << endl;
|
---|
| 1176 | s->seekg(i4,ios::cur);
|
---|
| 1177 | break;
|
---|
| 1178 |
|
---|
| 1179 | case PPS_OBJECT :
|
---|
| 1180 | GetRawU8(cid);
|
---|
| 1181 | GetRawU8(oid);
|
---|
[2660] | 1182 | cout << indents[idxindent]
|
---|
| 1183 | << "<PPS_OBJECT> tag at position " << hex << cpos << " ClassId= " << cid
|
---|
[2475] | 1184 | << " ObjectId= " << oid << dec << endl;
|
---|
[2660] | 1185 | idxind++;
|
---|
| 1186 | idxindent = (idxind <= _MXINDENT_) ? idxind : _MXINDENT_;
|
---|
[2475] | 1187 | break;
|
---|
| 1188 |
|
---|
| 1189 | case PPS_REFERENCE :
|
---|
| 1190 | GetRawU8(oid);
|
---|
| 1191 | GetRawI8(i8);
|
---|
[2660] | 1192 | cout << indents[idxindent]
|
---|
| 1193 | << "<PPS_REFERENCE> tag at position " << hex << cpos << " ObjectId= "
|
---|
[2475] | 1194 | << oid << " OrigPos=" << i8 << dec << endl;
|
---|
| 1195 | break;
|
---|
| 1196 |
|
---|
| 1197 | case PPS_NAMETAG_MARK :
|
---|
[2660] | 1198 | cout << indents[idxindent]
|
---|
| 1199 | << "<PPS_NAMETAG_MARK> tag at position " << hex << cpos << dec << endl;
|
---|
[2475] | 1200 | break;
|
---|
| 1201 |
|
---|
| 1202 | case PPS_POSTAG_MARK :
|
---|
| 1203 | GetRawI8(i8);
|
---|
[2660] | 1204 | cout << indents[idxindent]
|
---|
| 1205 | << "<PPS_POSTAG_MARK> tag at position " << hex << cpos
|
---|
[2475] | 1206 | << " TPos=" << i8 << dec << endl;
|
---|
| 1207 | break;
|
---|
| 1208 |
|
---|
| 1209 | case PPS_ENDOBJECT :
|
---|
| 1210 | GetRawU8(oid);
|
---|
[2664] | 1211 | idxind--;
|
---|
| 1212 | idxindent = (idxind >= 0) ? idxind : 0;
|
---|
[2660] | 1213 | cout << indents[idxindent]
|
---|
| 1214 | << "<PPS_ENDOBJECT> tag at position " << hex << cpos << " ObjectId= "
|
---|
[2475] | 1215 | << oid << dec << endl;
|
---|
| 1216 | break;
|
---|
| 1217 |
|
---|
| 1218 | case PPS_POSTAG_TABLE :
|
---|
| 1219 | GetRawI4(i4);
|
---|
| 1220 | for(int kkt=0; kkt<i4; kkt++) GetRawI8(i8);
|
---|
[2660] | 1221 | cout << indents[idxindent]
|
---|
| 1222 | << "<PPS_POSTAG_TABLE> tag at position " << hex << cpos << dec << endl;
|
---|
[2475] | 1223 | break;
|
---|
| 1224 |
|
---|
| 1225 | case PPS_NAMETAG_TABLE :
|
---|
[2477] | 1226 | if (Version() < 3) {
|
---|
| 1227 | GetRawI8(i8);
|
---|
| 1228 | GetRawI4(i4);
|
---|
| 1229 | buff = new char[i4+1];
|
---|
| 1230 | GetRawBytes(buff, i4);
|
---|
| 1231 | buff[i4] = '\0'; str = buff;
|
---|
| 1232 | delete[] buff;
|
---|
[2660] | 1233 | cout << indents[idxindent]
|
---|
| 1234 | << "<PPS_NAMETAG_TABLE> tag at position " << hex << cpos << dec
|
---|
[2477] | 1235 | << " Name= " << str << endl;
|
---|
| 1236 | }
|
---|
| 1237 | else {
|
---|
[2660] | 1238 | cout << indents[idxindent]
|
---|
| 1239 | << "<PPS_NAMETAG_TABLE> tag at position " << hex << cpos << dec << endl;
|
---|
[2482] | 1240 | int_8 stats[8];
|
---|
| 1241 | GetI8s(stats,8);
|
---|
| 1242 | GetRawU8(ui8); // nb de nametag
|
---|
[3572] | 1243 | for(uint_8 kt=0; kt<ui8; kt++) {
|
---|
[2477] | 1244 | string tname;
|
---|
[2482] | 1245 | GetRawI8(i8);
|
---|
[2477] | 1246 | GetStr(tname);
|
---|
| 1247 | if (lev > 0)
|
---|
| 1248 | cout << "<PPS_NAMETAG_ENTRY> NameTag=" << tname
|
---|
| 1249 | << " NameTagMark Position=" << hex << i8 << dec << endl;
|
---|
| 1250 | }
|
---|
| 1251 | GetRawI8(i8); // position debut NameTagTable
|
---|
| 1252 | }
|
---|
[2475] | 1253 | break;
|
---|
| 1254 |
|
---|
| 1255 | case PPS_EOF :
|
---|
[2477] | 1256 | if (Version() < 3) GetRawI8(i8);
|
---|
[2660] | 1257 | cout << indents[idxindent]
|
---|
| 1258 | << "<PPS_EOF> tag at position " << hex << cpos
|
---|
[2475] | 1259 | << " TagPos=" << i8 << dec << endl;
|
---|
| 1260 | eofok = true;
|
---|
| 1261 | break;
|
---|
| 1262 |
|
---|
| 1263 | default :
|
---|
| 1264 | cerr << " ERROR : Unexpected tag value " << hex << ppstag
|
---|
| 1265 | << " At position" << cpos << dec << endl;
|
---|
| 1266 | throw FileFormatExc("PPFBinaryInputStream::AnalyseTags() - Unexpected tag value !");
|
---|
| 1267 | }
|
---|
| 1268 | }
|
---|
| 1269 | else {
|
---|
| 1270 | string dtype = "???? x";
|
---|
| 1271 | if (ppst30 == PPS_DATATYPE_COMPLEX) dtype = "COMPLEX x";
|
---|
| 1272 | else if (ppst3 == PPS_DATATYPE_CHAR) dtype = "CHAR x";
|
---|
| 1273 | else if (ppst3 == PPS_DATATYPE_FLOAT) dtype = "FLOAT x";
|
---|
| 1274 | else if (ppst3 == PPS_DATATYPE_INTEGER) dtype = "INTEGER x";
|
---|
| 1275 | else if (ppst3 == PPS_DATATYPE_UNSIGNED) dtype = "UNSIGNED x";
|
---|
[3750] | 1276 | int_4 dsize = (int_4)tagsize2datasize(ppst1);
|
---|
[2477] | 1277 | int_8 dsizeskip = dsize;
|
---|
[2475] | 1278 | if (ppst30 == PPS_DATATYPE_COMPLEX) {
|
---|
| 1279 | dsize--;
|
---|
| 1280 | dsizeskip = 2*dsize;
|
---|
| 1281 | }
|
---|
| 1282 | char sb[16];
|
---|
| 1283 | sprintf(sb, "%d", dsize);
|
---|
| 1284 | dtype += sb;
|
---|
| 1285 |
|
---|
| 1286 | switch (ppst2) {
|
---|
| 1287 |
|
---|
| 1288 | case PPS_SIMPLE :
|
---|
[2660] | 1289 | if (lev > 2) cout << indents[idxindent]
|
---|
| 1290 | << "<PPS_SIMPLE> tag at position " << hex << cpos << dec
|
---|
[2475] | 1291 | << " DataType=" << dtype << endl;
|
---|
| 1292 | s->seekg(dsizeskip, ios::cur);
|
---|
| 1293 | break;
|
---|
| 1294 |
|
---|
| 1295 | case PPS_SIMPLE_ARRAY4 :
|
---|
| 1296 | GetRawI4(i4);
|
---|
[2660] | 1297 | if (lev > 0) cout << indents[idxindent]
|
---|
| 1298 | << "<PPS_SIMPLE_ARRAY4> tag at position " << hex << cpos << dec
|
---|
[2475] | 1299 | << " DataType=" << dtype << " NElts= " << i4 << endl;
|
---|
[2477] | 1300 | s->seekg(dsizeskip*(int_8)i4, ios::cur);
|
---|
[2475] | 1301 | break;
|
---|
| 1302 |
|
---|
| 1303 | case PPS_SIMPLE_ARRAY8 :
|
---|
| 1304 | GetRawU8(ui8);
|
---|
[2660] | 1305 | if (lev > 0) cout << indents[idxindent]
|
---|
| 1306 | << "<PPS_SIMPLE_ARRAY8> tag at position " << hex << cpos << dec
|
---|
[2475] | 1307 | << " DataType=" << dtype << " NElts= " << ui8 << endl;
|
---|
[2477] | 1308 | s->seekg(dsizeskip*ui8, ios::cur);
|
---|
[2475] | 1309 | break;
|
---|
| 1310 | }
|
---|
| 1311 | }
|
---|
| 1312 | }
|
---|
| 1313 | if (!eofok)
|
---|
| 1314 | throw FileFormatExc("PPFBinaryInputStream::AnalyseTags() - Not found <PPS_EOF> tag ");
|
---|
| 1315 |
|
---|
| 1316 | cout << " PPFBinaryInputStream::AnalyseTags() - End - Total Number of Tags= " << totntags << endl;
|
---|
| 1317 | cout << " ---------------------------------------------------------- \n" << endl;
|
---|
| 1318 | return;
|
---|
| 1319 | }
|
---|
| 1320 |
|
---|
| 1321 |
|
---|
[2477] | 1322 | //-------------------------------------------------------------------------
|
---|
| 1323 | //------------------- Classe PPFBinaryOutputStream -----------------------
|
---|
| 1324 | //-------------------------------------------------------------------------
|
---|
| 1325 |
|
---|
| 1326 |
|
---|
[2805] | 1327 | /*!
|
---|
| 1328 | \class SOPHYA::PPFBinaryInputStream
|
---|
| 1329 | \ingroup BaseTools
|
---|
| 1330 | PPF output stream implementing write operations. The byte-ordering (endianess)
|
---|
| 1331 | of the output stream can be selected at creation. By default, the native endianness
|
---|
| 1332 | of the machine is used.
|
---|
| 1333 | */
|
---|
| 1334 |
|
---|
| 1335 | /*! Constructor from a RawInOutStream pointer
|
---|
| 1336 | \param os : pointer to RawInOutStream
|
---|
| 1337 | \param ad : if true, the RawInOutStream \b os is deleted by the destructor
|
---|
| 1338 | \param endianness : Endianness selector PPS_NATIVE PPS_LITTLE_ENDIAN PPS_BIG_ENDIAN
|
---|
| 1339 | */
|
---|
[2476] | 1340 | PPFBinaryOutputStream::PPFBinaryOutputStream(RawInOutStream* os, bool ad, int endianness)
|
---|
[2475] | 1341 | {
|
---|
[2476] | 1342 | s = os;
|
---|
| 1343 | _ads = ad;
|
---|
| 1344 | Init(endianness);
|
---|
[2475] | 1345 | }
|
---|
| 1346 |
|
---|
[2805] | 1347 | /*! Constructor
|
---|
| 1348 | \param flnm : output file name
|
---|
| 1349 | \param endianness : Endianness selector PPS_NATIVE PPS_LITTLE_ENDIAN PPS_BIG_ENDIAN
|
---|
| 1350 | */
|
---|
[2475] | 1351 | PPFBinaryOutputStream::PPFBinaryOutputStream(string const& flnm, int endianness)
|
---|
| 1352 | {
|
---|
[2476] | 1353 | // Output stream creation
|
---|
| 1354 | s = new RawOutFileStream(flnm.c_str());
|
---|
| 1355 | _ads = true;
|
---|
| 1356 | Init(endianness);
|
---|
| 1357 | }
|
---|
| 1358 |
|
---|
| 1359 | PPFBinaryOutputStream::~PPFBinaryOutputStream()
|
---|
| 1360 | {
|
---|
| 1361 | WriteNameTagTable();
|
---|
| 1362 | if (_ads && (s != NULL)) delete s; // Close the stream
|
---|
| 1363 | }
|
---|
| 1364 |
|
---|
| 1365 | void
|
---|
| 1366 | PPFBinaryOutputStream::Init(int endianness)
|
---|
| 1367 | {
|
---|
[2475] | 1368 | if (endianness == -1)
|
---|
| 1369 | bigEndian = IS_BIG_ENDIAN;
|
---|
| 1370 | else
|
---|
| 1371 | bigEndian = endianness;
|
---|
| 1372 |
|
---|
| 1373 | version = 3;
|
---|
| 1374 | // Header
|
---|
[3750] | 1375 | PutRawBytes("SOS-SOPHYA-PPersistFile V4 ",32);
|
---|
[2475] | 1376 | PutRawBytes(bigEndian
|
---|
| 1377 | ? "BIG-ENDIAN "
|
---|
| 1378 | : "LITTLE-ENDIAN ",32);
|
---|
| 1379 |
|
---|
| 1380 | // ---- GMT creation date of the file
|
---|
| 1381 | time_t tm = time(NULL);
|
---|
[2477] | 1382 | creationdate = tm;
|
---|
[2475] | 1383 | char datestring[33];
|
---|
| 1384 | int l=strftime(datestring,32,"%d/%m/%Y %H:%M:%S GMT",gmtime(&tm));
|
---|
| 1385 | for(int i=l; i<32; i++) datestring[i] = ' ';
|
---|
| 1386 | datestring[32] = '\0';
|
---|
| 1387 | PutRawBytes(datestring, 32);
|
---|
| 1388 | }
|
---|
| 1389 |
|
---|
[2476] | 1390 | void
|
---|
| 1391 | PPFBinaryOutputStream::WriteNameTagTable()
|
---|
| 1392 | {
|
---|
[2477] | 1393 | int_8 tagPos;
|
---|
| 1394 | tagPos = s->tellp();
|
---|
| 1395 | PutRawUByte(PPS_NAMETAG_TABLE); // NameTagTable tag
|
---|
| 1396 | // Ecriture nb de PosTag et nb d'objets dans le flot
|
---|
[2482] | 1397 | int_8 stats[8] = {0,0,0,0,0,0,0,0};
|
---|
| 1398 | stats[0] = _nbpostag;
|
---|
| 1399 | stats[1] = _nbobjs;
|
---|
| 1400 | stats[2] = _nbtlobjs;
|
---|
| 1401 | stats[3] = _nbrefs;
|
---|
| 1402 | stats[4] = _maxnestlevel;
|
---|
| 1403 | PutI8s(stats, 8);
|
---|
[2477] | 1404 | // Ecriture nb de tag et les tags
|
---|
[2482] | 1405 | PutRawU8((uint_8)tags.size()); // Number of tags
|
---|
[2477] | 1406 | if (tags.size() > 0) {
|
---|
[2476] | 1407 | for (map<string,int_8>::iterator i = tags.begin(); i != tags.end(); i++) {
|
---|
| 1408 | int_8 pos = (*i).second;
|
---|
[2482] | 1409 | PutRawI8(pos);
|
---|
[2476] | 1410 | PutStr((*i).first);
|
---|
| 1411 | }
|
---|
| 1412 | }
|
---|
[2477] | 1413 | PutRawI8(tagPos);
|
---|
| 1414 | PutRawUByte(PPS_EOF);
|
---|
| 1415 | return;
|
---|
[2476] | 1416 | }
|
---|
| 1417 |
|
---|
| 1418 | void
|
---|
| 1419 | PPFBinaryOutputStream::WriteNameTagTableV2()
|
---|
[2475] | 1420 | {
|
---|
| 1421 | if (tags.size() == 0) {
|
---|
| 1422 | PutRawUByte(PPS_EOF);
|
---|
| 1423 | PutRawI8(-1);
|
---|
| 1424 | } else {
|
---|
| 1425 | int_8 tagPos;
|
---|
| 1426 | tagPos = s->tellp();
|
---|
| 1427 | for (map<string,int_8>::iterator i = tags.begin(); i != tags.end(); i++) {
|
---|
| 1428 | string name = (*i).first;
|
---|
| 1429 | int_8 pos = (*i).second;
|
---|
| 1430 | PutRawUByte(PPS_NAMETAG_TABLE); // This is a tag
|
---|
| 1431 | PutRawI8(pos); // position of previous tag
|
---|
| 1432 | PutRawI4(name.length()); // length of the name
|
---|
| 1433 | PutRawBytes(name.c_str(), name.length()); // name, without final "0".
|
---|
| 1434 | }
|
---|
| 1435 | PutRawUByte(PPS_EOF);
|
---|
| 1436 | PutRawI8(tagPos);
|
---|
| 1437 | }
|
---|
| 1438 |
|
---|
| 1439 | }
|
---|
| 1440 |
|
---|
[2476] | 1441 |
|
---|
[2475] | 1442 | int_8
|
---|
| 1443 | PPFBinaryOutputStream::WritePositionTag()
|
---|
| 1444 | {
|
---|
| 1445 | int_8 tagpos;
|
---|
| 1446 | tagpos = s->tellp();
|
---|
| 1447 | PutRawByte(PPS_POSTAG_MARK);
|
---|
[2481] | 1448 | PutRawI8(tagpos);
|
---|
[2477] | 1449 | _nbpostag++; // Compteur de nombre de tags
|
---|
[2475] | 1450 | return(tagpos);
|
---|
| 1451 | }
|
---|
| 1452 |
|
---|
| 1453 | void
|
---|
| 1454 | PPFBinaryOutputStream::WriteNameTag(string const& name)
|
---|
| 1455 | {
|
---|
| 1456 | // if (name.length() > MAXTAGLEN_V2)
|
---|
| 1457 | // throw ParmError("PPFBinaryOutputStream::WriteNameTag tag name too long");
|
---|
| 1458 |
|
---|
| 1459 | if (tags.find(name) != tags.end())
|
---|
| 1460 | throw DuplicateIdExc("PPFBinaryOutputStream::WriteNameTag duplicate tag name");
|
---|
| 1461 |
|
---|
| 1462 | // Get current file position
|
---|
| 1463 | int_8 tagPos;
|
---|
| 1464 | tagPos = s->tellp();
|
---|
| 1465 |
|
---|
| 1466 | tags[name] = tagPos;
|
---|
| 1467 | PutRawUByte(PPS_NAMETAG_MARK); // This is a tag
|
---|
| 1468 | // objList.clear(); // $CHECK$ EA 171199 - Ne pas faire ? Reza 03/2000
|
---|
| 1469 | }
|
---|
| 1470 |
|
---|
| 1471 | //++
|
---|
| 1472 | // void PPFBinaryOutputStream::PutByte(char& c)
|
---|
| 1473 | // void PPFBinaryOutputStream::PutBytes(void const* ptr, size_t bytes)
|
---|
| 1474 | // void PPFBinaryOutputStream::PutR4 (r_4 result)
|
---|
| 1475 | // void PPFBinaryOutputStream::PutR4s (r_4 const* tab, size_t n)
|
---|
| 1476 | // void PPFBinaryOutputStream::PutR8 (r_8 result)
|
---|
| 1477 | // void PPFBinaryOutputStream::PutR8s (r_8 const* tab, size_t n)
|
---|
| 1478 | // void PPFBinaryOutputStream::PutI2 (int_2 result)
|
---|
| 1479 | // void PPFBinaryOutputStream::PutI2s (int_2 const* tab, size_t n)
|
---|
| 1480 | // void PPFBinaryOutputStream::PutU2 (uint_2 result)
|
---|
| 1481 | // void PPFBinaryOutputStream::PutU2s (uint_2 const* tab, size_t n)
|
---|
| 1482 | // void PPFBinaryOutputStream::PutI4 (int_4 result)
|
---|
| 1483 | // void PPFBinaryOutputStream::PutI4s (int_4 const* tab, size_t n)
|
---|
| 1484 | // void PPFBinaryOutputStream::PutU4 (uint_4 result)
|
---|
| 1485 | // void PPFBinaryOutputStream::PutU4s (uint_4 const* tab, size_t n)
|
---|
| 1486 | // void PPFBinaryOutputStream::PutI8 (int_8 result)
|
---|
| 1487 | // void PPFBinaryOutputStream::PutI8s (int_8 const* tab, size_t n)
|
---|
| 1488 | // void PPFBinaryOutputStream::PutU8 (uint_8 result)
|
---|
| 1489 | // void PPFBinaryOutputStream::PutU8s (uint_8 const* tab, size_t n)
|
---|
| 1490 | // void PPFBinaryOutputStream::PutStr (string const&)
|
---|
| 1491 | // Ecriture de données portables.. Pour chaque type
|
---|
| 1492 | // de données, on peut écrire une valeur, ou un tableau de valeurs.
|
---|
| 1493 | // void PPFBinaryOutputStream::PutLine(char const* ptr, size_t len)
|
---|
| 1494 | // Ecriture d'une ligne de texte dans le fichier PPersist.
|
---|
| 1495 | //--
|
---|
| 1496 |
|
---|
| 1497 |
|
---|
| 1498 |
|
---|
| 1499 |
|
---|
| 1500 | void
|
---|
| 1501 | PPFBinaryOutputStream::PutRawBytes(void const* ptr, size_t bytes)
|
---|
| 1502 | {
|
---|
| 1503 | s->write((char const*)ptr, bytes);
|
---|
| 1504 | }
|
---|
| 1505 |
|
---|
| 1506 | void
|
---|
| 1507 | PPFBinaryOutputStream::PutRawByte(char c)
|
---|
| 1508 | {
|
---|
| 1509 | PutRawBytes(&c, 1);
|
---|
| 1510 | }
|
---|
| 1511 |
|
---|
| 1512 | void
|
---|
| 1513 | PPFBinaryOutputStream::PutRawUByte(unsigned char c)
|
---|
| 1514 | {
|
---|
| 1515 | PutRawBytes(&c, 1);
|
---|
| 1516 | }
|
---|
| 1517 |
|
---|
| 1518 | void
|
---|
| 1519 | PPFBinaryOutputStream::PutRawI2 (int_2 val)
|
---|
| 1520 | {
|
---|
| 1521 | if (bigEndian != IS_BIG_ENDIAN)
|
---|
| 1522 | bswap2(&val);
|
---|
| 1523 |
|
---|
| 1524 | PutRawBytes(&val, sizeof(int_2));
|
---|
| 1525 | }
|
---|
| 1526 |
|
---|
| 1527 | void
|
---|
| 1528 | PPFBinaryOutputStream::PutRawI4 (int_4 val)
|
---|
| 1529 | {
|
---|
| 1530 | if (bigEndian != IS_BIG_ENDIAN)
|
---|
| 1531 | bswap4(&val);
|
---|
| 1532 |
|
---|
| 1533 | PutRawBytes(&val, sizeof(int_4));
|
---|
| 1534 | }
|
---|
| 1535 |
|
---|
| 1536 | void
|
---|
| 1537 | PPFBinaryOutputStream::PutRawI8 (int_8 val)
|
---|
| 1538 | {
|
---|
| 1539 | if (bigEndian != IS_BIG_ENDIAN)
|
---|
| 1540 | bswap8(&val);
|
---|
| 1541 |
|
---|
| 1542 | PutRawBytes(&val, sizeof(int_8));
|
---|
| 1543 | }
|
---|
| 1544 |
|
---|
| 1545 | void
|
---|
| 1546 | PPFBinaryOutputStream::PutRawU8 (uint_8 val)
|
---|
| 1547 | {
|
---|
| 1548 | if (bigEndian != IS_BIG_ENDIAN)
|
---|
| 1549 | bswap8(&val);
|
---|
| 1550 |
|
---|
| 1551 | PutRawBytes(&val, sizeof(uint_8));
|
---|
| 1552 | }
|
---|
| 1553 |
|
---|
| 1554 | void
|
---|
[3750] | 1555 | PPFBinaryOutputStream::PutArrayTag(unsigned char datasz, size_t sz, unsigned char datatype)
|
---|
[2475] | 1556 | // datatype = PPS_DATATYPE_CHAR or PPS_DATATYPE_FLOAT or PPS_DATATYPE_INTEGER or PPS_DATATYPE_UNSIGNED
|
---|
| 1557 | {
|
---|
| 1558 | if (sz <= 0x7fffffff) {
|
---|
[3750] | 1559 | PutRawUByte(PPS_SIMPLE_ARRAY4 + datasize2tagsize(datasz) + datatype);
|
---|
[2475] | 1560 | PutRawI4(sz);
|
---|
| 1561 | } else {
|
---|
[3750] | 1562 | PutRawUByte(PPS_SIMPLE_ARRAY8 + datasize2tagsize(datasz) + datatype);
|
---|
[2475] | 1563 | PutRawU8(sz);
|
---|
| 1564 | }
|
---|
| 1565 | }
|
---|
| 1566 |
|
---|
| 1567 | void
|
---|
| 1568 | PPFBinaryOutputStream::PutByte(char c)
|
---|
| 1569 | {
|
---|
[3750] | 1570 | PutRawByte(PPS_SIMPLE + datasize2tagsize(1) + PPS_DATATYPE_CHAR);
|
---|
[2475] | 1571 | PutRawBytes(&c, 1);
|
---|
| 1572 | }
|
---|
| 1573 |
|
---|
| 1574 |
|
---|
| 1575 |
|
---|
| 1576 | void
|
---|
| 1577 | PPFBinaryOutputStream::PutBytes(void const* ptr, size_t bytes)
|
---|
| 1578 | {
|
---|
| 1579 | PutArrayTag(1, bytes, PPS_DATATYPE_CHAR);
|
---|
| 1580 | PutRawBytes(ptr, bytes);
|
---|
| 1581 | }
|
---|
| 1582 |
|
---|
| 1583 | void
|
---|
| 1584 | PPFBinaryOutputStream::PutR4 (r_4 val)
|
---|
| 1585 | {
|
---|
[3750] | 1586 | PutRawUByte(PPS_SIMPLE + datasize2tagsize(4) + PPS_DATATYPE_FLOAT);
|
---|
[2475] | 1587 |
|
---|
| 1588 | if (bigEndian != IS_BIG_ENDIAN)
|
---|
| 1589 | bswap4(&val);
|
---|
| 1590 |
|
---|
| 1591 | PutRawBytes(&val, sizeof(r_4));
|
---|
| 1592 | }
|
---|
| 1593 |
|
---|
| 1594 | void
|
---|
| 1595 | PPFBinaryOutputStream::PutR4s (r_4 const* tab, size_t n)
|
---|
| 1596 | {
|
---|
| 1597 | PutArrayTag(4, n, PPS_DATATYPE_FLOAT);
|
---|
| 1598 |
|
---|
| 1599 | if (bigEndian == IS_BIG_ENDIAN) {
|
---|
| 1600 | PutRawBytes(tab, n*sizeof(r_4));
|
---|
| 1601 | } else {
|
---|
[3750] | 1602 | for (size_t i=0; i<n; i++) {
|
---|
[2475] | 1603 | r_4 val = tab[i];
|
---|
| 1604 | bswap4(&val);
|
---|
| 1605 | PutRawBytes(&val, sizeof(r_4));
|
---|
| 1606 | }
|
---|
| 1607 | }
|
---|
| 1608 | }
|
---|
| 1609 |
|
---|
| 1610 | void
|
---|
| 1611 | PPFBinaryOutputStream::PutR8 (r_8 val)
|
---|
| 1612 | {
|
---|
[3750] | 1613 | PutRawUByte(PPS_SIMPLE + datasize2tagsize(8) + PPS_DATATYPE_FLOAT);
|
---|
[2475] | 1614 |
|
---|
| 1615 | if (bigEndian != IS_BIG_ENDIAN)
|
---|
| 1616 | bswap8(&val);
|
---|
| 1617 |
|
---|
| 1618 | PutRawBytes(&val, sizeof(r_8));
|
---|
| 1619 | }
|
---|
| 1620 |
|
---|
| 1621 | void
|
---|
| 1622 | PPFBinaryOutputStream::PutR8s (r_8 const* tab, size_t n)
|
---|
| 1623 | {
|
---|
| 1624 | PutArrayTag(8, n, PPS_DATATYPE_FLOAT);
|
---|
| 1625 |
|
---|
| 1626 | if (bigEndian == IS_BIG_ENDIAN) {
|
---|
| 1627 | PutRawBytes(tab, n*sizeof(r_8));
|
---|
| 1628 | } else {
|
---|
[3750] | 1629 | for (size_t i=0; i<n; i++) {
|
---|
[2475] | 1630 | r_8 val = tab[i];
|
---|
| 1631 | bswap8(&val);
|
---|
| 1632 | PutRawBytes(&val, sizeof(r_8));
|
---|
| 1633 | }
|
---|
| 1634 | }
|
---|
| 1635 | }
|
---|
| 1636 |
|
---|
| 1637 | void
|
---|
| 1638 | PPFBinaryOutputStream::PutI1 (int_1 val)
|
---|
| 1639 | {
|
---|
[3750] | 1640 | PutRawUByte(PPS_SIMPLE + datasize2tagsize(1) + PPS_DATATYPE_INTEGER);
|
---|
[2475] | 1641 | PutRawBytes(&val, sizeof(int_1));
|
---|
| 1642 | }
|
---|
| 1643 |
|
---|
| 1644 | void
|
---|
| 1645 | PPFBinaryOutputStream::PutI1s (int_1 const* tab, size_t n)
|
---|
| 1646 | {
|
---|
| 1647 | PutArrayTag(1, n, PPS_DATATYPE_INTEGER);
|
---|
| 1648 | PutRawBytes(tab, n*sizeof(int_1));
|
---|
| 1649 | }
|
---|
| 1650 |
|
---|
| 1651 | void
|
---|
| 1652 | PPFBinaryOutputStream::PutU1 (uint_1 val)
|
---|
| 1653 | {
|
---|
[3750] | 1654 | PutRawUByte(PPS_SIMPLE + datasize2tagsize(1) + PPS_DATATYPE_UNSIGNED);
|
---|
[2475] | 1655 | PutRawBytes(&val, sizeof(uint_1));
|
---|
| 1656 | }
|
---|
| 1657 |
|
---|
| 1658 | void
|
---|
| 1659 | PPFBinaryOutputStream::PutU1s (uint_1 const* tab, size_t n)
|
---|
| 1660 | {
|
---|
| 1661 | PutArrayTag(1, n, PPS_DATATYPE_UNSIGNED);
|
---|
| 1662 | PutRawBytes(tab, n*sizeof(uint_1));
|
---|
| 1663 | }
|
---|
| 1664 |
|
---|
| 1665 | void
|
---|
| 1666 | PPFBinaryOutputStream::PutI2 (int_2 val)
|
---|
| 1667 | {
|
---|
[3750] | 1668 | PutRawUByte(PPS_SIMPLE + datasize2tagsize(2) + PPS_DATATYPE_INTEGER);
|
---|
[2475] | 1669 |
|
---|
| 1670 | if (bigEndian != IS_BIG_ENDIAN)
|
---|
| 1671 | bswap2(&val);
|
---|
| 1672 |
|
---|
| 1673 | PutRawBytes(&val, sizeof(int_2));
|
---|
| 1674 | }
|
---|
| 1675 |
|
---|
| 1676 | void
|
---|
| 1677 | PPFBinaryOutputStream::PutI2s (int_2 const* tab, size_t n)
|
---|
| 1678 | {
|
---|
| 1679 | PutArrayTag(2, n, PPS_DATATYPE_INTEGER);
|
---|
| 1680 |
|
---|
| 1681 | if (bigEndian == IS_BIG_ENDIAN) {
|
---|
| 1682 | PutRawBytes(tab, n*sizeof(int_2));
|
---|
| 1683 | } else {
|
---|
[3750] | 1684 | for (size_t i=0; i<n; i++) {
|
---|
[2475] | 1685 | int_2 val = tab[i];
|
---|
| 1686 | bswap2(&val);
|
---|
| 1687 | PutRawBytes(&val, sizeof(int_2));
|
---|
| 1688 | }
|
---|
| 1689 | }
|
---|
| 1690 | }
|
---|
| 1691 |
|
---|
| 1692 | void
|
---|
| 1693 | PPFBinaryOutputStream::PutU2 (uint_2 val)
|
---|
| 1694 | {
|
---|
[3750] | 1695 | PutRawUByte(PPS_SIMPLE + datasize2tagsize(2) + PPS_DATATYPE_UNSIGNED);
|
---|
[2475] | 1696 |
|
---|
| 1697 | if (bigEndian != IS_BIG_ENDIAN)
|
---|
| 1698 | bswap2(&val);
|
---|
| 1699 |
|
---|
| 1700 | PutRawBytes(&val, sizeof(uint_2));
|
---|
| 1701 | }
|
---|
| 1702 |
|
---|
| 1703 | void
|
---|
| 1704 | PPFBinaryOutputStream::PutU2s (uint_2 const* tab, size_t n)
|
---|
| 1705 | {
|
---|
| 1706 | PutArrayTag(2, n, PPS_DATATYPE_UNSIGNED);
|
---|
| 1707 |
|
---|
| 1708 | if (bigEndian == IS_BIG_ENDIAN) {
|
---|
| 1709 | PutRawBytes(tab, n*sizeof(uint_2));
|
---|
| 1710 | } else {
|
---|
[3750] | 1711 | for (size_t i=0; i<n; i++) {
|
---|
[2475] | 1712 | uint_2 val = tab[i];
|
---|
| 1713 | bswap2(&val);
|
---|
| 1714 | PutRawBytes(&val, sizeof(uint_2));
|
---|
| 1715 | }
|
---|
| 1716 | }
|
---|
| 1717 | }
|
---|
| 1718 |
|
---|
| 1719 | void
|
---|
| 1720 | PPFBinaryOutputStream::PutI4 (int_4 val)
|
---|
| 1721 | {
|
---|
[3750] | 1722 | PutRawUByte(PPS_SIMPLE + datasize2tagsize(4) + PPS_DATATYPE_INTEGER);
|
---|
[2475] | 1723 |
|
---|
| 1724 | if (bigEndian != IS_BIG_ENDIAN)
|
---|
| 1725 | bswap4(&val);
|
---|
| 1726 |
|
---|
| 1727 | PutRawBytes(&val, sizeof(int_4));
|
---|
| 1728 | }
|
---|
| 1729 |
|
---|
| 1730 | void
|
---|
| 1731 | PPFBinaryOutputStream::PutI4s (int_4 const* tab, size_t n)
|
---|
| 1732 | {
|
---|
| 1733 | PutArrayTag(4, n, PPS_DATATYPE_INTEGER);
|
---|
| 1734 |
|
---|
| 1735 | if (bigEndian == IS_BIG_ENDIAN) {
|
---|
| 1736 | PutRawBytes(tab, n*sizeof(int_4));
|
---|
| 1737 | } else {
|
---|
[3750] | 1738 | for (size_t i=0; i<n; i++) {
|
---|
[2475] | 1739 | int_4 val = tab[i];
|
---|
| 1740 | bswap4(&val);
|
---|
| 1741 | PutRawBytes(&val, sizeof(int_4));
|
---|
| 1742 | }
|
---|
| 1743 | }
|
---|
| 1744 | }
|
---|
| 1745 |
|
---|
| 1746 | void
|
---|
| 1747 | PPFBinaryOutputStream::PutU4 (uint_4 val)
|
---|
| 1748 | {
|
---|
[3750] | 1749 | PutRawUByte(PPS_SIMPLE + datasize2tagsize(4) + PPS_DATATYPE_UNSIGNED);
|
---|
[2475] | 1750 |
|
---|
| 1751 | if (bigEndian != IS_BIG_ENDIAN)
|
---|
| 1752 | bswap4(&val);
|
---|
| 1753 |
|
---|
| 1754 | PutRawBytes(&val, sizeof(uint_4));
|
---|
| 1755 | }
|
---|
| 1756 |
|
---|
| 1757 | void
|
---|
| 1758 | PPFBinaryOutputStream::PutU4s (uint_4 const* tab, size_t n)
|
---|
| 1759 | {
|
---|
| 1760 | PutArrayTag(4, n, PPS_DATATYPE_UNSIGNED);
|
---|
| 1761 |
|
---|
| 1762 | if (bigEndian == IS_BIG_ENDIAN) {
|
---|
| 1763 | PutRawBytes(tab, n*sizeof(uint_4));
|
---|
| 1764 | } else {
|
---|
[3750] | 1765 | for (size_t i=0; i<n; i++) {
|
---|
[2475] | 1766 | uint_4 val = tab[i];
|
---|
| 1767 | bswap4(&val);
|
---|
| 1768 | PutRawBytes(&val, sizeof(uint_4));
|
---|
| 1769 | }
|
---|
| 1770 | }
|
---|
| 1771 | }
|
---|
| 1772 |
|
---|
| 1773 | void
|
---|
| 1774 | PPFBinaryOutputStream::PutI8 (int_8 val)
|
---|
| 1775 | {
|
---|
[3750] | 1776 | PutRawUByte(PPS_SIMPLE + datasize2tagsize(8) + PPS_DATATYPE_INTEGER);
|
---|
[2475] | 1777 |
|
---|
| 1778 | if (bigEndian != IS_BIG_ENDIAN)
|
---|
| 1779 | bswap8(&val);
|
---|
| 1780 |
|
---|
| 1781 | PutRawBytes(&val, sizeof(int_8));
|
---|
| 1782 | }
|
---|
| 1783 |
|
---|
| 1784 | void
|
---|
| 1785 | PPFBinaryOutputStream::PutI8s (int_8 const* tab, size_t n)
|
---|
| 1786 | {
|
---|
| 1787 | PutArrayTag(8, n, PPS_DATATYPE_INTEGER);
|
---|
| 1788 |
|
---|
| 1789 | if (bigEndian == IS_BIG_ENDIAN) {
|
---|
| 1790 | PutRawBytes(tab, n*sizeof(int_8));
|
---|
| 1791 | } else {
|
---|
[3750] | 1792 | for (size_t i=0; i<n; i++) {
|
---|
[2475] | 1793 | int_8 val = tab[i];
|
---|
| 1794 | bswap8(&val);
|
---|
| 1795 | PutRawBytes(&val, sizeof(int_8));
|
---|
| 1796 | }
|
---|
| 1797 | }
|
---|
| 1798 | }
|
---|
| 1799 |
|
---|
| 1800 | void
|
---|
| 1801 | PPFBinaryOutputStream::PutU8 (uint_8 val)
|
---|
| 1802 | {
|
---|
[3750] | 1803 | PutRawUByte(PPS_SIMPLE + datasize2tagsize(8) + PPS_DATATYPE_UNSIGNED);
|
---|
[2475] | 1804 |
|
---|
| 1805 | if (bigEndian != IS_BIG_ENDIAN)
|
---|
| 1806 | bswap8(&val);
|
---|
| 1807 |
|
---|
| 1808 | PutRawBytes(&val, sizeof(uint_8));
|
---|
| 1809 | }
|
---|
| 1810 |
|
---|
| 1811 | void
|
---|
| 1812 | PPFBinaryOutputStream::PutU8s (uint_8 const* tab, size_t n)
|
---|
| 1813 | {
|
---|
| 1814 | PutArrayTag(8, n, PPS_DATATYPE_UNSIGNED);
|
---|
| 1815 |
|
---|
| 1816 | if (bigEndian == IS_BIG_ENDIAN) {
|
---|
| 1817 | PutRawBytes(tab, n*sizeof(uint_8));
|
---|
| 1818 | } else {
|
---|
[3750] | 1819 | for (size_t i=0; i<n; i++) {
|
---|
[2475] | 1820 | uint_8 val = tab[i];
|
---|
| 1821 | bswap8(&val);
|
---|
| 1822 | PutRawBytes(&val, sizeof(uint_8));
|
---|
| 1823 | }
|
---|
| 1824 | }
|
---|
| 1825 | }
|
---|
| 1826 |
|
---|
| 1827 | void
|
---|
| 1828 | PPFBinaryOutputStream::PutStr(string const& str)
|
---|
| 1829 | {
|
---|
| 1830 | PutRawUByte(PPS_STRING);
|
---|
| 1831 | PutRawI4(str.length());
|
---|
| 1832 | PutRawBytes(str.c_str(), str.length());
|
---|
| 1833 | }
|
---|
| 1834 |
|
---|
| 1835 | void
|
---|
| 1836 | PPFBinaryOutputStream::PutLine(char const* ptr, size_t len)
|
---|
| 1837 | {
|
---|
| 1838 | string str = ptr;
|
---|
| 1839 | PutStr(str);
|
---|
| 1840 | }
|
---|
| 1841 |
|
---|
| 1842 |
|
---|
| 1843 | void
|
---|
| 1844 | PPFBinaryOutputStream::PutZ4 (complex<r_4> val)
|
---|
| 1845 | {
|
---|
[3750] | 1846 | PutRawUByte(PPS_SIMPLE + datasize2tagsize(4) + PPS_DATATYPE_COMPLEX);
|
---|
[2475] | 1847 | r_4 reim[2];
|
---|
| 1848 | reim[0] = val.real();
|
---|
| 1849 | reim[1] = val.imag();
|
---|
| 1850 | if (bigEndian != IS_BIG_ENDIAN) {
|
---|
| 1851 | bswap4(reim);
|
---|
| 1852 | bswap4(reim+1);
|
---|
| 1853 | }
|
---|
| 1854 | PutRawBytes(reim, 2*sizeof(r_4));
|
---|
| 1855 | }
|
---|
| 1856 |
|
---|
| 1857 | void
|
---|
| 1858 | PPFBinaryOutputStream::PutZ4s (complex<r_4> const* tab, size_t n)
|
---|
| 1859 | {
|
---|
| 1860 | PutArrayTag(4, n, PPS_DATATYPE_COMPLEX);
|
---|
| 1861 |
|
---|
| 1862 | if (bigEndian == IS_BIG_ENDIAN) {
|
---|
| 1863 | PutRawBytes(tab, n*2*sizeof(r_4));
|
---|
| 1864 | } else {
|
---|
[3750] | 1865 | for (size_t i=0; i<n; i++) {
|
---|
[2475] | 1866 | r_4 reim[2];
|
---|
| 1867 | reim[0] = tab[i].real();
|
---|
| 1868 | reim[1] = tab[i].imag();
|
---|
| 1869 | bswap4(reim);
|
---|
| 1870 | bswap4(reim+1);
|
---|
| 1871 | PutRawBytes(reim, 2*sizeof(r_4));
|
---|
| 1872 | }
|
---|
| 1873 | }
|
---|
| 1874 | }
|
---|
| 1875 |
|
---|
| 1876 | void
|
---|
| 1877 | PPFBinaryOutputStream::PutZ8 (complex<r_8> val)
|
---|
| 1878 | {
|
---|
[3750] | 1879 | PutRawUByte(PPS_SIMPLE + datasize2tagsize(8) + PPS_DATATYPE_COMPLEX);
|
---|
[2475] | 1880 | r_8 reim[2];
|
---|
| 1881 | reim[0] = val.real();
|
---|
| 1882 | reim[1] = val.imag();
|
---|
| 1883 | if (bigEndian != IS_BIG_ENDIAN) {
|
---|
| 1884 | bswap8(reim);
|
---|
| 1885 | bswap8(reim+1);
|
---|
| 1886 | }
|
---|
| 1887 | PutRawBytes(reim, 2*sizeof(r_8));
|
---|
| 1888 | }
|
---|
| 1889 |
|
---|
| 1890 | void
|
---|
| 1891 | PPFBinaryOutputStream::PutZ8s (complex<r_8> const* tab, size_t n)
|
---|
| 1892 | {
|
---|
| 1893 | PutArrayTag(8, n, PPS_DATATYPE_COMPLEX);
|
---|
| 1894 |
|
---|
| 1895 | if (bigEndian == IS_BIG_ENDIAN) {
|
---|
| 1896 | PutRawBytes(tab, n*2*sizeof(r_8));
|
---|
| 1897 | } else {
|
---|
[3750] | 1898 | for (size_t i=0; i<n; i++) {
|
---|
[2475] | 1899 | r_8 reim[2];
|
---|
| 1900 | reim[0] = tab[i].real();
|
---|
| 1901 | reim[1] = tab[i].imag();
|
---|
| 1902 | bswap8(reim);
|
---|
| 1903 | bswap8(reim+1);
|
---|
| 1904 | PutRawBytes(reim, 2*sizeof(r_8));
|
---|
| 1905 | }
|
---|
| 1906 | }
|
---|
| 1907 | }
|
---|
| 1908 |
|
---|
[3750] | 1909 | // Support pour les long double (128 bits floating point numbers)
|
---|
| 1910 | #ifdef SO_LDBLE128
|
---|
[2475] | 1911 | void
|
---|
[3750] | 1912 | PPFBinaryOutputStream::PutR16 (r_16 val)
|
---|
| 1913 | {
|
---|
| 1914 | PutRawUByte(PPS_SIMPLE + datasize2tagsize(16) + PPS_DATATYPE_FLOAT);
|
---|
| 1915 |
|
---|
| 1916 | if (bigEndian != IS_BIG_ENDIAN)
|
---|
| 1917 | bswap16(&val);
|
---|
| 1918 |
|
---|
| 1919 | PutRawBytes(&val, sizeof(r_16));
|
---|
| 1920 | }
|
---|
| 1921 |
|
---|
| 1922 | void
|
---|
| 1923 | PPFBinaryOutputStream::PutR16s (r_16 const* tab, size_t n)
|
---|
| 1924 | {
|
---|
| 1925 | PutArrayTag(16, n, PPS_DATATYPE_FLOAT);
|
---|
| 1926 |
|
---|
| 1927 | if (bigEndian == IS_BIG_ENDIAN) {
|
---|
| 1928 | PutRawBytes(tab, n*sizeof(r_16));
|
---|
| 1929 | } else {
|
---|
| 1930 | for (size_t i=0; i<n; i++) {
|
---|
| 1931 | r_16 val = tab[i];
|
---|
| 1932 | bswap16(&val);
|
---|
| 1933 | PutRawBytes(&val, sizeof(r_16));
|
---|
| 1934 | }
|
---|
| 1935 | }
|
---|
| 1936 | }
|
---|
| 1937 |
|
---|
| 1938 | void
|
---|
| 1939 | PPFBinaryOutputStream::PutZ16 (complex<r_16> val)
|
---|
| 1940 | {
|
---|
| 1941 | PutRawUByte(PPS_SIMPLE + datasize2tagsize(16) + PPS_DATATYPE_COMPLEX);
|
---|
| 1942 | r_16 reim[2];
|
---|
| 1943 | reim[0] = val.real();
|
---|
| 1944 | reim[1] = val.imag();
|
---|
| 1945 | if (bigEndian != IS_BIG_ENDIAN) {
|
---|
| 1946 | bswap16(reim);
|
---|
| 1947 | bswap16(reim+1);
|
---|
| 1948 | }
|
---|
| 1949 | PutRawBytes(reim, 2*sizeof(r_16));
|
---|
| 1950 | }
|
---|
| 1951 |
|
---|
| 1952 | void
|
---|
| 1953 | PPFBinaryOutputStream::PutZ16s (complex<r_16> const* tab, size_t n)
|
---|
| 1954 | {
|
---|
| 1955 | PutArrayTag(16, n, PPS_DATATYPE_COMPLEX);
|
---|
| 1956 |
|
---|
| 1957 | if (bigEndian == IS_BIG_ENDIAN) {
|
---|
| 1958 | PutRawBytes(tab, n*2*sizeof(r_16));
|
---|
| 1959 | } else {
|
---|
| 1960 | for (size_t i=0; i<n; i++) {
|
---|
| 1961 | r_16 reim[2];
|
---|
| 1962 | reim[0] = tab[i].real();
|
---|
| 1963 | reim[1] = tab[i].imag();
|
---|
| 1964 | bswap16(reim);
|
---|
| 1965 | bswap16(reim+1);
|
---|
| 1966 | PutRawBytes(reim, 2*sizeof(r_16));
|
---|
| 1967 | }
|
---|
| 1968 | }
|
---|
| 1969 | }
|
---|
| 1970 | #endif
|
---|
| 1971 |
|
---|
| 1972 | void
|
---|
[2475] | 1973 | PPFBinaryOutputStream::PutPosTagTable(int_8 const * ptab, size_t sz)
|
---|
| 1974 | {
|
---|
| 1975 | PutRawUByte(PPS_POSTAG_TABLE);
|
---|
| 1976 | int_4 tsz = sz;
|
---|
| 1977 | PutRawI4(tsz);
|
---|
| 1978 | for(int kk=0; kk<tsz; kk++)
|
---|
| 1979 | PutRawI8(ptab[kk]);
|
---|
| 1980 | return;
|
---|
| 1981 | }
|
---|
| 1982 |
|
---|
| 1983 | void
|
---|
| 1984 | PPFBinaryOutputStream::PutPosTagTable(vector<int_8> const& ptab)
|
---|
| 1985 | {
|
---|
| 1986 | PutRawUByte(PPS_POSTAG_TABLE);
|
---|
| 1987 | int_4 tsz = ptab.size();
|
---|
| 1988 | PutRawI4(tsz);
|
---|
| 1989 | for(int kk=0; kk<tsz; kk++)
|
---|
| 1990 | PutRawI8(ptab[kk]);
|
---|
| 1991 | return;
|
---|
| 1992 | }
|
---|
| 1993 |
|
---|