Changeset 2476 in Sophya for trunk/SophyaLib/BaseTools/ppfbinstream.cc
- Timestamp:
- Dec 5, 2003, 12:02:27 AM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/BaseTools/ppfbinstream.cc
r2475 r2476 50 50 51 51 52 PPFBinaryInputStream::PPFBinaryInputStream( )53 { 54 s = NULL;55 version = 0;56 bigEndian = true;52 PPFBinaryInputStream::PPFBinaryInputStream(RawInOutStream * is, bool ad, bool scan) 53 { 54 s = is; 55 _ads = ad; 56 Init(scan); 57 57 } 58 58 … … 64 64 { 65 65 s = new RawInFileStream(flnm.c_str()); 66 66 _ads = true; 67 Init(scan); 68 } 69 70 PPFBinaryInputStream::~PPFBinaryInputStream() 71 { 72 if (_ads && (s!=NULL) ) delete s; 73 } 74 75 void 76 PPFBinaryInputStream::Init(bool scan) 77 { 67 78 // Read and check header 68 79 … … 75 86 version = atoi(rbuf+25); 76 87 if (version < 2) { 77 cerr << "PPFBinaryInputStream::PPFBinaryInputStream(" << flnm<< ") Version(=" << version88 cerr << "PPFBinaryInputStream::PPFBinaryInputStream(" << FileName() << ") Version(=" << version 78 89 << ") < 2 not supported !" << endl; 79 90 throw FileFormatExc("PPFBinaryInputStream::PPFBinaryInputStream() - Unsupported (Old) Version"); … … 104 115 105 116 creationdate = mktime(&tm); 106 filename = flnm; // keep the filename107 117 seqread = true; // To flag non sequential reads 108 if (scan && s->isSeekable()) Scan(); 109 } 110 111 112 113 PPFBinaryInputStream::~PPFBinaryInputStream() 114 { 115 if (s) delete s; 116 } 118 if (scan && s->isSeekable()) { 119 if (Version() >= 3) ReadNameTagTable(); 120 else ReadNameTagTableV2(); 121 } 122 } 123 124 125 117 126 118 127 … … 126 135 127 136 void 128 PPFBinaryInputStream::Scan() 129 { 130 // On cherche la liste des tags, a la fin du fichier 131 137 PPFBinaryInputStream::ReadNameTagTable() 138 { 132 139 unsigned char ppstype; 133 140 int_8 debut; … … 138 145 GetTypeTag(ppstype); 139 146 if (ppstype != PPS_EOF) 140 throw FileFormatExc("PPFBinaryInputStream::Scan corrupted file, no eof entry at end of file"); 147 throw FileFormatExc("PPFBinaryInputStream::ReadNameTagTable() Corrupted file, no EOF tag at end of file"); 148 149 // Lecture position NameTagTable 150 int_8 pos; 151 GetRawI8(pos); 152 if (pos < 0) { // no tags 153 s->seekg(debut); 154 return; 155 } 156 157 // On se positionne au debut du NameTagTable 158 s->seekg(pos); 159 GetTypeTag(ppstype); 160 if (ppstype != PPS_NAMETAG_TABLE) 161 throw FileFormatExc("PPFBinaryInputStream::ReadNameTagTable() Corrupted file PPS_NAMETAG_TABLE not found"); 162 uint_8 ttsz,it; 163 GetU8(ttsz); 164 for(it=0; it<ttsz; it++) { 165 int_8 tpos; 166 string tname; 167 GetI8(tpos); 168 GetStr(tname); 169 tags[tname] = tpos; 170 } 171 // On revient au debut du float, juste apres l'entete 172 s->seekg(debut); 173 } 174 175 void 176 PPFBinaryInputStream::ReadNameTagTableV2() 177 { 178 // On cherche la liste des tags, a la fin du fichier 179 180 unsigned char ppstype; 181 int_8 debut; 182 debut = s->tellg(); 183 184 s->seekg(-(sizeof(int_8)+1), ios::end); 185 186 GetTypeTag(ppstype); 187 if (ppstype != PPS_EOF) 188 throw FileFormatExc("PPFBinaryInputStream::ReadNameTagTableV2() Corrupted file, no eof entry at end of file"); 141 189 142 190 int_8 pos; … … 154 202 155 203 if (ppstype != PPS_NAMETAG_TABLE) 156 throw FileFormatExc("PPFBinaryInputStream:: Scan corrupted file, bad tag entry");204 throw FileFormatExc("PPFBinaryInputStream::ReadNameTagTableV2() Corrupted file, bad tag entry"); 157 205 158 206 GetRawI8(pos); … … 160 208 GetRawI4(len); 161 209 if (len > MAXTAGLEN_V2) 162 throw FileFormatExc("PPFBinaryInputStream:: Scan corrupted file, tag name too long");210 throw FileFormatExc("PPFBinaryInputStream::ReadNameTagTableV2() Corrupted file, tag name too long"); 163 211 GetRawBytes(buffer, len); 164 212 buffer[len] = '\0'; … … 242 290 243 291 bool 244 PPFBinaryInputStream::Skip Item()292 PPFBinaryInputStream::SkipNextItem() 245 293 { 246 294 // A FAIRE NOV 2003 - REZA 247 295 return true; 296 } 297 298 char 299 PPFBinaryInputStream::NextItemTag(short datasz, size_t sz) 300 { 301 datasz = 0; 302 sz = 0; 303 return 0; 304 } 305 306 void 307 PPFBinaryInputStream::SkipItem(bool fgrdt, char itag) 308 { 309 return; 248 310 } 249 311 … … 888 950 //-- 889 951 890 PPFBinaryOutputStream::PPFBinaryOutputStream() 891 { 892 s = NULL; 893 version = 0; 952 PPFBinaryOutputStream::PPFBinaryOutputStream(RawInOutStream* os, bool ad, int endianness) 953 { 954 s = os; 955 _ads = ad; 956 Init(endianness); 894 957 } 895 958 896 959 PPFBinaryOutputStream::PPFBinaryOutputStream(string const& flnm, int endianness) 960 { 961 // Output stream creation 962 s = new RawOutFileStream(flnm.c_str()); 963 _ads = true; 964 Init(endianness); 965 } 966 967 PPFBinaryOutputStream::~PPFBinaryOutputStream() 968 { 969 WriteNameTagTable(); 970 if (_ads && (s != NULL)) delete s; // Close the stream 971 } 972 973 void 974 PPFBinaryOutputStream::Init(int endianness) 897 975 { 898 976 if (endianness == -1) … … 901 979 bigEndian = endianness; 902 980 903 // Output stream creation904 s = new RawOutFileStream(flnm.c_str());905 981 version = 3; 906 982 // Header … … 917 993 datestring[32] = '\0'; 918 994 PutRawBytes(datestring, 32); 919 filename = flnm; 920 } 921 922 PPFBinaryOutputStream::~PPFBinaryOutputStream() 995 } 996 997 void 998 PPFBinaryOutputStream::WriteNameTagTable() 999 { 1000 if (tags.size() == 0) { 1001 PutRawUByte(PPS_EOF); 1002 PutRawI8(-1); 1003 } 1004 else { 1005 int_8 tagPos; 1006 tagPos = s->tellp(); 1007 PutRawUByte(PPS_NAMETAG_TABLE); // This is a tag 1008 PutU8((uint_8)tags.size()); // Number of tags 1009 for (map<string,int_8>::iterator i = tags.begin(); i != tags.end(); i++) { 1010 int_8 pos = (*i).second; 1011 PutI8(pos); 1012 PutStr((*i).first); 1013 } 1014 PutRawUByte(PPS_EOF); 1015 PutRawI8(tagPos); 1016 } 1017 1018 } 1019 1020 void 1021 PPFBinaryOutputStream::WriteNameTagTableV2() 923 1022 { 924 1023 if (tags.size() == 0) { … … 940 1039 } 941 1040 942 delete s; // Close the stream 943 } 1041 } 1042 944 1043 945 1044 int_8
Note:
See TracChangeset
for help on using the changeset viewer.