| 1 | |
| 2 | #include "stdafx.h" |
| 3 | |
| 4 | #include "FSD_CArchive.hxx" |
| 5 | #include "FSD_Archive.ixx" |
| 6 | |
| 7 | #include <FSD_CFile.hxx> |
| 8 | |
| 9 | #define FSD_REF 'R' |
| 10 | #define FSD_CHA 'c' |
| 11 | #define FSD_EXT 'C' |
| 12 | #define FSD_INT 'I' |
| 13 | #define FSD_BOO 'B' |
| 14 | #define FSD_REA 'F' |
| 15 | #define FSD_SHO 'f' |
| 16 | #define FSD_END 'E' |
| 17 | |
| 18 | const Standard_CString MAGICNUMBER = "FSDARCH"; |
| 19 | |
| 20 | FSD_Archive::FSD_Archive() |
| 21 | { |
| 22 | myStream = NULL; |
| 23 | myEof = Standard_False; |
| 24 | myExternFlag = Standard_False; |
| 25 | myCFile = NULL; |
| 26 | myFormat = Standard_False; |
| 27 | } |
| 28 | |
| 29 | FSD_Archive::FSD_Archive(const FSD_CArchive& anArchive) |
| 30 | { |
| 31 | myStream = anArchive; |
| 32 | myEof = Standard_False; |
| 33 | myExternFlag = Standard_True; |
| 34 | myCFile = NULL; |
| 35 | myFormat = Standard_False; |
| 36 | #ifdef WNT |
| 37 | if (myStream->IsLoading()) SetOpenMode(Storage_VSRead); |
| 38 | else SetOpenMode(Storage_VSWrite); |
| 39 | #endif |
| 40 | } |
| 41 | |
| 42 | Storage_Error FSD_Archive::IsGoodFileType(const TCollection_AsciiString& |
| 43 | #ifdef WNT |
| 44 | aName |
| 45 | #endif |
| 46 | ) |
| 47 | { |
| 48 | FSD_Archive f; |
| 49 | Storage_Error s; |
| 50 | #ifdef WNT |
| 51 | s = f.Open(aName,Storage_VSRead); |
| 52 | |
| 53 | if (s == Storage_VSOk) { |
| 54 | TCollection_AsciiString l; |
| 55 | Standard_Integer len = strlen(FSD_Archive::MagicNumber()); |
| 56 | |
| 57 | f.ReadChar(l,len); |
| 58 | |
| 59 | f.Close(); |
| 60 | |
| 61 | if (strncmp(FSD_Archive::MagicNumber(),l.ToCString(),len) != 0) { |
| 62 | s = Storage_VSFormatError; |
| 63 | } |
| 64 | } |
| 65 | #else |
| 66 | s = Storage_VSFormatError; |
| 67 | #endif |
| 68 | return s; |
| 69 | } |
| 70 | |
| 71 | Storage_Error FSD_Archive::Open(const TCollection_AsciiString& aName, |
| 72 | const Storage_OpenMode |
| 73 | #ifdef WNT |
| 74 | aMode |
| 75 | #endif |
| 76 | ) |
| 77 | { |
| 78 | Storage_Error result = Storage_VSOk; |
| 79 | |
| 80 | SetName(aName); |
| 81 | #ifdef WNT |
| 82 | if (OpenMode() == Storage_VSNone) { |
| 83 | if (aMode == Storage_VSRead) { |
| 84 | if (!((FSD_CFile*)myCFile)->Open(aName.ToCString(),CFile::modeRead)) |
| 85 | result = Storage_VSOpenError; |
| 86 | } |
| 87 | else if (aMode == Storage_VSWrite) { |
| 88 | if (!((FSD_CFile*)myCFile)->Open(aName.ToCString(),CFile::modeCreate | CFile::modeWrite)) |
| 89 | result = Storage_VSOpenError; |
| 90 | } |
| 91 | else if (aMode == Storage_VSReadWrite) { |
| 92 | if (!((FSD_CFile*)myCFile)->Open(aName.ToCString(),CFile::modeReadWrite)) |
| 93 | result = Storage_VSOpenError; |
| 94 | } |
| 95 | if (result == Storage_VSOk) { |
| 96 | if (aMode == Storage_VSRead) { |
| 97 | myStream = new CArchive( ((FSD_CFile*)myCFile), CArchive::load); |
| 98 | } |
| 99 | else { |
| 100 | myStream = new CArchive( ((FSD_CFile*)myCFile), CArchive::store); |
| 101 | } |
| 102 | |
| 103 | SetOpenMode(aMode); |
| 104 | } |
| 105 | |
| 106 | myEof = Standard_False; |
| 107 | |
| 108 | } |
| 109 | else { |
| 110 | result = Storage_VSAlreadyOpen; |
| 111 | } |
| 112 | #else |
| 113 | result = Storage_VSOpenError; |
| 114 | #endif |
| 115 | return result; |
| 116 | } |
| 117 | |
| 118 | Standard_Boolean FSD_Archive::IsEnd() |
| 119 | { |
| 120 | return myEof; |
| 121 | } |
| 122 | |
| 123 | Storage_Error FSD_Archive::Close() |
| 124 | { |
| 125 | Storage_Error result = Storage_VSOk; |
| 126 | |
| 127 | myEof = Standard_False; |
| 128 | |
| 129 | if (OpenMode() != Storage_VSNone) { |
| 130 | #ifdef WNT |
| 131 | if (!myExternFlag) { |
| 132 | (*myStream).Close(); |
| 133 | ((FSD_CFile*)myCFile)->Close(); |
| 134 | delete myStream; |
| 135 | } |
| 136 | myExternFlag = Standard_False; |
| 137 | myStream = NULL; |
| 138 | SetOpenMode(Storage_VSNone); |
| 139 | #endif |
| 140 | } |
| 141 | else { |
| 142 | result = Storage_VSNotOpen; |
| 143 | } |
| 144 | |
| 145 | return result; |
| 146 | } |
| 147 | |
| 148 | // ------------------ PROTECTED |
| 149 | |
| 150 | const Standard_CString FSD_Archive::MagicNumber() |
| 151 | { |
| 152 | return MAGICNUMBER; |
| 153 | } |
| 154 | |
| 155 | |
| 156 | void FSD_Archive::ReadLine(TCollection_AsciiString& |
| 157 | #ifdef WNT |
| 158 | buffer |
| 159 | #endif |
| 160 | ) |
| 161 | { |
| 162 | #ifdef WNT |
| 163 | TRY { |
| 164 | char c; |
| 165 | Standard_Boolean IsEnd = Standard_False; |
| 166 | |
| 167 | buffer.Clear(); |
| 168 | |
| 169 | while (!IsEnd) { |
| 170 | (*myStream) >> c; |
| 171 | |
| 172 | if (c != '\0') { |
| 173 | buffer += c; |
| 174 | } |
| 175 | else { |
| 176 | buffer += c; |
| 177 | IsEnd = Standard_True; |
| 178 | } |
| 179 | } |
| 180 | } |
| 181 | CATCH(CArchiveException,e) { |
| 182 | if (e->m_cause == CArchiveException::endOfFile) myEof = Standard_True; |
| 183 | } |
| 184 | END_CATCH |
| 185 | #endif |
| 186 | } |
| 187 | |
| 188 | void FSD_Archive::WriteLine(const TCollection_AsciiString& |
| 189 | #ifdef WNT |
| 190 | buffer |
| 191 | #endif |
| 192 | ) |
| 193 | { |
| 194 | #ifdef WNT |
| 195 | Standard_Integer i; |
| 196 | for (i = 1; i <= buffer.Length(); i++) { |
| 197 | (*myStream) << buffer.Value(i); |
| 198 | } |
| 199 | (*myStream) << (Standard_Character)0; |
| 200 | #endif |
| 201 | } |
| 202 | |
| 203 | void FSD_Archive::WriteExtendedLine(const TCollection_ExtendedString& |
| 204 | #ifdef WNT |
| 205 | buffer |
| 206 | #endif |
| 207 | ) |
| 208 | { |
| 209 | #ifdef WNT |
| 210 | Standard_ExtString extBuffer; |
| 211 | Standard_Integer i; |
| 212 | |
| 213 | extBuffer = buffer.ToExtString(); |
| 214 | |
| 215 | for (i = 0; i < buffer.Length(); i++) { |
| 216 | (*myStream) << extBuffer[i]; |
| 217 | } |
| 218 | |
| 219 | (*myStream) << (Standard_ExtCharacter)0; |
| 220 | #endif |
| 221 | } |
| 222 | |
| 223 | void FSD_Archive::ReadExtendedLine(TCollection_ExtendedString& |
| 224 | #ifdef WNT |
| 225 | buffer |
| 226 | #endif |
| 227 | ) |
| 228 | { |
| 229 | #ifdef WNT |
| 230 | TRY { |
| 231 | Standard_ExtCharacter i = 0; |
| 232 | Standard_Boolean fin = Standard_False; |
| 233 | |
| 234 | buffer.Clear(); |
| 235 | |
| 236 | while (!fin) { |
| 237 | (*myStream) >> i; |
| 238 | if (i == 0) fin = Standard_True; |
| 239 | else buffer += (Standard_ExtCharacter)i; |
| 240 | } |
| 241 | } |
| 242 | CATCH(CArchiveException,e) { |
| 243 | if (e->m_cause == CArchiveException::endOfFile) myEof = Standard_True; |
| 244 | } |
| 245 | END_CATCH |
| 246 | #endif |
| 247 | } |
| 248 | |
| 249 | void FSD_Archive::ReadChar(TCollection_AsciiString& |
| 250 | #ifdef WNT |
| 251 | buffer |
| 252 | #endif |
| 253 | ,const Standard_Integer |
| 254 | #ifdef WNT |
| 255 | rsize |
| 256 | #endif |
| 257 | ) |
| 258 | { |
| 259 | #ifdef WNT |
| 260 | TRY { |
| 261 | char c; |
| 262 | Standard_Integer ccount = 0; |
| 263 | |
| 264 | buffer.Clear(); |
| 265 | |
| 266 | while (ccount < rsize) { |
| 267 | (*myStream) >> c; |
| 268 | buffer += c; |
| 269 | ccount++; |
| 270 | } |
| 271 | } |
| 272 | CATCH(CArchiveException,e) { |
| 273 | if (e->m_cause == CArchiveException::endOfFile) myEof = Standard_True; |
| 274 | } |
| 275 | END_CATCH |
| 276 | #endif |
| 277 | } |
| 278 | |
| 279 | |
| 280 | Storage_Error FSD_Archive::FindTag(const Standard_CString |
| 281 | #ifdef WNT |
| 282 | aTag |
| 283 | #endif |
| 284 | ) |
| 285 | { |
| 286 | #ifdef WNT |
| 287 | TCollection_AsciiString l; |
| 288 | Standard_CString str; |
| 289 | |
| 290 | ReadLine(l); |
| 291 | str = l.ToCString(); |
| 292 | |
| 293 | Standard_Integer aNum = 0; |
| 294 | |
| 295 | if(!myFormat) |
| 296 | aNum = 1; |
| 297 | |
| 298 | while ((strcmp(&str[aNum],aTag) != 0) && !IsEnd()) { |
| 299 | // while ((strcmp(&str[1],aTag) != 0) && !IsEnd()) { |
| 300 | ReadLine(l); |
| 301 | str = l.ToCString(); |
| 302 | } |
| 303 | |
| 304 | if (IsEnd()) { |
| 305 | return Storage_VSSectionNotFound; |
| 306 | } |
| 307 | else { |
| 308 | return Storage_VSOk; |
| 309 | } |
| 310 | #else |
| 311 | return Storage_VSSectionNotFound; |
| 312 | #endif |
| 313 | } |
| 314 | |
| 315 | void FSD_Archive::SkipObject() |
| 316 | { |
| 317 | #ifdef WNT |
| 318 | Standard_Boolean errorStatus = Standard_False; |
| 319 | TRY { |
| 320 | char c; |
| 321 | Standard_Boolean IsEnd = Standard_False; |
| 322 | Standard_Integer rtmp,itmp; |
| 323 | Standard_Real ftmp; |
| 324 | Standard_ShortReal stmp; |
| 325 | Standard_Integer btmp; |
| 326 | Standard_Character ctmp; |
| 327 | Standard_ExtCharacter etmp; |
| 328 | |
| 329 | ReadPersistentObjectHeader(rtmp,itmp); |
| 330 | |
| 331 | while (!IsEnd) { |
| 332 | (*myStream) >> c; |
| 333 | |
| 334 | switch (c) { |
| 335 | case FSD_REF: |
| 336 | (*myStream) >> rtmp; |
| 337 | break; |
| 338 | case FSD_CHA: |
| 339 | (*myStream) >> ctmp; |
| 340 | break; |
| 341 | case FSD_EXT: |
| 342 | (*myStream) >> etmp; |
| 343 | break; |
| 344 | case FSD_INT: |
| 345 | (*myStream) >> itmp; |
| 346 | break; |
| 347 | case FSD_BOO: |
| 348 | (*myStream) >> btmp; |
| 349 | break; |
| 350 | case FSD_REA: |
| 351 | (*myStream) >> ftmp; |
| 352 | break; |
| 353 | case FSD_SHO: |
| 354 | (*myStream) >> stmp; |
| 355 | break; |
| 356 | case FSD_END: |
| 357 | IsEnd = Standard_True; |
| 358 | break; |
| 359 | default: |
| 360 | errorStatus = Standard_True; |
| 361 | IsEnd = Standard_True; |
| 362 | break; |
| 363 | } |
| 364 | } |
| 365 | } |
| 366 | CATCH(CArchiveException,e) { |
| 367 | if ((e->m_cause != CArchiveException::endOfFile) && |
| 368 | (e->m_cause != CArchiveException::none)) errorStatus = Standard_True; |
| 369 | else if (e->m_cause == CArchiveException::endOfFile) myEof = Standard_True; |
| 370 | } |
| 371 | END_CATCH |
| 372 | #endif |
| 373 | } |
| 374 | |
| 375 | // ---------------------- PUBLIC : PUT |
| 376 | |
| 377 | Storage_BaseDriver& FSD_Archive::PutReference(const Standard_Integer |
| 378 | #ifdef WNT |
| 379 | aValue |
| 380 | #endif |
| 381 | ) |
| 382 | { |
| 383 | #ifdef WNT |
| 384 | Standard_Boolean errorStatus = Standard_False; |
| 385 | |
| 386 | TRY { |
| 387 | (*myStream) << FSD_REF << aValue; |
| 388 | } |
| 389 | CATCH(CArchiveException,e) { |
| 390 | errorStatus = Standard_True; |
| 391 | } |
| 392 | END_CATCH |
| 393 | |
| 394 | if (errorStatus) Storage_StreamWriteError::Raise(); |
| 395 | #endif |
| 396 | return *this; |
| 397 | } |
| 398 | |
| 399 | Storage_BaseDriver& FSD_Archive::PutCharacter(const Standard_Character |
| 400 | #ifdef WNT |
| 401 | aValue |
| 402 | #endif |
| 403 | ) |
| 404 | { |
| 405 | #ifdef WNT |
| 406 | Standard_Boolean errorStatus = Standard_False; |
| 407 | |
| 408 | TRY { |
| 409 | //unsigned short i = aValue; |
| 410 | //(*myStream) << FSD_CHA << i; |
| 411 | (*myStream) << FSD_CHA << aValue; |
| 412 | } |
| 413 | CATCH(CArchiveException,e) { |
| 414 | errorStatus = Standard_True; |
| 415 | } |
| 416 | END_CATCH |
| 417 | |
| 418 | if (errorStatus) Storage_StreamWriteError::Raise(); |
| 419 | #endif |
| 420 | return *this; |
| 421 | } |
| 422 | |
| 423 | Storage_BaseDriver& FSD_Archive::PutExtCharacter(const Standard_ExtCharacter |
| 424 | #ifdef WNT |
| 425 | aValue |
| 426 | #endif |
| 427 | ) |
| 428 | { |
| 429 | #ifdef WNT |
| 430 | Standard_Boolean errorStatus = Standard_False; |
| 431 | TRY { |
| 432 | (*myStream) << FSD_EXT << aValue; |
| 433 | } |
| 434 | CATCH(CArchiveException,e) { |
| 435 | errorStatus = Standard_True; |
| 436 | } |
| 437 | END_CATCH |
| 438 | |
| 439 | if (errorStatus) Storage_StreamWriteError::Raise(); |
| 440 | #endif |
| 441 | return *this; |
| 442 | } |
| 443 | |
| 444 | Storage_BaseDriver& FSD_Archive::PutInteger(const Standard_Integer |
| 445 | #ifdef WNT |
| 446 | aValue |
| 447 | #endif |
| 448 | ) |
| 449 | { |
| 450 | #ifdef WNT |
| 451 | Standard_Boolean errorStatus = Standard_False; |
| 452 | TRY { |
| 453 | (*myStream) << FSD_INT << aValue; |
| 454 | } |
| 455 | CATCH(CArchiveException,e) { |
| 456 | errorStatus = Standard_True; |
| 457 | } |
| 458 | END_CATCH |
| 459 | |
| 460 | if (errorStatus) Storage_StreamWriteError::Raise(); |
| 461 | #endif |
| 462 | return *this; |
| 463 | } |
| 464 | |
| 465 | Storage_BaseDriver& FSD_Archive::PutBoolean(const Standard_Boolean |
| 466 | #ifdef WNT |
| 467 | aValue |
| 468 | #endif |
| 469 | ) |
| 470 | { |
| 471 | #ifdef WNT |
| 472 | Standard_Boolean errorStatus = Standard_False; |
| 473 | TRY { |
| 474 | (*myStream) << FSD_BOO << ((Standard_Integer)aValue); |
| 475 | } |
| 476 | CATCH(CArchiveException,e) { |
| 477 | errorStatus = Standard_True; |
| 478 | } |
| 479 | END_CATCH |
| 480 | |
| 481 | if (errorStatus) Storage_StreamWriteError::Raise(); |
| 482 | #endif |
| 483 | return *this; |
| 484 | } |
| 485 | |
| 486 | Storage_BaseDriver& FSD_Archive::PutReal(const Standard_Real |
| 487 | #ifdef WNT |
| 488 | aValue |
| 489 | #endif |
| 490 | ) |
| 491 | { |
| 492 | #ifdef WNT |
| 493 | Standard_Boolean errorStatus = Standard_False; |
| 494 | TRY { |
| 495 | (*myStream) << FSD_REA << ((Standard_Real)aValue); |
| 496 | } |
| 497 | CATCH(CArchiveException,e) { |
| 498 | errorStatus = Standard_True; |
| 499 | } |
| 500 | END_CATCH |
| 501 | |
| 502 | if (errorStatus) Storage_StreamWriteError::Raise(); |
| 503 | #endif |
| 504 | return *this; |
| 505 | } |
| 506 | |
| 507 | Storage_BaseDriver& FSD_Archive::PutShortReal(const Standard_ShortReal |
| 508 | #ifdef WNT |
| 509 | aValue |
| 510 | #endif |
| 511 | ) |
| 512 | { |
| 513 | #ifdef WNT |
| 514 | Standard_Boolean errorStatus = Standard_False; |
| 515 | TRY { |
| 516 | (*myStream) << FSD_SHO << aValue; |
| 517 | } |
| 518 | CATCH(CArchiveException,e) { |
| 519 | errorStatus = Standard_True; |
| 520 | } |
| 521 | END_CATCH |
| 522 | |
| 523 | if (errorStatus) Storage_StreamWriteError::Raise(); |
| 524 | #endif |
| 525 | return *this; |
| 526 | } |
| 527 | |
| 528 | // ----------------- PUBLIC : GET |
| 529 | |
| 530 | Storage_BaseDriver& FSD_Archive::GetReference(Standard_Integer& |
| 531 | #ifdef WNT |
| 532 | aValue |
| 533 | #endif |
| 534 | ) |
| 535 | { |
| 536 | #ifdef WNT |
| 537 | Standard_Boolean errorStatus = Standard_False; |
| 538 | TRY { |
| 539 | char ptype; |
| 540 | (*myStream) >> ptype; |
| 541 | if (ptype == FSD_REF) |
| 542 | (*myStream) >> aValue; |
| 543 | else errorStatus = Standard_True; |
| 544 | } |
| 545 | CATCH(CArchiveException,e) { |
| 546 | if (e->m_cause == CArchiveException::endOfFile) myEof = Standard_True; |
| 547 | else errorStatus = Standard_True; |
| 548 | } |
| 549 | END_CATCH |
| 550 | |
| 551 | if (errorStatus) Storage_StreamTypeMismatchError::Raise(); |
| 552 | #endif |
| 553 | return *this; |
| 554 | } |
| 555 | |
| 556 | Storage_BaseDriver& FSD_Archive::GetCharacter(Standard_Character& |
| 557 | #ifdef WNT |
| 558 | aValue |
| 559 | #endif |
| 560 | ) |
| 561 | { |
| 562 | #ifdef WNT |
| 563 | Standard_Boolean errorStatus = Standard_False; |
| 564 | TRY { |
| 565 | //unsigned short i; |
| 566 | Standard_Character i; |
| 567 | char ptype; |
| 568 | (*myStream) >> ptype; |
| 569 | if (ptype == FSD_CHA) { |
| 570 | (*myStream) >> i; |
| 571 | aValue = (char)i; |
| 572 | } |
| 573 | else errorStatus = Standard_True; |
| 574 | } |
| 575 | CATCH(CArchiveException,e) { |
| 576 | if (e->m_cause == CArchiveException::endOfFile) myEof = Standard_True; |
| 577 | else errorStatus = Standard_True; |
| 578 | } |
| 579 | END_CATCH |
| 580 | |
| 581 | if (errorStatus) Storage_StreamTypeMismatchError::Raise(); |
| 582 | #endif |
| 583 | return *this; |
| 584 | } |
| 585 | |
| 586 | Storage_BaseDriver& FSD_Archive::GetExtCharacter(Standard_ExtCharacter& |
| 587 | #ifdef WNT |
| 588 | aValue |
| 589 | #endif |
| 590 | ) |
| 591 | { |
| 592 | #ifdef WNT |
| 593 | Standard_Boolean errorStatus = Standard_False; |
| 594 | TRY { |
| 595 | char ptype; |
| 596 | (*myStream) >> ptype; |
| 597 | if (ptype == FSD_EXT) |
| 598 | (*myStream) >> aValue; |
| 599 | else errorStatus = Standard_True; |
| 600 | } |
| 601 | CATCH(CArchiveException,e) { |
| 602 | if (e->m_cause == CArchiveException::endOfFile) myEof = Standard_True; |
| 603 | else errorStatus = Standard_True; |
| 604 | } |
| 605 | END_CATCH |
| 606 | |
| 607 | if (errorStatus) Storage_StreamTypeMismatchError::Raise(); |
| 608 | #endif |
| 609 | return *this; |
| 610 | } |
| 611 | |
| 612 | Storage_BaseDriver& FSD_Archive::GetInteger(Standard_Integer& |
| 613 | #ifdef WNT |
| 614 | aValue |
| 615 | #endif |
| 616 | ) |
| 617 | { |
| 618 | #ifdef WNT |
| 619 | Standard_Boolean errorStatus = Standard_False; |
| 620 | TRY { |
| 621 | char ptype; |
| 622 | (*myStream) >> ptype; |
| 623 | if (ptype == FSD_INT) |
| 624 | (*myStream) >> aValue; |
| 625 | else errorStatus = Standard_True; |
| 626 | } |
| 627 | CATCH(CArchiveException,e) { |
| 628 | if (e->m_cause == CArchiveException::endOfFile) myEof = Standard_True; |
| 629 | else errorStatus = Standard_True; |
| 630 | } |
| 631 | END_CATCH |
| 632 | |
| 633 | if (errorStatus) Storage_StreamTypeMismatchError::Raise(); |
| 634 | #endif |
| 635 | return *this; |
| 636 | } |
| 637 | |
| 638 | Storage_BaseDriver& FSD_Archive::GetBoolean(Standard_Boolean& |
| 639 | #ifdef WNT |
| 640 | aValue |
| 641 | #endif |
| 642 | ) |
| 643 | { |
| 644 | #ifdef WNT |
| 645 | Standard_Boolean errorStatus = Standard_False; |
| 646 | TRY { |
| 647 | char ptype; |
| 648 | (*myStream) >> ptype; |
| 649 | if (ptype == FSD_BOO) |
| 650 | (*myStream) >> aValue; |
| 651 | else errorStatus = Standard_True; |
| 652 | } |
| 653 | CATCH(CArchiveException,e) { |
| 654 | if (e->m_cause == CArchiveException::endOfFile) myEof = Standard_True; |
| 655 | else errorStatus = Standard_True; |
| 656 | } |
| 657 | END_CATCH |
| 658 | |
| 659 | if (errorStatus) Storage_StreamTypeMismatchError::Raise(); |
| 660 | #endif |
| 661 | return *this; |
| 662 | } |
| 663 | |
| 664 | Storage_BaseDriver& FSD_Archive::GetReal(Standard_Real& |
| 665 | #ifdef WNT |
| 666 | aValue |
| 667 | #endif |
| 668 | ) |
| 669 | { |
| 670 | #ifdef WNT |
| 671 | Standard_Boolean errorStatus = Standard_False; |
| 672 | TRY { |
| 673 | char ptype; |
| 674 | (*myStream) >> ptype; |
| 675 | if (ptype == FSD_REA) |
| 676 | (*myStream) >> aValue; |
| 677 | else errorStatus = Standard_True; |
| 678 | } |
| 679 | CATCH(CArchiveException,e) { |
| 680 | if (e->m_cause == CArchiveException::endOfFile) myEof = Standard_True; |
| 681 | else errorStatus = Standard_True; |
| 682 | } |
| 683 | END_CATCH |
| 684 | |
| 685 | if (errorStatus) Storage_StreamTypeMismatchError::Raise(); |
| 686 | #endif |
| 687 | return *this; |
| 688 | } |
| 689 | |
| 690 | Storage_BaseDriver& FSD_Archive::GetShortReal(Standard_ShortReal& |
| 691 | #ifdef WNT |
| 692 | aValue |
| 693 | #endif |
| 694 | ) |
| 695 | { |
| 696 | #ifdef WNT |
| 697 | Standard_Boolean errorStatus = Standard_False; |
| 698 | TRY { |
| 699 | char ptype; |
| 700 | (*myStream) >> ptype; |
| 701 | if (ptype == FSD_SHO) |
| 702 | (*myStream) >> aValue; |
| 703 | else errorStatus = Standard_True; |
| 704 | } |
| 705 | CATCH(CArchiveException,e) { |
| 706 | if (e->m_cause == CArchiveException::endOfFile) myEof = Standard_True; |
| 707 | else errorStatus = Standard_True; |
| 708 | } |
| 709 | END_CATCH |
| 710 | |
| 711 | if (errorStatus) Storage_StreamTypeMismatchError::Raise(); |
| 712 | #endif |
| 713 | return *this; |
| 714 | } |
| 715 | |
| 716 | // -------------------------- DESTROY |
| 717 | |
| 718 | void FSD_Archive::Destroy() |
| 719 | { |
| 720 | if (OpenMode() != Storage_VSNone) { |
| 721 | Close(); |
| 722 | if (myCFile) { |
| 723 | delete ((FSD_CFile*)myCFile); |
| 724 | myCFile = NULL; |
| 725 | } |
| 726 | |
| 727 | } |
| 728 | } |
| 729 | |
| 730 | // -------------------------- INFO : WRITE |
| 731 | |
| 732 | Storage_Error FSD_Archive::BeginWriteInfoSection() |
| 733 | { |
| 734 | #ifdef WNT |
| 735 | Standard_Boolean errorStatus = Standard_False; |
| 736 | TRY { |
| 737 | //(*myStream) << FSD_Archive::MagicNumber(); |
| 738 | WriteLine(TCollection_AsciiString(FSD_Archive::MagicNumber())); |
| 739 | //(*myStream) << "BEGIN_INFO_SECTION" << '\0'; |
| 740 | WriteLine(TCollection_AsciiString("BEGIN_INFO_SECTION")); |
| 741 | } |
| 742 | CATCH(CArchiveException,e) { |
| 743 | errorStatus = Standard_True; |
| 744 | } |
| 745 | END_CATCH |
| 746 | |
| 747 | if (errorStatus) Storage_StreamWriteError::Raise(); |
| 748 | #else |
| 749 | Storage_StreamWriteError::Raise(); |
| 750 | #endif |
| 751 | return Storage_VSOk; |
| 752 | } |
| 753 | |
| 754 | void FSD_Archive::WriteInfo(const Standard_Integer |
| 755 | #ifdef WNT |
| 756 | nbObj |
| 757 | #endif |
| 758 | ,const TCollection_AsciiString& |
| 759 | #ifdef WNT |
| 760 | dbVersion |
| 761 | #endif |
| 762 | ,const TCollection_AsciiString& |
| 763 | #ifdef WNT |
| 764 | date |
| 765 | #endif |
| 766 | ,const TCollection_AsciiString& |
| 767 | #ifdef WNT |
| 768 | schemaName |
| 769 | #endif |
| 770 | ,const TCollection_AsciiString& |
| 771 | #ifdef WNT |
| 772 | schemaVersion |
| 773 | #endif |
| 774 | ,const TCollection_ExtendedString& |
| 775 | #ifdef WNT |
| 776 | appName |
| 777 | #endif |
| 778 | ,const TCollection_AsciiString& |
| 779 | #ifdef WNT |
| 780 | appVersion |
| 781 | #endif |
| 782 | ,const TCollection_ExtendedString& |
| 783 | #ifdef WNT |
| 784 | dataType |
| 785 | #endif |
| 786 | ,const TColStd_SequenceOfAsciiString& |
| 787 | #ifdef WNT |
| 788 | userInfo |
| 789 | #endif |
| 790 | ) |
| 791 | { |
| 792 | #ifdef WNT |
| 793 | Standard_Boolean errorStatus = Standard_False; |
| 794 | TRY { |
| 795 | Standard_Integer i; |
| 796 | |
| 797 | (*myStream) << nbObj; |
| 798 | //(*myStream) << dbVersion.ToCString() << '\0'; |
| 799 | WriteLine(dbVersion); |
| 800 | //(*myStream) << date.ToCString() << '\0'; |
| 801 | WriteLine(date); |
| 802 | //(*myStream) << schemaName.ToCString() << '\0'; |
| 803 | WriteLine(schemaName); |
| 804 | //(*myStream) << schemaVersion.ToCString() << '\0'; |
| 805 | WriteLine(schemaVersion); |
| 806 | WriteExtendedLine(appName); |
| 807 | //(*myStream) << appVersion.ToCString() << '\0'; |
| 808 | WriteLine(appVersion); |
| 809 | WriteExtendedLine(dataType); |
| 810 | (*myStream) << userInfo.Length(); |
| 811 | |
| 812 | for (i = 1; i <= userInfo.Length(); i++) { |
| 813 | //(*myStream) << userInfo.Value(i).ToCString() << '\0'; |
| 814 | WriteLine(userInfo.Value(i)); |
| 815 | } |
| 816 | } |
| 817 | CATCH(CArchiveException,e) { |
| 818 | errorStatus = Standard_True; |
| 819 | } |
| 820 | END_CATCH |
| 821 | |
| 822 | if (errorStatus) Storage_StreamWriteError::Raise(); |
| 823 | #else |
| 824 | Storage_StreamWriteError::Raise(); |
| 825 | #endif |
| 826 | } |
| 827 | |
| 828 | |
| 829 | Storage_Error FSD_Archive::EndWriteInfoSection() |
| 830 | { |
| 831 | #ifdef WNT |
| 832 | Standard_Boolean errorStatus = Standard_False; |
| 833 | TRY { |
| 834 | //(*myStream) << "END_INFO_SECTION" << '\0'; |
| 835 | WriteLine(TCollection_AsciiString("END_INFO_SECTION")); |
| 836 | } |
| 837 | CATCH(CArchiveException,e) { |
| 838 | errorStatus = Standard_True; |
| 839 | } |
| 840 | END_CATCH |
| 841 | |
| 842 | if (errorStatus) Storage_StreamWriteError::Raise(); |
| 843 | #else |
| 844 | Storage_StreamWriteError::Raise(); |
| 845 | #endif |
| 846 | return Storage_VSOk; |
| 847 | } |
| 848 | |
| 849 | Storage_Error FSD_Archive::BeginReadInfoSection() |
| 850 | { |
| 851 | Storage_Error s; |
| 852 | #ifdef WNT |
| 853 | TCollection_AsciiString l; |
| 854 | Standard_Integer len = strlen(FSD_Archive::MagicNumber()); |
| 855 | |
| 856 | // first character is length of the magic number |
| 857 | ReadChar(l,1); |
| 858 | |
| 859 | if(l.ToCString()[0] != (Standard_Character) len) |
| 860 | myFormat = Standard_True; |
| 861 | |
| 862 | if(myFormat) { |
| 863 | TCollection_AsciiString ll; |
| 864 | ReadLine(ll); |
| 865 | l += ll; |
| 866 | } else { |
| 867 | ReadChar(l,len); |
| 868 | } |
| 869 | if (strncmp(FSD_Archive::MagicNumber(),l.ToCString(),len) != 0) { |
| 870 | s = Storage_VSFormatError; |
| 871 | } |
| 872 | else { |
| 873 | s = FindTag("BEGIN_INFO_SECTION"); |
| 874 | } |
| 875 | #else |
| 876 | s = Storage_VSFormatError; |
| 877 | #endif |
| 878 | return s; |
| 879 | } |
| 880 | |
| 881 | // ------------------- INFO : READ |
| 882 | |
| 883 | void FSD_Archive::ReadInfo(Standard_Integer& |
| 884 | #ifdef WNT |
| 885 | nbObj |
| 886 | #endif |
| 887 | ,TCollection_AsciiString& |
| 888 | #ifdef WNT |
| 889 | dbVersion |
| 890 | #endif |
| 891 | ,TCollection_AsciiString& |
| 892 | #ifdef WNT |
| 893 | date |
| 894 | #endif |
| 895 | ,TCollection_AsciiString& |
| 896 | #ifdef WNT |
| 897 | schemaName |
| 898 | #endif |
| 899 | ,TCollection_AsciiString& |
| 900 | #ifdef WNT |
| 901 | schemaVersion |
| 902 | #endif |
| 903 | ,TCollection_ExtendedString& |
| 904 | #ifdef WNT |
| 905 | appName |
| 906 | #endif |
| 907 | ,TCollection_AsciiString& |
| 908 | #ifdef WNT |
| 909 | appVersion |
| 910 | #endif |
| 911 | ,TCollection_ExtendedString& |
| 912 | #ifdef WNT |
| 913 | dataType |
| 914 | #endif |
| 915 | ,TColStd_SequenceOfAsciiString& |
| 916 | #ifdef WNT |
| 917 | userInfo |
| 918 | #endif |
| 919 | ) |
| 920 | { |
| 921 | #ifdef WNT |
| 922 | Standard_Boolean errorStatus = Standard_False; |
| 923 | TRY { |
| 924 | (*myStream) >> nbObj; |
| 925 | |
| 926 | ReadLine(dbVersion); |
| 927 | ReadLine(date); |
| 928 | ReadLine(schemaName); |
| 929 | ReadLine(schemaVersion); |
| 930 | ReadExtendedLine(appName); |
| 931 | ReadLine(appVersion); |
| 932 | ReadExtendedLine(dataType); |
| 933 | |
| 934 | Standard_Integer i,len = 0; |
| 935 | |
| 936 | (*myStream) >> len; |
| 937 | |
| 938 | TCollection_AsciiString line; |
| 939 | |
| 940 | for (i = 1; i <= len && !IsEnd(); i++) { |
| 941 | ReadLine(line); |
| 942 | userInfo.Append(line); |
| 943 | line.Clear(); |
| 944 | } |
| 945 | } |
| 946 | CATCH(CArchiveException,e) { |
| 947 | if (e->m_cause == CArchiveException::endOfFile) myEof = Standard_True; |
| 948 | else errorStatus = Standard_True; |
| 949 | } |
| 950 | END_CATCH |
| 951 | |
| 952 | if (errorStatus) |
| 953 | #endif |
| 954 | Storage_StreamTypeMismatchError::Raise(); |
| 955 | } |
| 956 | |
| 957 | Storage_Error FSD_Archive::EndReadInfoSection() |
| 958 | { |
| 959 | return FindTag("END_INFO_SECTION"); |
| 960 | } |
| 961 | |
| 962 | // ---------------- COMMENTS : WRITE |
| 963 | |
| 964 | Storage_Error FSD_Archive::BeginWriteCommentSection() |
| 965 | { |
| 966 | #ifdef WNT |
| 967 | Standard_Boolean errorStatus = Standard_False; |
| 968 | TRY { |
| 969 | //(*myStream) << "BEGIN_COMMENT_SECTION" << '\0'; |
| 970 | WriteLine(TCollection_AsciiString("BEGIN_COMMENT_SECTION")); |
| 971 | } |
| 972 | CATCH(CArchiveException,e) { |
| 973 | errorStatus = Standard_True; |
| 974 | } |
| 975 | END_CATCH |
| 976 | |
| 977 | if (errorStatus) Storage_StreamWriteError::Raise(); |
| 978 | #else |
| 979 | Storage_StreamWriteError::Raise(); |
| 980 | #endif |
| 981 | return Storage_VSOk; |
| 982 | } |
| 983 | |
| 984 | void FSD_Archive::WriteComment(const TColStd_SequenceOfExtendedString& |
| 985 | #ifdef WNT |
| 986 | aCom |
| 987 | #endif |
| 988 | ) |
| 989 | { |
| 990 | #ifdef WNT |
| 991 | Standard_Boolean errorStatus = Standard_False; |
| 992 | TRY { |
| 993 | Standard_Integer i,aSize; |
| 994 | |
| 995 | aSize = aCom.Length(); |
| 996 | (*myStream) << aSize; |
| 997 | for (i = 1; i <= aSize; i++) { |
| 998 | WriteExtendedLine(aCom.Value(i)); |
| 999 | } |
| 1000 | } |
| 1001 | CATCH(CArchiveException,e) { |
| 1002 | errorStatus = Standard_True; |
| 1003 | } |
| 1004 | END_CATCH |
| 1005 | |
| 1006 | if (errorStatus) |
| 1007 | #endif |
| 1008 | Storage_StreamWriteError::Raise(); |
| 1009 | } |
| 1010 | |
| 1011 | Storage_Error FSD_Archive::EndWriteCommentSection() |
| 1012 | { |
| 1013 | #ifdef WNT |
| 1014 | Standard_Boolean errorStatus = Standard_False; |
| 1015 | TRY { |
| 1016 | //(*myStream) << "END_COMMENT_SECTION" << '\0'; |
| 1017 | WriteLine(TCollection_AsciiString("END_COMMENT_SECTION")); |
| 1018 | } |
| 1019 | CATCH(CArchiveException,e) { |
| 1020 | errorStatus = Standard_True; |
| 1021 | } |
| 1022 | END_CATCH |
| 1023 | |
| 1024 | if (errorStatus) Storage_StreamWriteError::Raise(); |
| 1025 | #else |
| 1026 | Storage_StreamWriteError::Raise(); |
| 1027 | #endif |
| 1028 | return Storage_VSOk; |
| 1029 | } |
| 1030 | |
| 1031 | // ---------------- COMMENTS : READ |
| 1032 | |
| 1033 | Storage_Error FSD_Archive::BeginReadCommentSection() |
| 1034 | { |
| 1035 | return FindTag("BEGIN_COMMENT_SECTION"); |
| 1036 | } |
| 1037 | |
| 1038 | void FSD_Archive::ReadComment(TColStd_SequenceOfExtendedString& |
| 1039 | #ifdef WNT |
| 1040 | aCom |
| 1041 | #endif |
| 1042 | ) |
| 1043 | { |
| 1044 | #ifdef WNT |
| 1045 | Standard_Boolean errorStatus = Standard_False; |
| 1046 | TRY { |
| 1047 | TCollection_ExtendedString line; |
| 1048 | Standard_Integer len,i; |
| 1049 | |
| 1050 | (*myStream) >> len; |
| 1051 | |
| 1052 | for (i = 1; i <= len && !IsEnd(); i++) { |
| 1053 | ReadExtendedLine(line); |
| 1054 | aCom.Append(line); |
| 1055 | line.Clear(); |
| 1056 | } |
| 1057 | } |
| 1058 | CATCH(CArchiveException,e) { |
| 1059 | if (e->m_cause == CArchiveException::endOfFile) myEof = Standard_True; |
| 1060 | else errorStatus = Standard_True; |
| 1061 | } |
| 1062 | END_CATCH |
| 1063 | |
| 1064 | if (errorStatus) |
| 1065 | #endif |
| 1066 | Storage_StreamTypeMismatchError::Raise(); |
| 1067 | } |
| 1068 | |
| 1069 | Storage_Error FSD_Archive::EndReadCommentSection() |
| 1070 | { |
| 1071 | return FindTag("END_COMMENT_SECTION"); |
| 1072 | } |
| 1073 | |
| 1074 | // --------------- TYPE : WRITE |
| 1075 | |
| 1076 | Storage_Error FSD_Archive::BeginWriteTypeSection() |
| 1077 | { |
| 1078 | #ifdef WNT |
| 1079 | Standard_Boolean errorStatus = Standard_False; |
| 1080 | TRY { |
| 1081 | //(*myStream) << "BEGIN_TYPE_SECTION" << '\0'; |
| 1082 | WriteLine(TCollection_AsciiString("BEGIN_TYPE_SECTION")); |
| 1083 | } |
| 1084 | CATCH(CArchiveException,e) { |
| 1085 | errorStatus = Standard_True; |
| 1086 | } |
| 1087 | END_CATCH |
| 1088 | |
| 1089 | if (errorStatus) Storage_StreamWriteError::Raise(); |
| 1090 | #else |
| 1091 | Storage_StreamWriteError::Raise(); |
| 1092 | #endif |
| 1093 | return Storage_VSOk; |
| 1094 | } |
| 1095 | |
| 1096 | void FSD_Archive::SetTypeSectionSize(const Standard_Integer |
| 1097 | #ifdef WNT |
| 1098 | aSize |
| 1099 | #endif |
| 1100 | ) |
| 1101 | { |
| 1102 | #ifdef WNT |
| 1103 | Standard_Boolean errorStatus = Standard_False; |
| 1104 | TRY { |
| 1105 | (*myStream) << aSize; |
| 1106 | } |
| 1107 | CATCH(CArchiveException,e) { |
| 1108 | errorStatus = Standard_True; |
| 1109 | } |
| 1110 | END_CATCH |
| 1111 | |
| 1112 | if (errorStatus) |
| 1113 | #endif |
| 1114 | Storage_StreamWriteError::Raise(); |
| 1115 | } |
| 1116 | |
| 1117 | void FSD_Archive::WriteTypeInformations(const Standard_Integer |
| 1118 | #ifdef WNT |
| 1119 | typeNum |
| 1120 | #endif |
| 1121 | ,const TCollection_AsciiString& |
| 1122 | #ifdef WNT |
| 1123 | typeName |
| 1124 | #endif |
| 1125 | ) |
| 1126 | { |
| 1127 | #ifdef WNT |
| 1128 | Standard_Boolean errorStatus = Standard_False; |
| 1129 | TRY { |
| 1130 | //(*myStream) << typeNum << typeName.ToCString() << '\0'; |
| 1131 | (*myStream) << typeNum; |
| 1132 | WriteLine(typeName); |
| 1133 | } |
| 1134 | CATCH(CArchiveException,e) { |
| 1135 | errorStatus = Standard_True; |
| 1136 | } |
| 1137 | END_CATCH |
| 1138 | |
| 1139 | if (errorStatus) |
| 1140 | #endif |
| 1141 | Storage_StreamWriteError::Raise(); |
| 1142 | } |
| 1143 | |
| 1144 | Storage_Error FSD_Archive::EndWriteTypeSection() |
| 1145 | { |
| 1146 | #ifdef WNT |
| 1147 | Standard_Boolean errorStatus = Standard_False; |
| 1148 | TRY { |
| 1149 | //(*myStream) << "END_TYPE_SECTION" << '\0'; |
| 1150 | WriteLine(TCollection_AsciiString("END_TYPE_SECTION")); |
| 1151 | } |
| 1152 | CATCH(CArchiveException,e) { |
| 1153 | errorStatus = Standard_True; |
| 1154 | } |
| 1155 | END_CATCH |
| 1156 | |
| 1157 | if (errorStatus) Storage_StreamWriteError::Raise(); |
| 1158 | #else |
| 1159 | Storage_StreamWriteError::Raise(); |
| 1160 | #endif |
| 1161 | return Storage_VSOk; |
| 1162 | } |
| 1163 | |
| 1164 | // ------------------- TYPE : READ |
| 1165 | |
| 1166 | Storage_Error FSD_Archive::BeginReadTypeSection() |
| 1167 | { |
| 1168 | return FindTag("BEGIN_TYPE_SECTION"); |
| 1169 | } |
| 1170 | |
| 1171 | Standard_Integer FSD_Archive::TypeSectionSize() |
| 1172 | { |
| 1173 | Standard_Integer i = 0; |
| 1174 | #ifdef WNT |
| 1175 | Standard_Boolean errorStatus = Standard_False; |
| 1176 | TRY { |
| 1177 | (*myStream) >> i; |
| 1178 | } |
| 1179 | CATCH(CArchiveException,e) { |
| 1180 | if (e->m_cause == CArchiveException::endOfFile) myEof = Standard_True; |
| 1181 | else errorStatus = Standard_True; |
| 1182 | } |
| 1183 | END_CATCH |
| 1184 | |
| 1185 | if (errorStatus) Storage_StreamTypeMismatchError::Raise(); |
| 1186 | #else |
| 1187 | Storage_StreamTypeMismatchError::Raise(); |
| 1188 | #endif |
| 1189 | return i; |
| 1190 | } |
| 1191 | |
| 1192 | void FSD_Archive::ReadTypeInformations(Standard_Integer& |
| 1193 | #ifdef WNT |
| 1194 | typeNum |
| 1195 | #endif |
| 1196 | ,TCollection_AsciiString& |
| 1197 | #ifdef WNT |
| 1198 | typeName |
| 1199 | #endif |
| 1200 | ) |
| 1201 | { |
| 1202 | #ifdef WNT |
| 1203 | Standard_Boolean errorStatus = Standard_False; |
| 1204 | TRY { |
| 1205 | unsigned char c; |
| 1206 | (*myStream) >> typeNum; |
| 1207 | (*myStream) >> c; |
| 1208 | if(myFormat) { |
| 1209 | TCollection_AsciiString tn; |
| 1210 | typeName = (Standard_Character) c; |
| 1211 | ReadLine(tn); |
| 1212 | typeName += tn; |
| 1213 | } else { |
| 1214 | ReadLine(typeName); |
| 1215 | } |
| 1216 | } |
| 1217 | CATCH(CArchiveException,e) { |
| 1218 | if (e->m_cause == CArchiveException::endOfFile) myEof = Standard_True; |
| 1219 | else errorStatus = Standard_True; |
| 1220 | } |
| 1221 | END_CATCH |
| 1222 | |
| 1223 | if (errorStatus) |
| 1224 | #endif |
| 1225 | Storage_StreamTypeMismatchError::Raise(); |
| 1226 | } |
| 1227 | |
| 1228 | Storage_Error FSD_Archive::EndReadTypeSection() |
| 1229 | { |
| 1230 | return FindTag("END_TYPE_SECTION"); |
| 1231 | } |
| 1232 | |
| 1233 | // -------------------- ROOT : WRITE |
| 1234 | |
| 1235 | Storage_Error FSD_Archive::BeginWriteRootSection() |
| 1236 | { |
| 1237 | #ifdef WNT |
| 1238 | Standard_Boolean errorStatus = Standard_False; |
| 1239 | TRY { |
| 1240 | //(*myStream) << "BEGIN_ROOT_SECTION" << '\0'; |
| 1241 | WriteLine(TCollection_AsciiString("BEGIN_ROOT_SECTION")); |
| 1242 | } |
| 1243 | CATCH(CArchiveException,e) { |
| 1244 | errorStatus = Standard_True; |
| 1245 | } |
| 1246 | END_CATCH |
| 1247 | |
| 1248 | if (errorStatus) Storage_StreamWriteError::Raise(); |
| 1249 | #else |
| 1250 | Storage_StreamWriteError::Raise(); |
| 1251 | #endif |
| 1252 | return Storage_VSOk; |
| 1253 | } |
| 1254 | |
| 1255 | void FSD_Archive::SetRootSectionSize(const Standard_Integer |
| 1256 | #ifdef WNT |
| 1257 | aSize |
| 1258 | #endif |
| 1259 | ) |
| 1260 | { |
| 1261 | #ifdef WNT |
| 1262 | Standard_Boolean errorStatus = Standard_False; |
| 1263 | TRY { |
| 1264 | (*myStream) << aSize; |
| 1265 | } |
| 1266 | CATCH(CArchiveException,e) { |
| 1267 | errorStatus = Standard_True; |
| 1268 | } |
| 1269 | END_CATCH |
| 1270 | |
| 1271 | if (errorStatus) |
| 1272 | #endif |
| 1273 | Storage_StreamWriteError::Raise(); |
| 1274 | } |
| 1275 | |
| 1276 | void FSD_Archive::WriteRoot(const TCollection_AsciiString& |
| 1277 | #ifdef WNT |
| 1278 | rootName |
| 1279 | #endif |
| 1280 | ,const Standard_Integer |
| 1281 | #ifdef WNT |
| 1282 | aRef |
| 1283 | #endif |
| 1284 | ,const TCollection_AsciiString& |
| 1285 | #ifdef WNT |
| 1286 | rootType |
| 1287 | #endif |
| 1288 | ) |
| 1289 | { |
| 1290 | #ifdef WNT |
| 1291 | Standard_Boolean errorStatus = Standard_False; |
| 1292 | TRY { |
| 1293 | //(*myStream) << aRef << rootName.ToCString() << '\0' << rootType.ToCString() << '\0'; |
| 1294 | (*myStream) << aRef; |
| 1295 | WriteLine(rootName); |
| 1296 | WriteLine(rootType); |
| 1297 | |
| 1298 | } |
| 1299 | CATCH(CArchiveException,e) { |
| 1300 | errorStatus = Standard_True; |
| 1301 | } |
| 1302 | END_CATCH |
| 1303 | |
| 1304 | if (errorStatus) |
| 1305 | #endif |
| 1306 | Storage_StreamWriteError::Raise(); |
| 1307 | } |
| 1308 | |
| 1309 | Storage_Error FSD_Archive::EndWriteRootSection() |
| 1310 | { |
| 1311 | #ifdef WNT |
| 1312 | Standard_Boolean errorStatus = Standard_False; |
| 1313 | TRY { |
| 1314 | //(*myStream) << "END_ROOT_SECTION" << '\0'; |
| 1315 | WriteLine(TCollection_AsciiString("END_ROOT_SECTION")); |
| 1316 | } |
| 1317 | CATCH(CArchiveException,e) { |
| 1318 | errorStatus = Standard_True; |
| 1319 | } |
| 1320 | END_CATCH |
| 1321 | |
| 1322 | if (errorStatus) Storage_StreamWriteError::Raise(); |
| 1323 | #else |
| 1324 | Storage_StreamWriteError::Raise(); |
| 1325 | #endif |
| 1326 | return Storage_VSOk; |
| 1327 | } |
| 1328 | |
| 1329 | // ----------------------- ROOT : READ |
| 1330 | |
| 1331 | Storage_Error FSD_Archive::BeginReadRootSection() |
| 1332 | { |
| 1333 | return FindTag("BEGIN_ROOT_SECTION"); |
| 1334 | } |
| 1335 | |
| 1336 | Standard_Integer FSD_Archive::RootSectionSize() |
| 1337 | { |
| 1338 | Standard_Integer i = 0; |
| 1339 | #ifdef WNT |
| 1340 | Standard_Boolean errorStatus = Standard_False; |
| 1341 | TRY { |
| 1342 | (*myStream) >> i; |
| 1343 | } |
| 1344 | CATCH(CArchiveException,e) { |
| 1345 | if (e->m_cause == CArchiveException::endOfFile) myEof = Standard_True; |
| 1346 | else errorStatus = Standard_True; |
| 1347 | } |
| 1348 | END_CATCH |
| 1349 | |
| 1350 | if (errorStatus) Storage_StreamTypeMismatchError::Raise(); |
| 1351 | #else |
| 1352 | Storage_StreamTypeMismatchError::Raise(); |
| 1353 | #endif |
| 1354 | return i; |
| 1355 | } |
| 1356 | |
| 1357 | void FSD_Archive::ReadRoot(TCollection_AsciiString& |
| 1358 | #ifdef WNT |
| 1359 | rootName |
| 1360 | #endif |
| 1361 | ,Standard_Integer& |
| 1362 | #ifdef WNT |
| 1363 | aRef |
| 1364 | #endif |
| 1365 | ,TCollection_AsciiString& |
| 1366 | #ifdef WNT |
| 1367 | rootType |
| 1368 | #endif |
| 1369 | ) |
| 1370 | { |
| 1371 | #ifdef WNT |
| 1372 | Standard_Boolean errorStatus = Standard_False; |
| 1373 | TRY { |
| 1374 | (*myStream) >> aRef; |
| 1375 | ReadLine(rootName); |
| 1376 | ReadLine(rootType); |
| 1377 | } |
| 1378 | CATCH(CArchiveException,e) { |
| 1379 | if (e->m_cause == CArchiveException::endOfFile) myEof = Standard_True; |
| 1380 | else errorStatus = Standard_True; |
| 1381 | } |
| 1382 | END_CATCH |
| 1383 | |
| 1384 | if (errorStatus) |
| 1385 | #endif |
| 1386 | Storage_StreamTypeMismatchError::Raise(); |
| 1387 | } |
| 1388 | |
| 1389 | Storage_Error FSD_Archive::EndReadRootSection() |
| 1390 | { |
| 1391 | return FindTag("END_ROOT_SECTION"); |
| 1392 | } |
| 1393 | |
| 1394 | // -------------------------- REF : WRITE |
| 1395 | |
| 1396 | Storage_Error FSD_Archive::BeginWriteRefSection() |
| 1397 | { |
| 1398 | #ifdef WNT |
| 1399 | Standard_Boolean errorStatus = Standard_False; |
| 1400 | TRY { |
| 1401 | //(*myStream) << "BEGIN_REF_SECTION" << '\0'; |
| 1402 | WriteLine(TCollection_AsciiString("BEGIN_REF_SECTION")); |
| 1403 | } |
| 1404 | CATCH(CArchiveException,e) { |
| 1405 | errorStatus = Standard_True; |
| 1406 | } |
| 1407 | END_CATCH |
| 1408 | |
| 1409 | if (errorStatus) Storage_StreamWriteError::Raise(); |
| 1410 | #else |
| 1411 | Storage_StreamWriteError::Raise(); |
| 1412 | #endif |
| 1413 | return Storage_VSOk; |
| 1414 | } |
| 1415 | |
| 1416 | void FSD_Archive::SetRefSectionSize(const Standard_Integer |
| 1417 | #ifdef WNT |
| 1418 | aSize |
| 1419 | #endif |
| 1420 | ) |
| 1421 | { |
| 1422 | #ifdef WNT |
| 1423 | Standard_Boolean errorStatus = Standard_False; |
| 1424 | TRY { |
| 1425 | (*myStream) << aSize; |
| 1426 | } |
| 1427 | CATCH(CArchiveException,e) { |
| 1428 | errorStatus = Standard_True; |
| 1429 | } |
| 1430 | END_CATCH |
| 1431 | |
| 1432 | if (errorStatus) |
| 1433 | #endif |
| 1434 | Storage_StreamWriteError::Raise(); |
| 1435 | } |
| 1436 | |
| 1437 | void FSD_Archive::WriteReferenceType(const Standard_Integer |
| 1438 | #ifdef WNT |
| 1439 | reference |
| 1440 | #endif |
| 1441 | ,const Standard_Integer |
| 1442 | #ifdef WNT |
| 1443 | typeNum |
| 1444 | #endif |
| 1445 | ) |
| 1446 | { |
| 1447 | #ifdef WNT |
| 1448 | Standard_Boolean errorStatus = Standard_False; |
| 1449 | TRY { |
| 1450 | (*myStream) << reference << typeNum; |
| 1451 | } |
| 1452 | CATCH(CArchiveException,e) { |
| 1453 | errorStatus = Standard_True; |
| 1454 | } |
| 1455 | END_CATCH |
| 1456 | |
| 1457 | if (errorStatus) |
| 1458 | #endif |
| 1459 | Storage_StreamWriteError::Raise(); |
| 1460 | } |
| 1461 | |
| 1462 | Storage_Error FSD_Archive::EndWriteRefSection() |
| 1463 | { |
| 1464 | #ifdef WNT |
| 1465 | Standard_Boolean errorStatus = Standard_False; |
| 1466 | TRY { |
| 1467 | //(*myStream) << "END_REF_SECTION" << '\0'; |
| 1468 | WriteLine(TCollection_AsciiString("END_REF_SECTION")); |
| 1469 | } |
| 1470 | CATCH(CArchiveException,e) { |
| 1471 | errorStatus = Standard_True; |
| 1472 | } |
| 1473 | END_CATCH |
| 1474 | |
| 1475 | if (errorStatus) Storage_StreamWriteError::Raise(); |
| 1476 | #else |
| 1477 | Storage_StreamWriteError::Raise(); |
| 1478 | #endif |
| 1479 | return Storage_VSOk; |
| 1480 | } |
| 1481 | |
| 1482 | // ----------------------- REF : READ |
| 1483 | |
| 1484 | Storage_Error FSD_Archive::BeginReadRefSection() |
| 1485 | { |
| 1486 | return FindTag("BEGIN_REF_SECTION"); |
| 1487 | } |
| 1488 | |
| 1489 | Standard_Integer FSD_Archive::RefSectionSize() |
| 1490 | { |
| 1491 | Standard_Integer i = 0; |
| 1492 | #ifdef WNT |
| 1493 | Standard_Boolean errorStatus = Standard_False; |
| 1494 | TRY { |
| 1495 | (*myStream) >> i; |
| 1496 | } |
| 1497 | CATCH(CArchiveException,e) { |
| 1498 | if (e->m_cause == CArchiveException::endOfFile) myEof = Standard_True; |
| 1499 | else errorStatus = Standard_True; |
| 1500 | } |
| 1501 | END_CATCH |
| 1502 | |
| 1503 | if (errorStatus) Storage_StreamTypeMismatchError::Raise(); |
| 1504 | #else |
| 1505 | Storage_StreamTypeMismatchError::Raise(); |
| 1506 | #endif |
| 1507 | return i; |
| 1508 | } |
| 1509 | |
| 1510 | void FSD_Archive::ReadReferenceType(Standard_Integer& |
| 1511 | #ifdef WNT |
| 1512 | reference |
| 1513 | #endif |
| 1514 | ,Standard_Integer& |
| 1515 | #ifdef WNT |
| 1516 | typeNum |
| 1517 | #endif |
| 1518 | ) |
| 1519 | { |
| 1520 | #ifdef WNT |
| 1521 | Standard_Boolean errorStatus = Standard_False; |
| 1522 | TRY { |
| 1523 | (*myStream) >> reference; |
| 1524 | (*myStream) >> typeNum; |
| 1525 | } |
| 1526 | CATCH(CArchiveException,e) { |
| 1527 | if (e->m_cause == CArchiveException::endOfFile) myEof = Standard_True; |
| 1528 | else errorStatus = Standard_True; |
| 1529 | } |
| 1530 | END_CATCH |
| 1531 | |
| 1532 | if (errorStatus) |
| 1533 | #endif |
| 1534 | Storage_StreamTypeMismatchError::Raise(); |
| 1535 | } |
| 1536 | |
| 1537 | Storage_Error FSD_Archive::EndReadRefSection() |
| 1538 | { |
| 1539 | return FindTag("END_REF_SECTION"); |
| 1540 | } |
| 1541 | |
| 1542 | // -------------------- DATA : WRITE |
| 1543 | |
| 1544 | Storage_Error FSD_Archive::BeginWriteDataSection() |
| 1545 | { |
| 1546 | #ifdef WNT |
| 1547 | Standard_Boolean errorStatus = Standard_False; |
| 1548 | TRY { |
| 1549 | //(*myStream) << "BEGIN_DATA_SECTION" << '\0'; |
| 1550 | WriteLine(TCollection_AsciiString("BEGIN_DATA_SECTION")); |
| 1551 | } |
| 1552 | CATCH(CArchiveException,e) { |
| 1553 | errorStatus = Standard_True; |
| 1554 | } |
| 1555 | END_CATCH |
| 1556 | |
| 1557 | if (errorStatus) Storage_StreamWriteError::Raise(); |
| 1558 | #else |
| 1559 | Storage_StreamWriteError::Raise(); |
| 1560 | #endif |
| 1561 | return Storage_VSOk; |
| 1562 | } |
| 1563 | |
| 1564 | void FSD_Archive::WritePersistentObjectHeader(const Standard_Integer |
| 1565 | #ifdef WNT |
| 1566 | aRef |
| 1567 | #endif |
| 1568 | ,const Standard_Integer |
| 1569 | #ifdef WNT |
| 1570 | aType |
| 1571 | #endif |
| 1572 | ) |
| 1573 | { |
| 1574 | #ifdef WNT |
| 1575 | Standard_Boolean errorStatus = Standard_False; |
| 1576 | TRY { |
| 1577 | (*myStream) << aRef << aType; |
| 1578 | } |
| 1579 | CATCH(CArchiveException,e) { |
| 1580 | errorStatus = Standard_True; |
| 1581 | } |
| 1582 | END_CATCH |
| 1583 | |
| 1584 | if (errorStatus) |
| 1585 | #endif |
| 1586 | Storage_StreamWriteError::Raise(); |
| 1587 | } |
| 1588 | |
| 1589 | void FSD_Archive::BeginWritePersistentObjectData() |
| 1590 | { |
| 1591 | } |
| 1592 | |
| 1593 | void FSD_Archive::BeginWriteObjectData() |
| 1594 | { |
| 1595 | } |
| 1596 | |
| 1597 | void FSD_Archive::EndWriteObjectData() |
| 1598 | { |
| 1599 | } |
| 1600 | |
| 1601 | void FSD_Archive::EndWritePersistentObjectData() |
| 1602 | { |
| 1603 | #ifdef WNT |
| 1604 | (*myStream) << 'E'; |
| 1605 | #endif |
| 1606 | } |
| 1607 | |
| 1608 | Storage_Error FSD_Archive::EndWriteDataSection() |
| 1609 | { |
| 1610 | #ifdef WNT |
| 1611 | Standard_Boolean errorStatus = Standard_False; |
| 1612 | TRY { |
| 1613 | //(*myStream) << "END_DATA_SECTION" << '\0'; |
| 1614 | WriteLine(TCollection_AsciiString("END_DATA_SECTION")); |
| 1615 | } |
| 1616 | CATCH(CArchiveException,e) { |
| 1617 | errorStatus = Standard_True; |
| 1618 | } |
| 1619 | END_CATCH |
| 1620 | |
| 1621 | if (errorStatus) Storage_StreamWriteError::Raise(); |
| 1622 | #else |
| 1623 | Storage_StreamWriteError::Raise(); |
| 1624 | #endif |
| 1625 | return Storage_VSOk; |
| 1626 | } |
| 1627 | |
| 1628 | // ---------------------- DATA : READ |
| 1629 | |
| 1630 | Storage_Error FSD_Archive::BeginReadDataSection() |
| 1631 | { |
| 1632 | return FindTag("BEGIN_DATA_SECTION"); |
| 1633 | } |
| 1634 | |
| 1635 | void FSD_Archive::ReadPersistentObjectHeader(Standard_Integer& |
| 1636 | #ifdef WNT |
| 1637 | aRef |
| 1638 | #endif |
| 1639 | ,Standard_Integer& |
| 1640 | #ifdef WNT |
| 1641 | aType |
| 1642 | #endif |
| 1643 | ) |
| 1644 | { |
| 1645 | #ifdef WNT |
| 1646 | Standard_Boolean errorStatus = Standard_False; |
| 1647 | TRY { |
| 1648 | (*myStream) >> aRef; |
| 1649 | (*myStream) >> aType; |
| 1650 | } |
| 1651 | CATCH(CArchiveException,e) { |
| 1652 | if (e->m_cause == CArchiveException::endOfFile) myEof = Standard_True; |
| 1653 | else errorStatus = Standard_True; |
| 1654 | } |
| 1655 | END_CATCH |
| 1656 | |
| 1657 | if (errorStatus) |
| 1658 | #endif |
| 1659 | Storage_StreamTypeMismatchError::Raise(); |
| 1660 | } |
| 1661 | |
| 1662 | void FSD_Archive::BeginReadPersistentObjectData() |
| 1663 | { |
| 1664 | } |
| 1665 | |
| 1666 | void FSD_Archive::BeginReadObjectData() |
| 1667 | { |
| 1668 | } |
| 1669 | |
| 1670 | void FSD_Archive::EndReadObjectData() |
| 1671 | { |
| 1672 | } |
| 1673 | |
| 1674 | void FSD_Archive::EndReadPersistentObjectData() |
| 1675 | { |
| 1676 | #ifdef WNT |
| 1677 | char theEnd; |
| 1678 | |
| 1679 | (*myStream) >> theEnd; |
| 1680 | |
| 1681 | if (theEnd != 'E') { |
| 1682 | Storage_StreamFormatError::Raise(); |
| 1683 | } |
| 1684 | #endif |
| 1685 | } |
| 1686 | |
| 1687 | Storage_Error FSD_Archive::EndReadDataSection() |
| 1688 | { |
| 1689 | return FindTag("END_DATA_SECTION"); |
| 1690 | } |
| 1691 | |
| 1692 | Storage_Position FSD_Archive::Tell() |
| 1693 | { |
| 1694 | return 0; //just a stub |
| 1695 | } |