Changeset 2476 in Sophya for trunk/SophyaLib/BaseTools
- Timestamp:
- Dec 5, 2003, 12:02:27 AM (22 years ago)
- Location:
- trunk/SophyaLib/BaseTools
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/BaseTools/ppersist.cc
r2475 r2476 180 180 } 181 181 182 static inline void bswap8_hash(void* p) 183 { 184 uint_8 tmp = *(uint_8*)p; 185 *(uint_8*)p = ((tmp >> (7*8)) & 0x000000FF) | 186 ((tmp >> (5*8)) & 0x0000FF00) | 187 ((tmp >> (3*8)) & 0x00FF0000) | 188 ((tmp >> (1*8)) & 0xFF000000) | 189 ((tmp & 0xFF000000) << (1*8)) | 190 ((tmp & 0x00FF0000) << (3*8)) | 191 ((tmp & 0x0000FF00) << (5*8)) | 192 ((tmp & 0x000000FF) << (7*8)); 193 } 182 194 183 195 … … 190 202 uint_8 hash2 = *((uint_8*) (ctx.buf+8)); 191 203 #if IS_BIG_ENDIAN 192 bswap8 (&hash1);193 bswap8 (&hash2);204 bswap8_hash(&hash1); 205 bswap8_hash(&hash2); 194 206 #endif 195 207 … … 628 640 objreftag rt; 629 641 rt.ppsoid = id; 642 // cout << " DBG-rt.ppspos = s->tellp(); " << endl; 630 643 rt.ppspos = s->tellp(); 644 // cout << " DBG-rt.ppspos = s->tellp(); = " << rt.ppspos << endl; 631 645 objList[mid] = rt; 632 646 } -
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 -
trunk/SophyaLib/BaseTools/ppfbinstream.h
r2475 r2476 55 55 }; 56 56 57 PPFBinaryIOStream() ;58 virtual ~PPFBinaryIOStream() ;57 PPFBinaryIOStream() { } 58 virtual ~PPFBinaryIOStream() { } 59 59 int Version() {return version;} // PIn/OutPersist version number 60 string FileName() { return filename; } // Retourne le nom de fichier61 60 62 61 protected: 63 62 64 63 map<string, int_8> tags; 65 string filename;66 64 int version; // PPersist(In/Out) version 67 65 }; … … 71 69 class PPFBinaryInputStream : public PPFBinaryIOStream { 72 70 public: 73 PPFBinaryInputStream( );71 PPFBinaryInputStream(RawInOutStream * is, bool ad, bool scan=false); 74 72 PPFBinaryInputStream(string const& flnm, bool scan=true); 75 73 virtual ~PPFBinaryInputStream(); 74 75 inline string FileName() { return s->getFileName(); } // Retourne le nom de fichier 76 76 77 77 // Gestion des tags … … 85 85 // Saut jusqu'au prochain objet 86 86 bool SkipToNextObject(); 87 // Saut d'un item de base (tag+donnees correspondantes) 88 bool SkipItem(); 87 // Saut d'un item de base (tag+donnees correspondantes), le suivant ds le flot 88 bool SkipNextItem(); 89 // Lecture du tag de type next item + infos correspondantes 90 // Le stream est re-positionne avant le tag 91 char NextItemTag(short datasz, size_t sz); 89 92 90 93 // Lecture donnees de base et tableaux de donnees de base … … 157 160 158 161 protected: 162 void Init(bool scan); 163 void ReadNameTagTableV2(); 164 void ReadNameTagTable(); 165 166 void SkipItem(bool fgrdi, char itag); 167 159 168 void CheckTag (short datasz, short datatype); 160 169 void CheckArrayTag(short datasz, size_t sz, short datatype); … … 168 177 void GetRawU8 (uint_8&); 169 178 170 void Scan();171 172 179 RawInOutStream* s; 180 bool _ads; // delete/close the stream at the end 173 181 174 182 bool bigEndian; … … 181 189 class PPFBinaryOutputStream : public PPFBinaryIOStream { 182 190 public: 183 PPFBinaryOutputStream( );191 PPFBinaryOutputStream(RawInOutStream* os, bool ad, int endianness = PPS_NATIVE); 184 192 PPFBinaryOutputStream(string const& flnm, int endianness = PPS_NATIVE); 185 193 virtual ~PPFBinaryOutputStream(); 194 195 inline string FileName() { return s->getFileName(); } // Retourne le nom de fichier 186 196 187 197 // Ecriture de tags … … 253 263 254 264 protected: 255 RawInOutStream* s; 256 bool bigEndian; 257 265 void Init(int endianness); 266 void WriteNameTagTable(); 267 void WriteNameTagTableV2(); 268 258 269 void PutArrayTag(short datasz, size_t sz, short datatype); 259 270 void PutRawByte (char); … … 264 275 void PutRawU8 (uint_8); 265 276 void PutRawBytes(void const* ptr, size_t bytes); 266 277 278 // Attributs, variables 279 RawInOutStream* s; 280 bool _ads; // delete/close the stream at the end 281 282 bool bigEndian; 283 267 284 }; 268 285 -
trunk/SophyaLib/BaseTools/rawstream.h
r2458 r2476 28 28 virtual RawInOutStream& seekp(int_8, int sd = ios::beg); 29 29 virtual RawInOutStream& write(const char* s, uint_8 n); 30 inline std::string getFileName() const { return _filename; } 31 protected: 32 std::string _filename; 33 30 34 }; 31 35 … … 43 47 virtual RawInOutStream& read(char* s, uint_8 n); 44 48 45 inline std::string getFileName() const { return _filename; }46 49 protected: 47 50 FILE * fip; 48 std::string _filename;49 51 }; 50 52 … … 62 64 virtual RawInOutStream& write(const char* s, uint_8 n); 63 65 64 inline std::string getFileName() const { return _filename; }65 66 protected: 66 67 FILE * fip; 67 std::string _filename;68 68 }; 69 69 -
trunk/SophyaLib/BaseTools/sversion.h
r2459 r2476 3 3 4 4 #define SOPHYA_VERSION 1.8 5 #define SOPHYA_REVISION 15 #define SOPHYA_REVISION 2 6 6 #define SOPHYA_TAG "V_Oct2003" 7 7
Note:
See TracChangeset
for help on using the changeset viewer.