source: Sophya/trunk/SophyaLib/BaseTools/ppfbinstream.cc@ 2475

Last change on this file since 2475 was 2475, checked in by ansari, 22 years ago

Separation ppersist.h .cc en deux : ajout de ppfbinstream.h .cc - Reza 4 Dec 2003

File size: 32.7 KB
RevLine 
[2475]1#include "machdefs.h"
2#include <stdio.h>
3#include <sys/types.h>
4#include <time.h>
5#include "ppfbinstream.h"
6#include "pexceptions.h"
7#include <iostream>
8
9
10/*
11// strptime n'est pas defini sous Linux - Reza Mars 2000
12#if defined(OS_LINUX) || defined(OS_MACOSX)
13extern "C" {
14char *strptime(const char *buf, const char *format, struct tm *tm);
15}
16#endif
17*/
18
19#define MAXTAGLEN_V2 255
20
21
22static inline void bswap8(void* p)
23{
24 uint_8 tmp = *(uint_8*)p;
25 *(uint_8*)p = ((tmp >> (7*8)) & 0x000000FF) |
26 ((tmp >> (5*8)) & 0x0000FF00) |
27 ((tmp >> (3*8)) & 0x00FF0000) |
28 ((tmp >> (1*8)) & 0xFF000000) |
29 ((tmp & 0xFF000000) << (1*8)) |
30 ((tmp & 0x00FF0000) << (3*8)) |
31 ((tmp & 0x0000FF00) << (5*8)) |
32 ((tmp & 0x000000FF) << (7*8));
33}
34
35static inline void bswap4(void* p)
36{
37 uint_4 tmp = *(uint_4*)p;
38 *(uint_4*)p = ((tmp >> 24) & 0x000000FF) |
39 ((tmp >> 8) & 0x0000FF00) |
40 ((tmp & 0x0000FF00) << 8) |
41 ((tmp & 0x000000FF) << 24);
42}
43
44static inline void bswap2(void* p)
45{
46 uint_2 tmp = *(uint_2*)p;
47 *(uint_2*)p = ((tmp >> 8) & 0x00FF) |
48 ((tmp & 0x00FF) << 8);
49}
50
51
52PPFBinaryInputStream::PPFBinaryInputStream()
53{
54 s = NULL;
55 version = 0;
56 bigEndian = true;
57}
58
59//++
60PPFBinaryInputStream::PPFBinaryInputStream(string const& flnm, bool scan)
61//
62// Constructeur. Ouvre le fichier.
63//--
64{
65 s = new RawInFileStream(flnm.c_str());
66
67 // Read and check header
68
69 char rbuf[36];
70 GetRawBytes(rbuf, 32);
71 if (strncmp(rbuf,"SOS-SOPHYA-PPersistFile", 23) != 0) {
72 throw FileFormatExc("PPFBinaryInputStream::PPFBinaryInputStream bad header");
73 }
74 rbuf[32] = '\0';
75 version = atoi(rbuf+25);
76 if (version < 2) {
77 cerr << "PPFBinaryInputStream::PPFBinaryInputStream(" << flnm << ") Version(=" << version
78 << ") < 2 not supported !" << endl;
79 throw FileFormatExc("PPFBinaryInputStream::PPFBinaryInputStream() - Unsupported (Old) Version");
80 }
81 // read endianness
82 GetRawBytes(rbuf, 32);
83 if (strncmp(rbuf,"BIG-ENDIAN",10) == 0)
84 bigEndian = true;
85 else if (strncmp(rbuf,"LITTLE-ENDIAN",13) == 0)
86 bigEndian = false;
87 else {
88 throw FileFormatExc("PPFBinaryInputStream::PPFBinaryInputStream bad header - endianness");
89 }
90
91 // read creation date
92 GetRawBytes(rbuf, 32);
93 rbuf[32] = '\0';
94 struct tm tm;
95 /* #if !(defined(__MWERKS__) || defined(OS_MACOSX)) RZ-DEL */
96 strptime(rbuf,"%d/%m/%Y %H:%M:%S GMT",&tm);
97 /* #else
98 sscanf(rbuf,"%2d/%2d/%4d %2d:%2d:%2d GMT",&tm.tm_mday,&tm.tm_mon,&tm.tm_year,
99 &tm.tm_hour,&tm.tm_min,&tm.tm_sec);
100
101 tm.tm_mon --;
102 tm.tm_year -= 1900;
103 #endif RZ-DEL */
104
105 creationdate = mktime(&tm);
106 filename = flnm; // keep the filename
107 seqread = true; // To flag non sequential reads
108 if (scan && s->isSeekable()) Scan();
109}
110
111
112
113PPFBinaryInputStream::~PPFBinaryInputStream()
114{
115 if (s) delete s;
116}
117
118
119string
120PPFBinaryInputStream::CreationDateStr()
121{
122 time_t cdt = CreationDate();
123 string cdate = ctime(&cdt);
124 return(cdate);
125}
126
127void
128PPFBinaryInputStream::Scan()
129{
130 // On cherche la liste des tags, a la fin du fichier
131
132 unsigned char ppstype;
133 int_8 debut;
134 debut = s->tellg();
135
136 s->seekg(-(sizeof(int_8)+1), ios::end);
137
138 GetTypeTag(ppstype);
139 if (ppstype != PPS_EOF)
140 throw FileFormatExc("PPFBinaryInputStream::Scan corrupted file, no eof entry at end of file");
141
142 int_8 pos;
143 GetRawI8(pos);
144 if (pos < 0) { // no tags
145 s->seekg(debut);
146 return;
147 }
148
149 char buffer[MAXTAGLEN_V2+1];
150 s->seekg(pos);
151 while (true) {
152 GetTypeTag(ppstype);
153 if (ppstype == PPS_EOF) break;
154
155 if (ppstype != PPS_NAMETAG_TABLE)
156 throw FileFormatExc("PPFBinaryInputStream::Scan corrupted file, bad tag entry");
157
158 GetRawI8(pos);
159 int_4 len;
160 GetRawI4(len);
161 if (len > MAXTAGLEN_V2)
162 throw FileFormatExc("PPFBinaryInputStream::Scan corrupted file, tag name too long");
163 GetRawBytes(buffer, len);
164 buffer[len] = '\0';
165
166 tags[buffer] = pos;
167 }
168 s->seekg(debut);
169}
170
171
172int
173PPFBinaryInputStream::NbNameTags()
174{
175 return tags.size();
176}
177
178bool
179PPFBinaryInputStream::GotoPositionTag(int_8 pos)
180{
181 s->seekg(pos);
182 int_8 tpos;
183 GetRawI8(tpos);
184 if (tpos != pos)
185 throw FileFormatExc("PPFBinaryInputStream::GotoPositionTag() - Wrong tag position!");
186 return true;
187}
188
189bool
190PPFBinaryInputStream::GotoNameTag(string const& name)
191{
192 map<string, int_8>::iterator i = tags.find(name);
193 if (i == tags.end())
194 return false;
195 // throw NotFoundExc("PPFBinaryInputStream::GotoNameTag tag not found");
196 s->seekg((*i).second);
197 seqread = false;
198 // objList.clear(); $CHECK$ EA 171199 Ne pas faire ? Reza 03/2000 ?
199 return(true);
200}
201
202
203bool
204PPFBinaryInputStream::GotoNameTagNum(int itag)
205{
206 if (itag<0 || itag >= (int)tags.size()) return false;
207 map<string, int_8>::iterator i = tags.begin();
208 for (int j=0; j<itag; j++) i++;
209 s->seekg((*i).second);
210 seqread = false;
211 // objList.clear(); $CHECK$ EA 171199 Ne pas faire ? Reza 03/2000 ?
212 return(true);
213}
214
215string
216PPFBinaryInputStream::GetTagName(int itag)
217{
218 if (itag<0 || itag >= (int)tags.size()) return "";
219 map<string, int_8>::iterator i = tags.begin();
220 for (int j=0; j<itag; j++) i++;
221 return((*i).first);
222}
223
224
225static vector<string> * ret_tag_names = NULL;
226vector<string> const &
227PPFBinaryInputStream::GetNameTags()
228{
229if (ret_tag_names) delete ret_tag_names;
230ret_tag_names = new vector<string> ;
231map<string, int_8>::iterator i;
232for(i=tags.begin(); i!=tags.end(); i++) ret_tag_names->push_back((*i).first);
233return(*ret_tag_names);
234}
235
236bool
237PPFBinaryInputStream::SkipToNextObject()
238{
239 // A FAIRE NOV 2003 - REZA
240 return true;
241}
242
243bool
244PPFBinaryInputStream::SkipItem()
245{
246 // A FAIRE NOV 2003 - REZA
247 return true;
248}
249
250//++
251// void PPFBinaryInputStream::GetByte(char& c)
252// void PPFBinaryInputStream::GetBytes(void* ptr, size_t bytes)
253// void PPFBinaryInputStream::GetR4 (r_4& result)
254// void PPFBinaryInputStream::GetR4s (r_4* tab, size_t n)
255// void PPFBinaryInputStream::GetR8 (r_8& result)
256// void PPFBinaryInputStream::GetR8s (r_8* tab, size_t n)
257// void PPFBinaryInputStream::GetI2 (int_2& result)
258// void PPFBinaryInputStream::GetI2s (int_2* tab, size_t n)
259// void PPFBinaryInputStream::GetU2 (uint_2& result)
260// void PPFBinaryInputStream::GetU2s (uint_2* tab, size_t n)
261// void PPFBinaryInputStream::GetI4 (int_4& result)
262// void PPFBinaryInputStream::GetI4s (int_4* tab, size_t n)
263// void PPFBinaryInputStream::GetU4 (uint_4& result)
264// void PPFBinaryInputStream::GetU4s (uint_4* tab, size_t n)
265// void PPFBinaryInputStream::GetI8 (int_8& result)
266// void PPFBinaryInputStream::GetI8s (int_8* tab, size_t n)
267// void PPFBinaryInputStream::GetU8 (uint_8& result)
268// void PPFBinaryInputStream::GetU8s (uint_8* tab, size_t n)
269// Lecture de données portables depuis le fichier PPersist. Pour chaque type
270// de données, on peut lire une valeur, ou un tableau de valeurs.
271// void PPFBinaryInputStream::GetLine(char* ptr, size_t len)
272// Lecture d'une ligne de texte depuis le fichier PPersist.
273//--
274
275
276void
277PPFBinaryInputStream::GetTypeTag(unsigned char& c)
278{
279 int_8 tpos;
280 c = PPS_NAMETAG_MARK;
281 while ( (c == PPS_NAMETAG_MARK) || (c == PPS_POSTAG_MARK) ) {
282 GetRawUByte(c);
283 if (c == PPS_POSTAG_MARK) GetRawI8(tpos);
284 }
285 // while (c == PPS_NAMETAG_MARK) { Il ne faut plus faire ca !
286 // objList.clear(); $CHECK$ Reza 03/2000
287 // GetRawByte(c);
288 // }
289}
290
291
292void
293PPFBinaryInputStream::GetRawByte(char& c)
294{
295 GetRawBytes(&c, 1);
296}
297
298void
299PPFBinaryInputStream::GetRawUByte(unsigned char& c)
300{
301 GetRawBytes(&c, 1);
302}
303
304void
305PPFBinaryInputStream::GetRawBytes(void* ptr, size_t bytes)
306{
307 s->read((char*)ptr, bytes);
308}
309
310void
311PPFBinaryInputStream::GetRawI2 (int_2& result)
312{
313 GetRawBytes(&result, sizeof(int_2));
314 if (bigEndian != IS_BIG_ENDIAN)
315 bswap2(&result);
316}
317
318void
319PPFBinaryInputStream::GetRawI4 (int_4& result)
320{
321 GetRawBytes(&result, sizeof(int_4));
322 if (bigEndian != IS_BIG_ENDIAN)
323 bswap4(&result);
324}
325
326void
327PPFBinaryInputStream::GetRawI8 (int_8& result)
328{
329 GetRawBytes(&result, sizeof(int_8));
330 if (bigEndian != IS_BIG_ENDIAN)
331 bswap8(&result);
332}
333
334void
335PPFBinaryInputStream::GetRawU8 (uint_8& result)
336{
337 GetRawBytes(&result, sizeof(uint_8));
338 if (bigEndian != IS_BIG_ENDIAN)
339 bswap8(&result);
340}
341
342void
343PPFBinaryInputStream::CheckTag(short datasz, short datatype)
344// datatype = PPS_DATATYPE_CHAR or PPS_DATATYPE_FLOAT or PPS_DATATYPE_INTEGER or PPS_DATATYPE_UNSIGNED
345{
346 unsigned char ppstype;
347 GetTypeTag(ppstype);
348 if (ppstype != PPS_SIMPLE + datasz + datatype)
349 throw FileFormatExc("PPFBinaryInputStream::CheckTag bad type in ppersist file");
350}
351
352void
353PPFBinaryInputStream::CheckArrayTag(short datasz, size_t sz, short datatype)
354// datatype = PPS_DATATYPE_CHAR or PPS_DATATYPE_FLOAT or PPS_DATATYPE_INTEGER or PPS_DATATYPE_UNSIGNED
355{
356 unsigned char ppstype;
357 GetTypeTag(ppstype);
358 size_t filesz;
359 if (sz <= 0x7fffffff) {
360 if (ppstype != PPS_SIMPLE_ARRAY4 + datasz + datatype)
361 throw FileFormatExc("PPFBinaryInputStream::CheckArrayTag bad type in ppersist file");
362 int_4 ff;
363 GetRawI4(ff); filesz=ff;
364 } else {
365 if (ppstype != PPS_SIMPLE_ARRAY8 + datasz + datatype)
366 throw FileFormatExc("PPFBinaryInputStream::CheckArrayTag bad type in ppersist file");
367 uint_8 ff;
368 GetRawU8(ff); filesz=ff;
369 }
370 if (filesz != sz)
371 throw FileFormatExc("PPFBinaryInputStream::CheckArrayTag bad array size in ppersist file");
372}
373
374void
375PPFBinaryInputStream::GetByte(char& c)
376{
377 CheckTag(1,PPS_DATATYPE_CHAR);
378 GetRawBytes(&c, 1);
379}
380
381
382void
383PPFBinaryInputStream::GetBytes(void* ptr, size_t bytes)
384{
385 CheckArrayTag(1, bytes, PPS_DATATYPE_CHAR);
386 GetRawBytes(ptr, bytes);
387}
388void
389PPFBinaryInputStream::GetR4 (r_4& result)
390{
391 CheckTag(4,PPS_DATATYPE_FLOAT);
392 GetRawBytes(&result, sizeof(r_4));
393 if (bigEndian != IS_BIG_ENDIAN)
394 bswap4(&result);
395}
396
397
398void
399PPFBinaryInputStream::GetR4s (r_4* tab, size_t n)
400{
401 CheckArrayTag(4,n,PPS_DATATYPE_FLOAT);
402 GetRawBytes(tab, n*sizeof(r_4));
403 if (bigEndian == IS_BIG_ENDIAN) return;
404
405 for (unsigned int i=0; i<n; i++)
406 bswap4(tab+i);
407
408 return;
409}
410
411void
412PPFBinaryInputStream::GetR8 (r_8& result)
413{
414 CheckTag(8,PPS_DATATYPE_FLOAT);
415 GetRawBytes(&result, sizeof(r_8));
416 if (bigEndian != IS_BIG_ENDIAN)
417 bswap8(&result);
418}
419
420void
421PPFBinaryInputStream::GetR8s (r_8* tab, size_t n)
422{
423 CheckArrayTag(8,n,PPS_DATATYPE_FLOAT);
424 GetRawBytes(tab, n*sizeof(r_8));
425 if (bigEndian == IS_BIG_ENDIAN) return;
426
427 for (unsigned int i=0; i<n; i++)
428 bswap8(tab+i);
429
430 return;
431}
432
433void
434PPFBinaryInputStream::GetI1 (int_1& result)
435{
436 CheckTag(1,PPS_DATATYPE_INTEGER);
437 GetRawBytes(&result, sizeof(int_1));
438}
439
440void
441PPFBinaryInputStream::GetI1s (int_1* tab, size_t n)
442{
443 CheckArrayTag(1,n,PPS_DATATYPE_INTEGER);
444 GetRawBytes(tab, n*sizeof(int_1));
445}
446
447void
448PPFBinaryInputStream::GetU1 (uint_1& result)
449{
450 CheckTag(1,PPS_DATATYPE_UNSIGNED);
451 GetRawBytes(&result, sizeof(uint_1));
452}
453
454void
455PPFBinaryInputStream::GetU1s (uint_1* tab, size_t n)
456{
457 CheckArrayTag(1,n,PPS_DATATYPE_UNSIGNED);
458 GetRawBytes(tab, n*sizeof(uint_1));
459}
460
461void
462PPFBinaryInputStream::GetI2 (int_2& result)
463{
464 CheckTag(2,PPS_DATATYPE_INTEGER);
465 GetRawBytes(&result, sizeof(int_2));
466 if (bigEndian != IS_BIG_ENDIAN)
467 bswap2(&result);
468}
469
470void
471PPFBinaryInputStream::GetI2s (int_2* tab, size_t n)
472{
473 CheckArrayTag(2,n,PPS_DATATYPE_INTEGER);
474 GetRawBytes(tab, n*sizeof(int_2));
475 if (bigEndian == IS_BIG_ENDIAN) return;
476
477 for (unsigned int i=0; i<n; i++)
478 bswap2(tab+i);
479
480 return;
481}
482
483void
484PPFBinaryInputStream::GetU2 (uint_2& result)
485{
486 CheckTag(2,PPS_DATATYPE_UNSIGNED);
487 GetRawBytes(&result, sizeof(uint_2));
488 if (bigEndian != IS_BIG_ENDIAN)
489 bswap2(&result);
490}
491
492void
493PPFBinaryInputStream::GetU2s (uint_2* tab, size_t n)
494{
495 CheckArrayTag(2,n,PPS_DATATYPE_UNSIGNED);
496 GetRawBytes(tab, n*sizeof(uint_2));
497 if (bigEndian == IS_BIG_ENDIAN) return;
498
499 for (unsigned int i=0; i<n; i++)
500 bswap2(tab+i);
501
502 return;
503}
504
505void
506PPFBinaryInputStream::GetI4 (int_4& result)
507{
508 CheckTag(4,PPS_DATATYPE_INTEGER);
509 GetRawBytes(&result, sizeof(int_4));
510 if (bigEndian != IS_BIG_ENDIAN)
511 bswap4(&result);
512}
513
514void
515PPFBinaryInputStream::GetI4s (int_4* tab, size_t n)
516{
517 CheckArrayTag(4,n,PPS_DATATYPE_INTEGER);
518 GetRawBytes(tab, n*sizeof(int_4));
519 if (bigEndian == IS_BIG_ENDIAN) return;
520
521 for (unsigned int i=0; i<n; i++)
522 bswap4(tab+i);
523
524 return;
525}
526
527void
528PPFBinaryInputStream::GetU4 (uint_4& result)
529{
530 CheckTag(4,PPS_DATATYPE_UNSIGNED);
531 GetRawBytes(&result, sizeof(uint_4));
532 if (bigEndian != IS_BIG_ENDIAN)
533 bswap4(&result);
534}
535
536void
537PPFBinaryInputStream::GetU4s (uint_4* tab, size_t n)
538{
539 CheckArrayTag(4,n,PPS_DATATYPE_UNSIGNED);
540 GetRawBytes(tab, n*sizeof(uint_4));
541 if (bigEndian == IS_BIG_ENDIAN) return;
542
543 for (unsigned int i=0; i<n; i++)
544 bswap4(tab+i);
545
546 return;
547}
548
549
550void
551PPFBinaryInputStream::GetI8 (int_8& result)
552{
553 CheckTag(8,PPS_DATATYPE_INTEGER);
554 GetRawBytes(&result, sizeof(int_8));
555 if (bigEndian != IS_BIG_ENDIAN)
556 bswap8(&result);
557}
558
559void
560PPFBinaryInputStream::GetI8s (int_8* tab, size_t n)
561{
562 CheckArrayTag(8,n,PPS_DATATYPE_INTEGER);
563 GetRawBytes(tab, n*sizeof(int_8));
564 if (bigEndian == IS_BIG_ENDIAN) return;
565
566 for (unsigned int i=0; i<n; i++)
567 bswap8(tab+i);
568
569 return;
570}
571
572void
573PPFBinaryInputStream::GetU8 (uint_8& result)
574{
575 CheckTag(8,PPS_DATATYPE_UNSIGNED);
576 GetRawBytes(&result, sizeof(uint_8));
577 if (bigEndian != IS_BIG_ENDIAN)
578 bswap8(&result);
579}
580
581void
582PPFBinaryInputStream::GetU8s (uint_8* tab, size_t n)
583{
584 CheckArrayTag(8,n,PPS_DATATYPE_UNSIGNED);
585 GetRawBytes(tab, n*sizeof(uint_8));
586 if (bigEndian == IS_BIG_ENDIAN) return;
587
588 for (unsigned int i=0; i<n; i++)
589 bswap8(tab+i);
590
591 return;
592}
593
594
595void
596PPFBinaryInputStream::GetLine(char* ptr, size_t len)
597{
598 string str;
599 GetStr(str);
600 strncpy(ptr, str.c_str(), len);
601 ptr[len] = '\0';
602}
603
604void
605PPFBinaryInputStream::GetStr(string& str)
606{
607 unsigned char ppstype;
608 GetTypeTag(ppstype);
609 if (ppstype != PPS_STRING)
610 throw FileFormatExc("PPFBinaryInputStream::GetStr bad type in ppersist file");
611 int_4 len;
612 GetRawI4(len);
613 char * buff = new char[len+1];
614 GetRawBytes(buff, len);
615 buff[len] = '\0';
616 str = buff;
617 delete[] buff;
618}
619
620void
621PPFBinaryInputStream::GetZ4 (complex<r_4>& result)
622{
623 CheckTag(4,PPS_DATATYPE_COMPLEX);
624 r_4 reim[2];
625 GetRawBytes(reim, 2*sizeof(r_4));
626 if (bigEndian != IS_BIG_ENDIAN) {
627 bswap4(reim);
628 bswap4(reim+1);
629 }
630 result = complex<r_4>(reim[0], reim[1]);
631}
632
633void
634PPFBinaryInputStream::GetZ4s (complex<r_4>* tab, size_t n)
635{
636 CheckArrayTag(4,n,PPS_DATATYPE_COMPLEX);
637 GetRawBytes(tab, n*2*sizeof(r_4));
638 if (bigEndian == IS_BIG_ENDIAN) return;
639
640 r_4 * p = (r_4 *)tab;
641 for (unsigned int i=0; i<n; i++) {
642 bswap4(p); p++;
643 bswap4(p); p++;
644 }
645 return;
646}
647
648void
649PPFBinaryInputStream::GetZ8 (complex<r_8>& result)
650{
651 CheckTag(8,PPS_DATATYPE_COMPLEX);
652 r_8 reim[2];
653 GetRawBytes(reim, 2*sizeof(r_8));
654 if (bigEndian != IS_BIG_ENDIAN) {
655 bswap8(reim);
656 bswap8(reim+1);
657 }
658 result = complex<r_8>(reim[0], reim[1]);
659}
660
661void
662PPFBinaryInputStream::GetZ8s (complex<r_8>* tab, size_t n)
663{
664 CheckArrayTag(8,n,PPS_DATATYPE_COMPLEX);
665 GetRawBytes(tab, n*2*sizeof(r_8));
666 if (bigEndian == IS_BIG_ENDIAN) return;
667
668 r_8 * p = (r_8 *)tab;
669 for (unsigned int i=0; i<n; i++) {
670 bswap8(p); p++;
671 bswap8(p); p++;
672 }
673 return;
674}
675
676
677void
678PPFBinaryInputStream::GetPosTagTable(int_8* ptab, size_t sz)
679{
680 unsigned char ppstype;
681 GetTypeTag(ppstype);
682 if (ppstype != PPS_POSTAG_TABLE)
683 throw FileFormatExc("PPFBinaryInputStream::GetPosTagTable bad type in ppersist stream");
684 int_4 tsz;
685 GetRawI4(tsz);
686 if (tsz != sz)
687 throw FileFormatExc("PPFBinaryInputStream::GetPosTagTable Size mismatch ");
688 for(int kk=0; kk<tsz; kk++)
689 GetRawI8(ptab[kk]);
690 return;
691}
692
693void
694PPFBinaryInputStream::GetPosTagTable(vector<int_8>& ptab)
695{
696 unsigned char ppstype;
697 GetTypeTag(ppstype);
698 if (ppstype != PPS_POSTAG_TABLE)
699 throw FileFormatExc("PPFBinaryInputStream::GetPosTagTable bad type in ppersist stream");
700 ptab.clear();
701 int_4 tsz;
702 GetRawI4(tsz);
703 int_8 tpos;
704 for(int kk=0; kk<tsz; kk++) {
705 GetRawI8(tpos);
706 ptab.push_back(tpos);
707 }
708 return;
709}
710
711
712void
713PPFBinaryInputStream::AnalyseTags(int lev)
714{
715 unsigned char ppstag=0;
716 unsigned char ppst1,ppst2,ppst3,ppst30;
717 int_8 cpos,fsize;
718 uint_8 ui8,cid,oid;
719 int_4 i4;
720 int_8 i8;
721 char * buff;
722 string str;
723
724 cout << "\n ---------------------------------------------------------- " << endl;
725 cout << " PPFBinaryInputStream::AnalyseTags(Level= " << lev << ")" << endl;
726
727
728 cpos = s->tellg();
729 s->seekg(0,ios::end);
730 fsize = s->tellg();
731 s->seekg(cpos,ios::beg);
732
733 cout << " Version= " << Version() << " FileSize= " << fsize
734 << " Creation Date= " << CreationDateStr() << endl;
735
736 uint_8 totntags = 0;
737 bool eofok = false;
738
739 while ( (ppstag != PPS_EOF) && (cpos < fsize) ) {
740 cpos = s->tellg();
741 GetRawUByte(ppstag);
742 totntags++;
743
744 ppst1 = ppstag&0x0f; // bits 0123
745 ppst2 = ppstag&0x30; // bits 45
746 ppst3 = ppstag&0xc0; // bits 67
747 ppst30 = ppstag&0xc1; // bits 0 67
748 if ((ppst2 == 0) && (ppst3 == 0) ) {
749 switch (ppst1) {
750
751 case PPS_NULL :
752 if (lev > 1) cout << "<PPS_NULL> tag at position " << hex << cpos << dec << endl;
753 break;
754
755 case PPS_STRING :
756 GetRawI4(i4);
757 if (lev > 1) cout << "<PPS_STRING> tag at position " << hex << cpos << dec
758 << " Length=" << i4 << endl;
759 s->seekg(i4,ios::cur);
760 break;
761
762 case PPS_OBJECT :
763 GetRawU8(cid);
764 GetRawU8(oid);
765 cout << "<PPS_OBJECT> tag at position " << hex << cpos << " ClassId= " << cid
766 << " ObjectId= " << oid << dec << endl;
767 break;
768
769 case PPS_REFERENCE :
770 GetRawU8(oid);
771 GetRawI8(i8);
772 cout << "<PPS_REFERENCE> tag at position " << hex << cpos << " ObjectId= "
773 << oid << " OrigPos=" << i8 << dec << endl;
774 break;
775
776 case PPS_NAMETAG_MARK :
777 cout << "<PPS_NAMETAG_MARK> tag at position " << hex << cpos << dec << endl;
778 break;
779
780 case PPS_POSTAG_MARK :
781 GetRawI8(i8);
782 cout << "<PPS_POSTAG_MARK> tag at position " << hex << cpos
783 << " TPos=" << i8 << dec << endl;
784 break;
785
786 case PPS_ENDOBJECT :
787 GetRawU8(oid);
788 cout << "<PPS_ENDOBJECT> tag at position " << hex << cpos << " ObjectId= "
789 << oid << dec << endl;
790 break;
791
792 case PPS_POSTAG_TABLE :
793 GetRawI4(i4);
794 for(int kkt=0; kkt<i4; kkt++) GetRawI8(i8);
795 cout << "<PPS_POSTAG_TABLE> tag at position " << hex << cpos << dec << endl;
796 break;
797
798 case PPS_NAMETAG_TABLE :
799 GetRawI8(i8);
800 GetRawI4(i4);
801 buff = new char[i4+1];
802 GetRawBytes(buff, i4);
803 buff[i4] = '\0'; str = buff;
804 delete[] buff;
805 cout << "<PPS_TAG> tag at position " << hex << cpos << dec
806 << " Name= " << str << endl;
807 break;
808
809 case PPS_EOF :
810 GetRawI8(i8);
811 cout << "<PPS_EOF> tag at position " << hex << cpos
812 << " TagPos=" << i8 << dec << endl;
813 eofok = true;
814 break;
815
816 default :
817 cerr << " ERROR : Unexpected tag value " << hex << ppstag
818 << " At position" << cpos << dec << endl;
819 throw FileFormatExc("PPFBinaryInputStream::AnalyseTags() - Unexpected tag value !");
820 }
821 }
822 else {
823 string dtype = "???? x";
824 if (ppst30 == PPS_DATATYPE_COMPLEX) dtype = "COMPLEX x";
825 else if (ppst3 == PPS_DATATYPE_CHAR) dtype = "CHAR x";
826 else if (ppst3 == PPS_DATATYPE_FLOAT) dtype = "FLOAT x";
827 else if (ppst3 == PPS_DATATYPE_INTEGER) dtype = "INTEGER x";
828 else if (ppst3 == PPS_DATATYPE_UNSIGNED) dtype = "UNSIGNED x";
829 int_4 dsize = ppst1;
830 int_4 dsizeskip = dsize;
831 if (ppst30 == PPS_DATATYPE_COMPLEX) {
832 dsize--;
833 dsizeskip = 2*dsize;
834 }
835 char sb[16];
836 sprintf(sb, "%d", dsize);
837 dtype += sb;
838
839 switch (ppst2) {
840
841 case PPS_SIMPLE :
842 if (lev > 2) cout << "<PPS_SIMPLE> tag at position " << hex << cpos << dec
843 << " DataType=" << dtype << endl;
844 s->seekg(dsizeskip, ios::cur);
845 break;
846
847 case PPS_SIMPLE_ARRAY4 :
848 GetRawI4(i4);
849 if (lev > 0) cout << "<PPS_SIMPLE_ARRAY4> tag at position " << hex << cpos << dec
850 << " DataType=" << dtype << " NElts= " << i4 << endl;
851 s->seekg((int_8)dsizeskip*(int_8)i4, ios::cur);
852 break;
853
854 case PPS_SIMPLE_ARRAY8 :
855 GetRawU8(ui8);
856 if (lev > 0) cout << "<PPS_SIMPLE_ARRAY8> tag at position " << hex << cpos << dec
857 << " DataType=" << dtype << " NElts= " << ui8 << endl;
858 s->seekg((int_8)dsizeskip*ui8, ios::cur);
859 break;
860 }
861 }
862 }
863 if (!eofok)
864 throw FileFormatExc("PPFBinaryInputStream::AnalyseTags() - Not found <PPS_EOF> tag ");
865
866 cout << " PPFBinaryInputStream::AnalyseTags() - End - Total Number of Tags= " << totntags << endl;
867 cout << " ---------------------------------------------------------- \n" << endl;
868 return;
869}
870
871
872//++
873// Class POutPersist
874// Lib Outils++
875// include ppersist.h
876//
877// Fichier d'objets persistants, en écriture.
878//--
879
880
881//++
882// POutPersist(string const& flnm, int endianness = PPersist::PPS_NATIVE)
883//
884// Crée un nouveau fichier ppersist. Par défaut, il est petit=boutien
885// sur machines petit-boutiennes, et gros-boutien sur machines
886// gros-boutiennes. On peut explicitement spécifier PPersist::PPS_LITTLE_ENDIAN
887// ou PPersist::PPS_BIG_ENDIAN.
888//--
889
890PPFBinaryOutputStream::PPFBinaryOutputStream()
891{
892 s = NULL;
893 version = 0;
894}
895
896PPFBinaryOutputStream::PPFBinaryOutputStream(string const& flnm, int endianness)
897{
898 if (endianness == -1)
899 bigEndian = IS_BIG_ENDIAN;
900 else
901 bigEndian = endianness;
902
903 // Output stream creation
904 s = new RawOutFileStream(flnm.c_str());
905 version = 3;
906 // Header
907 PutRawBytes("SOS-SOPHYA-PPersistFile V3 ",32);
908 PutRawBytes(bigEndian
909 ? "BIG-ENDIAN "
910 : "LITTLE-ENDIAN ",32);
911
912// ---- GMT creation date of the file
913 time_t tm = time(NULL);
914 char datestring[33];
915 int l=strftime(datestring,32,"%d/%m/%Y %H:%M:%S GMT",gmtime(&tm));
916 for(int i=l; i<32; i++) datestring[i] = ' ';
917 datestring[32] = '\0';
918 PutRawBytes(datestring, 32);
919 filename = flnm;
920}
921
922PPFBinaryOutputStream::~PPFBinaryOutputStream()
923{
924 if (tags.size() == 0) {
925 PutRawUByte(PPS_EOF);
926 PutRawI8(-1);
927 } else {
928 int_8 tagPos;
929 tagPos = s->tellp();
930 for (map<string,int_8>::iterator i = tags.begin(); i != tags.end(); i++) {
931 string name = (*i).first;
932 int_8 pos = (*i).second;
933 PutRawUByte(PPS_NAMETAG_TABLE); // This is a tag
934 PutRawI8(pos); // position of previous tag
935 PutRawI4(name.length()); // length of the name
936 PutRawBytes(name.c_str(), name.length()); // name, without final "0".
937 }
938 PutRawUByte(PPS_EOF);
939 PutRawI8(tagPos);
940 }
941
942 delete s; // Close the stream
943}
944
945int_8
946PPFBinaryOutputStream::WritePositionTag()
947{
948 int_8 tagpos;
949 tagpos = s->tellp();
950 PutRawByte(PPS_POSTAG_MARK);
951 PutI8(tagpos);
952 return(tagpos);
953}
954
955void
956PPFBinaryOutputStream::WriteNameTag(string const& name)
957{
958 // if (name.length() > MAXTAGLEN_V2)
959 // throw ParmError("PPFBinaryOutputStream::WriteNameTag tag name too long");
960
961 if (tags.find(name) != tags.end())
962 throw DuplicateIdExc("PPFBinaryOutputStream::WriteNameTag duplicate tag name");
963
964 // Get current file position
965 int_8 tagPos;
966 tagPos = s->tellp();
967
968 tags[name] = tagPos;
969 PutRawUByte(PPS_NAMETAG_MARK); // This is a tag
970 // objList.clear(); // $CHECK$ EA 171199 - Ne pas faire ? Reza 03/2000
971}
972
973//++
974// void PPFBinaryOutputStream::PutByte(char& c)
975// void PPFBinaryOutputStream::PutBytes(void const* ptr, size_t bytes)
976// void PPFBinaryOutputStream::PutR4 (r_4 result)
977// void PPFBinaryOutputStream::PutR4s (r_4 const* tab, size_t n)
978// void PPFBinaryOutputStream::PutR8 (r_8 result)
979// void PPFBinaryOutputStream::PutR8s (r_8 const* tab, size_t n)
980// void PPFBinaryOutputStream::PutI2 (int_2 result)
981// void PPFBinaryOutputStream::PutI2s (int_2 const* tab, size_t n)
982// void PPFBinaryOutputStream::PutU2 (uint_2 result)
983// void PPFBinaryOutputStream::PutU2s (uint_2 const* tab, size_t n)
984// void PPFBinaryOutputStream::PutI4 (int_4 result)
985// void PPFBinaryOutputStream::PutI4s (int_4 const* tab, size_t n)
986// void PPFBinaryOutputStream::PutU4 (uint_4 result)
987// void PPFBinaryOutputStream::PutU4s (uint_4 const* tab, size_t n)
988// void PPFBinaryOutputStream::PutI8 (int_8 result)
989// void PPFBinaryOutputStream::PutI8s (int_8 const* tab, size_t n)
990// void PPFBinaryOutputStream::PutU8 (uint_8 result)
991// void PPFBinaryOutputStream::PutU8s (uint_8 const* tab, size_t n)
992// void PPFBinaryOutputStream::PutStr (string const&)
993// Ecriture de données portables.. Pour chaque type
994// de données, on peut écrire une valeur, ou un tableau de valeurs.
995// void PPFBinaryOutputStream::PutLine(char const* ptr, size_t len)
996// Ecriture d'une ligne de texte dans le fichier PPersist.
997//--
998
999
1000
1001
1002void
1003PPFBinaryOutputStream::PutRawBytes(void const* ptr, size_t bytes)
1004{
1005 s->write((char const*)ptr, bytes);
1006}
1007
1008void
1009PPFBinaryOutputStream::PutRawByte(char c)
1010{
1011 PutRawBytes(&c, 1);
1012}
1013
1014void
1015PPFBinaryOutputStream::PutRawUByte(unsigned char c)
1016{
1017 PutRawBytes(&c, 1);
1018}
1019
1020void
1021PPFBinaryOutputStream::PutRawI2 (int_2 val)
1022{
1023 if (bigEndian != IS_BIG_ENDIAN)
1024 bswap2(&val);
1025
1026 PutRawBytes(&val, sizeof(int_2));
1027}
1028
1029void
1030PPFBinaryOutputStream::PutRawI4 (int_4 val)
1031{
1032 if (bigEndian != IS_BIG_ENDIAN)
1033 bswap4(&val);
1034
1035 PutRawBytes(&val, sizeof(int_4));
1036}
1037
1038void
1039PPFBinaryOutputStream::PutRawI8 (int_8 val)
1040{
1041 if (bigEndian != IS_BIG_ENDIAN)
1042 bswap8(&val);
1043
1044 PutRawBytes(&val, sizeof(int_8));
1045}
1046
1047void
1048PPFBinaryOutputStream::PutRawU8 (uint_8 val)
1049{
1050 if (bigEndian != IS_BIG_ENDIAN)
1051 bswap8(&val);
1052
1053 PutRawBytes(&val, sizeof(uint_8));
1054}
1055
1056void
1057PPFBinaryOutputStream::PutArrayTag(short datasz, size_t sz, short datatype)
1058// datatype = PPS_DATATYPE_CHAR or PPS_DATATYPE_FLOAT or PPS_DATATYPE_INTEGER or PPS_DATATYPE_UNSIGNED
1059{
1060 if (sz <= 0x7fffffff) {
1061 PutRawUByte(PPS_SIMPLE_ARRAY4 + datasz + datatype);
1062 PutRawI4(sz);
1063 } else {
1064 PutRawUByte(PPS_SIMPLE_ARRAY8 + datasz + datatype);
1065 PutRawU8(sz);
1066 }
1067}
1068
1069void
1070PPFBinaryOutputStream::PutByte(char c)
1071{
1072 PutRawByte(PPS_SIMPLE + 1 + PPS_DATATYPE_CHAR);
1073 PutRawBytes(&c, 1);
1074}
1075
1076
1077
1078void
1079PPFBinaryOutputStream::PutBytes(void const* ptr, size_t bytes)
1080{
1081 PutArrayTag(1, bytes, PPS_DATATYPE_CHAR);
1082 PutRawBytes(ptr, bytes);
1083}
1084
1085void
1086PPFBinaryOutputStream::PutR4 (r_4 val)
1087{
1088 PutRawUByte(PPS_SIMPLE + 4 + PPS_DATATYPE_FLOAT);
1089
1090 if (bigEndian != IS_BIG_ENDIAN)
1091 bswap4(&val);
1092
1093 PutRawBytes(&val, sizeof(r_4));
1094}
1095
1096void
1097PPFBinaryOutputStream::PutR4s (r_4 const* tab, size_t n)
1098{
1099 PutArrayTag(4, n, PPS_DATATYPE_FLOAT);
1100
1101 if (bigEndian == IS_BIG_ENDIAN) {
1102 PutRawBytes(tab, n*sizeof(r_4));
1103 } else {
1104 for (unsigned int i=0; i<n; i++) {
1105 r_4 val = tab[i];
1106 bswap4(&val);
1107 PutRawBytes(&val, sizeof(r_4));
1108 }
1109 }
1110}
1111
1112void
1113PPFBinaryOutputStream::PutR8 (r_8 val)
1114{
1115 PutRawUByte(PPS_SIMPLE + 8 + PPS_DATATYPE_FLOAT);
1116
1117 if (bigEndian != IS_BIG_ENDIAN)
1118 bswap8(&val);
1119
1120 PutRawBytes(&val, sizeof(r_8));
1121}
1122
1123void
1124PPFBinaryOutputStream::PutR8s (r_8 const* tab, size_t n)
1125{
1126 PutArrayTag(8, n, PPS_DATATYPE_FLOAT);
1127
1128 if (bigEndian == IS_BIG_ENDIAN) {
1129 PutRawBytes(tab, n*sizeof(r_8));
1130 } else {
1131 for (unsigned int i=0; i<n; i++) {
1132 r_8 val = tab[i];
1133 bswap8(&val);
1134 PutRawBytes(&val, sizeof(r_8));
1135 }
1136 }
1137}
1138
1139void
1140PPFBinaryOutputStream::PutI1 (int_1 val)
1141{
1142 PutRawUByte(PPS_SIMPLE + 1 + PPS_DATATYPE_INTEGER);
1143 PutRawBytes(&val, sizeof(int_1));
1144}
1145
1146void
1147PPFBinaryOutputStream::PutI1s (int_1 const* tab, size_t n)
1148{
1149 PutArrayTag(1, n, PPS_DATATYPE_INTEGER);
1150 PutRawBytes(tab, n*sizeof(int_1));
1151}
1152
1153void
1154PPFBinaryOutputStream::PutU1 (uint_1 val)
1155{
1156 PutRawUByte(PPS_SIMPLE + 1 + PPS_DATATYPE_UNSIGNED);
1157 PutRawBytes(&val, sizeof(uint_1));
1158}
1159
1160void
1161PPFBinaryOutputStream::PutU1s (uint_1 const* tab, size_t n)
1162{
1163 PutArrayTag(1, n, PPS_DATATYPE_UNSIGNED);
1164 PutRawBytes(tab, n*sizeof(uint_1));
1165}
1166
1167void
1168PPFBinaryOutputStream::PutI2 (int_2 val)
1169{
1170 PutRawUByte(PPS_SIMPLE + 2 + PPS_DATATYPE_INTEGER);
1171
1172 if (bigEndian != IS_BIG_ENDIAN)
1173 bswap2(&val);
1174
1175 PutRawBytes(&val, sizeof(int_2));
1176}
1177
1178void
1179PPFBinaryOutputStream::PutI2s (int_2 const* tab, size_t n)
1180{
1181 PutArrayTag(2, n, PPS_DATATYPE_INTEGER);
1182
1183 if (bigEndian == IS_BIG_ENDIAN) {
1184 PutRawBytes(tab, n*sizeof(int_2));
1185 } else {
1186 for (unsigned int i=0; i<n; i++) {
1187 int_2 val = tab[i];
1188 bswap2(&val);
1189 PutRawBytes(&val, sizeof(int_2));
1190 }
1191 }
1192}
1193
1194void
1195PPFBinaryOutputStream::PutU2 (uint_2 val)
1196{
1197 PutRawUByte(PPS_SIMPLE + 2 + PPS_DATATYPE_UNSIGNED);
1198
1199 if (bigEndian != IS_BIG_ENDIAN)
1200 bswap2(&val);
1201
1202 PutRawBytes(&val, sizeof(uint_2));
1203}
1204
1205void
1206PPFBinaryOutputStream::PutU2s (uint_2 const* tab, size_t n)
1207{
1208 PutArrayTag(2, n, PPS_DATATYPE_UNSIGNED);
1209
1210 if (bigEndian == IS_BIG_ENDIAN) {
1211 PutRawBytes(tab, n*sizeof(uint_2));
1212 } else {
1213 for (unsigned int i=0; i<n; i++) {
1214 uint_2 val = tab[i];
1215 bswap2(&val);
1216 PutRawBytes(&val, sizeof(uint_2));
1217 }
1218 }
1219}
1220
1221void
1222PPFBinaryOutputStream::PutI4 (int_4 val)
1223{
1224 PutRawUByte(PPS_SIMPLE + 4 + PPS_DATATYPE_INTEGER);
1225
1226 if (bigEndian != IS_BIG_ENDIAN)
1227 bswap4(&val);
1228
1229 PutRawBytes(&val, sizeof(int_4));
1230}
1231
1232void
1233PPFBinaryOutputStream::PutI4s (int_4 const* tab, size_t n)
1234{
1235 PutArrayTag(4, n, PPS_DATATYPE_INTEGER);
1236
1237 if (bigEndian == IS_BIG_ENDIAN) {
1238 PutRawBytes(tab, n*sizeof(int_4));
1239 } else {
1240 for (unsigned int i=0; i<n; i++) {
1241 int_4 val = tab[i];
1242 bswap4(&val);
1243 PutRawBytes(&val, sizeof(int_4));
1244 }
1245 }
1246}
1247
1248void
1249PPFBinaryOutputStream::PutU4 (uint_4 val)
1250{
1251 PutRawUByte(PPS_SIMPLE + 4 + PPS_DATATYPE_UNSIGNED);
1252
1253 if (bigEndian != IS_BIG_ENDIAN)
1254 bswap4(&val);
1255
1256 PutRawBytes(&val, sizeof(uint_4));
1257}
1258
1259void
1260PPFBinaryOutputStream::PutU4s (uint_4 const* tab, size_t n)
1261{
1262 PutArrayTag(4, n, PPS_DATATYPE_UNSIGNED);
1263
1264 if (bigEndian == IS_BIG_ENDIAN) {
1265 PutRawBytes(tab, n*sizeof(uint_4));
1266 } else {
1267 for (unsigned int i=0; i<n; i++) {
1268 uint_4 val = tab[i];
1269 bswap4(&val);
1270 PutRawBytes(&val, sizeof(uint_4));
1271 }
1272 }
1273}
1274
1275void
1276PPFBinaryOutputStream::PutI8 (int_8 val)
1277{
1278 PutRawUByte(PPS_SIMPLE + 8 + PPS_DATATYPE_INTEGER);
1279
1280 if (bigEndian != IS_BIG_ENDIAN)
1281 bswap8(&val);
1282
1283 PutRawBytes(&val, sizeof(int_8));
1284}
1285
1286void
1287PPFBinaryOutputStream::PutI8s (int_8 const* tab, size_t n)
1288{
1289 PutArrayTag(8, n, PPS_DATATYPE_INTEGER);
1290
1291 if (bigEndian == IS_BIG_ENDIAN) {
1292 PutRawBytes(tab, n*sizeof(int_8));
1293 } else {
1294 for (unsigned int i=0; i<n; i++) {
1295 int_8 val = tab[i];
1296 bswap8(&val);
1297 PutRawBytes(&val, sizeof(int_8));
1298 }
1299 }
1300}
1301
1302void
1303PPFBinaryOutputStream::PutU8 (uint_8 val)
1304{
1305 PutRawUByte(PPS_SIMPLE + 8 + PPS_DATATYPE_UNSIGNED);
1306
1307 if (bigEndian != IS_BIG_ENDIAN)
1308 bswap8(&val);
1309
1310 PutRawBytes(&val, sizeof(uint_8));
1311}
1312
1313void
1314PPFBinaryOutputStream::PutU8s (uint_8 const* tab, size_t n)
1315{
1316 PutArrayTag(8, n, PPS_DATATYPE_UNSIGNED);
1317
1318 if (bigEndian == IS_BIG_ENDIAN) {
1319 PutRawBytes(tab, n*sizeof(uint_8));
1320 } else {
1321 for (unsigned int i=0; i<n; i++) {
1322 uint_8 val = tab[i];
1323 bswap8(&val);
1324 PutRawBytes(&val, sizeof(uint_8));
1325 }
1326 }
1327}
1328
1329void
1330PPFBinaryOutputStream::PutStr(string const& str)
1331{
1332 PutRawUByte(PPS_STRING);
1333 PutRawI4(str.length());
1334 PutRawBytes(str.c_str(), str.length());
1335}
1336
1337void
1338PPFBinaryOutputStream::PutLine(char const* ptr, size_t len)
1339{
1340 string str = ptr;
1341 PutStr(str);
1342}
1343
1344
1345void
1346PPFBinaryOutputStream::PutZ4 (complex<r_4> val)
1347{
1348 PutRawUByte(PPS_SIMPLE + 4 + PPS_DATATYPE_COMPLEX);
1349 r_4 reim[2];
1350 reim[0] = val.real();
1351 reim[1] = val.imag();
1352 if (bigEndian != IS_BIG_ENDIAN) {
1353 bswap4(reim);
1354 bswap4(reim+1);
1355 }
1356 PutRawBytes(reim, 2*sizeof(r_4));
1357}
1358
1359void
1360PPFBinaryOutputStream::PutZ4s (complex<r_4> const* tab, size_t n)
1361{
1362 PutArrayTag(4, n, PPS_DATATYPE_COMPLEX);
1363
1364 if (bigEndian == IS_BIG_ENDIAN) {
1365 PutRawBytes(tab, n*2*sizeof(r_4));
1366 } else {
1367 for (unsigned int i=0; i<n; i++) {
1368 r_4 reim[2];
1369 reim[0] = tab[i].real();
1370 reim[1] = tab[i].imag();
1371 bswap4(reim);
1372 bswap4(reim+1);
1373 PutRawBytes(reim, 2*sizeof(r_4));
1374 }
1375 }
1376}
1377
1378void
1379PPFBinaryOutputStream::PutZ8 (complex<r_8> val)
1380{
1381 PutRawUByte(PPS_SIMPLE + 8 + PPS_DATATYPE_COMPLEX);
1382 r_8 reim[2];
1383 reim[0] = val.real();
1384 reim[1] = val.imag();
1385 if (bigEndian != IS_BIG_ENDIAN) {
1386 bswap8(reim);
1387 bswap8(reim+1);
1388 }
1389 PutRawBytes(reim, 2*sizeof(r_8));
1390}
1391
1392void
1393PPFBinaryOutputStream::PutZ8s (complex<r_8> const* tab, size_t n)
1394{
1395 PutArrayTag(8, n, PPS_DATATYPE_COMPLEX);
1396
1397 if (bigEndian == IS_BIG_ENDIAN) {
1398 PutRawBytes(tab, n*2*sizeof(r_8));
1399 } else {
1400 for (unsigned int i=0; i<n; i++) {
1401 r_8 reim[2];
1402 reim[0] = tab[i].real();
1403 reim[1] = tab[i].imag();
1404 bswap8(reim);
1405 bswap8(reim+1);
1406 PutRawBytes(reim, 2*sizeof(r_8));
1407 }
1408 }
1409}
1410
1411void
1412PPFBinaryOutputStream::PutPosTagTable(int_8 const * ptab, size_t sz)
1413{
1414 PutRawUByte(PPS_POSTAG_TABLE);
1415 int_4 tsz = sz;
1416 PutRawI4(tsz);
1417 for(int kk=0; kk<tsz; kk++)
1418 PutRawI8(ptab[kk]);
1419 return;
1420}
1421
1422void
1423PPFBinaryOutputStream::PutPosTagTable(vector<int_8> const& ptab)
1424{
1425 PutRawUByte(PPS_POSTAG_TABLE);
1426 int_4 tsz = ptab.size();
1427 PutRawI4(tsz);
1428 for(int kk=0; kk<tsz; kk++)
1429 PutRawI8(ptab[kk]);
1430 return;
1431}
1432
Note: See TracBrowser for help on using the repository browser.