Stream wrapper for input of binary data that converts from either little-endian or big-endian to host ordering, depending on object settings. */
| 598 | settings. |
| 599 | */ |
| 600 | class ISwitchableStream : public IStream |
| 601 | { |
| 602 | public: |
| 603 | static const bool DefaultIsLittleEndian = true; |
| 604 | |
| 605 | PDAL_EXPORT ISwitchableStream() : m_isLittleEndian(DefaultIsLittleEndian) |
| 606 | {} |
| 607 | |
| 608 | PDAL_EXPORT ISwitchableStream(const std::string& filename) |
| 609 | : IStream(filename) |
| 610 | , m_isLittleEndian(DefaultIsLittleEndian) |
| 611 | {} |
| 612 | |
| 613 | PDAL_EXPORT ISwitchableStream(std::istream* stream) |
| 614 | : IStream(stream) |
| 615 | , m_isLittleEndian(DefaultIsLittleEndian) |
| 616 | {} |
| 617 | |
| 618 | PDAL_EXPORT bool isLittleEndian() const |
| 619 | { return m_isLittleEndian; } |
| 620 | PDAL_EXPORT void switchToLittleEndian() |
| 621 | { m_isLittleEndian = true; } |
| 622 | PDAL_EXPORT void switchToBigEndian() |
| 623 | { m_isLittleEndian = false; } |
| 624 | |
| 625 | PDAL_EXPORT ISwitchableStream& operator>>(uint8_t& v) |
| 626 | { |
| 627 | v = (uint8_t)m_stream->get(); |
| 628 | return *this; |
| 629 | } |
| 630 | |
| 631 | PDAL_EXPORT ISwitchableStream& operator>>(int8_t& v) |
| 632 | { |
| 633 | v = (int8_t)m_stream->get(); |
| 634 | return *this; |
| 635 | } |
| 636 | |
| 637 | PDAL_EXPORT ISwitchableStream& operator>>(uint16_t& v) |
| 638 | { |
| 639 | m_stream->read((char*)&v, sizeof(v)); |
| 640 | v = isLittleEndian() ? le16toh(v) : be16toh(v); |
| 641 | return *this; |
| 642 | } |
| 643 | |
| 644 | PDAL_EXPORT ISwitchableStream& operator>>(int16_t& v) |
| 645 | { |
| 646 | m_stream->read((char*)&v, sizeof(v)); |
| 647 | v = isLittleEndian() ? (int16_t)le16toh((uint16_t)v) |
| 648 | : (int16_t)be16toh((uint16_t)v); |
| 649 | return *this; |
| 650 | } |
| 651 | |
| 652 | PDAL_EXPORT ISwitchableStream& operator>>(uint32_t& v) |
| 653 | { |
| 654 | m_stream->read((char*)&v, sizeof(v)); |
| 655 | v = isLittleEndian() ? le32toh(v) : be32toh(v); |
| 656 | return *this; |
| 657 | } |
nothing calls this directly
no test coverage detected