| 365 m_val.sprintf ("%p", v); |
365 m_val.sprintf ("%p", v); |
| 366 } |
366 } |
| 367 |
367 |
| 368 // ============================================================================= |
368 // ============================================================================= |
| 369 // ----------------------------------------------------------------------------- |
369 // ----------------------------------------------------------------------------- |
| 370 File::File() |
|
| 371 { |
|
| 372 // Make a null file |
|
| 373 m_file = null; |
|
| 374 m_textstream = null; |
|
| 375 } |
|
| 376 |
|
| 377 File::File (QString path, OpenType rtype) |
|
| 378 { |
|
| 379 m_file = null; |
|
| 380 m_path = path; |
|
| 381 open (path, rtype); |
|
| 382 } |
|
| 383 |
|
| 384 File::File (FILE* fp, OpenType rtype) |
|
| 385 { |
|
| 386 m_file = null; |
|
| 387 open (fp, rtype); |
|
| 388 } |
|
| 389 |
|
| 390 // ============================================================================= |
|
| 391 // ----------------------------------------------------------------------------- |
|
| 392 File::~File() |
|
| 393 { |
|
| 394 if (m_file) |
|
| 395 { |
|
| 396 m_file->close(); |
|
| 397 delete m_file; |
|
| 398 |
|
| 399 if (m_textstream) |
|
| 400 delete m_textstream; |
|
| 401 } |
|
| 402 } |
|
| 403 |
|
| 404 // ============================================================================= |
|
| 405 // ----------------------------------------------------------------------------- |
|
| 406 bool File::open (FILE* fp, OpenType rtype) |
|
| 407 { |
|
| 408 return open ("", rtype, fp); |
|
| 409 } |
|
| 410 |
|
| 411 bool File::open (QString path, OpenType rtype, FILE* fp) |
|
| 412 { |
|
| 413 close(); |
|
| 414 |
|
| 415 if (!m_file) |
|
| 416 m_file = new QFile; |
|
| 417 |
|
| 418 m_file->setFileName (path); |
|
| 419 |
|
| 420 bool result; |
|
| 421 |
|
| 422 QIODevice::OpenMode mode = |
|
| 423 (rtype == Read) ? QIODevice::ReadOnly : |
|
| 424 (rtype == Write) ? QIODevice::WriteOnly : QIODevice::Append; |
|
| 425 |
|
| 426 if (fp) |
|
| 427 result = m_file->open (fp, mode); |
|
| 428 else |
|
| 429 result = m_file->open (mode); |
|
| 430 |
|
| 431 if (result) |
|
| 432 { |
|
| 433 m_textstream = new QTextStream (m_file); |
|
| 434 m_path = path; |
|
| 435 return true; |
|
| 436 } |
|
| 437 |
|
| 438 delete m_file; |
|
| 439 m_file = null; |
|
| 440 return false; |
|
| 441 } |
|
| 442 |
|
| 443 // ============================================================================= |
|
| 444 // ----------------------------------------------------------------------------- |
|
| 445 File::iterator File::begin() |
|
| 446 { |
|
| 447 return iterator (this); |
|
| 448 } |
|
| 449 |
|
| 450 File::iterator& File::end() |
|
| 451 { |
|
| 452 return m_endIterator; |
|
| 453 } |
|
| 454 |
|
| 455 // ============================================================================= |
|
| 456 // ----------------------------------------------------------------------------- |
|
| 457 void File::write (QString msg) |
|
| 458 { |
|
| 459 m_file->write (msg.toUtf8(), msg.length()); |
|
| 460 } |
|
| 461 |
|
| 462 // ============================================================================= |
|
| 463 // ----------------------------------------------------------------------------- |
|
| 464 bool File::readLine (QString& line) |
|
| 465 { |
|
| 466 if (!m_textstream || m_textstream->atEnd()) |
|
| 467 return false; |
|
| 468 |
|
| 469 line = m_textstream->readLine(); |
|
| 470 return true; |
|
| 471 } |
|
| 472 |
|
| 473 // ============================================================================= |
|
| 474 // ----------------------------------------------------------------------------- |
|
| 475 bool File::atEnd() const |
|
| 476 { |
|
| 477 assert (m_textstream != null); |
|
| 478 return m_textstream->atEnd(); |
|
| 479 } |
|
| 480 |
|
| 481 // ============================================================================= |
|
| 482 // ----------------------------------------------------------------------------- |
|
| 483 bool File::isNull() const |
|
| 484 { |
|
| 485 return m_file == null; |
|
| 486 } |
|
| 487 |
|
| 488 bool File::operator!() const |
|
| 489 { |
|
| 490 return isNull(); |
|
| 491 } |
|
| 492 |
|
| 493 // ============================================================================= |
|
| 494 // ----------------------------------------------------------------------------- |
|
| 495 void File::close() |
|
| 496 { |
|
| 497 if (!m_file) |
|
| 498 return; |
|
| 499 |
|
| 500 delete m_file; |
|
| 501 m_file = null; |
|
| 502 |
|
| 503 if (m_textstream) |
|
| 504 { |
|
| 505 delete m_textstream; |
|
| 506 m_textstream = null; |
|
| 507 } |
|
| 508 } |
|
| 509 |
|
| 510 // ============================================================================= |
|
| 511 // ----------------------------------------------------------------------------- |
|
| 512 bool File::flush() |
|
| 513 { |
|
| 514 return m_file->flush(); |
|
| 515 } |
|
| 516 |
|
| 517 // ============================================================================= |
|
| 518 // ----------------------------------------------------------------------------- |
|
| 519 File::operator bool() const |
|
| 520 { |
|
| 521 return !isNull(); |
|
| 522 } |
|
| 523 |
|
| 524 // ============================================================================= |
|
| 525 // ----------------------------------------------------------------------------- |
|
| 526 void File::rewind() |
|
| 527 { |
|
| 528 m_file->seek (0); |
|
| 529 } |
|
| 530 |
|
| 531 // ============================================================================= |
|
| 532 // ----------------------------------------------------------------------------- |
|
| 533 File::iterator::iterator (File* f) : m_file (f) |
|
| 534 { |
|
| 535 operator++(); |
|
| 536 } |
|
| 537 |
|
| 538 // ============================================================================= |
|
| 539 // ----------------------------------------------------------------------------- |
|
| 540 void File::iterator::operator++() |
|
| 541 { |
|
| 542 m_gotdata = m_file->readLine (m_text); |
|
| 543 } |
|
| 544 |
|
| 545 // ============================================================================= |
|
| 546 // ----------------------------------------------------------------------------- |
|
| 547 QString File::iterator::operator*() |
|
| 548 { |
|
| 549 return m_text; |
|
| 550 } |
|
| 551 |
|
| 552 // ============================================================================= |
|
| 553 // The prime contestant for the weirdest operator== 2013 award? |
|
| 554 // ----------------------------------------------------------------------------- |
|
| 555 bool File::iterator::operator== (File::iterator& other) |
|
| 556 { |
|
| 557 return (other.m_file == null && !m_gotdata); |
|
| 558 } |
|
| 559 |
|
| 560 // ============================================================================= |
|
| 561 // ----------------------------------------------------------------------------- |
|
| 562 bool File::iterator::operator!= (File::iterator& other) |
|
| 563 { |
|
| 564 return !operator== (other); |
|
| 565 } |
|
| 566 |
|
| 567 // ============================================================================= |
|
| 568 // ----------------------------------------------------------------------------- |
|
| 569 LDBoundingBox::LDBoundingBox() |
370 LDBoundingBox::LDBoundingBox() |
| 570 { |
371 { |
| 571 reset(); |
372 reset(); |
| 572 } |
373 } |
| 573 |
374 |