class Core::IO::BinaryAccessor

Overview

Base class for accessing typed binary data. More…

#include <corestreamaccessor.h>

class BinaryAccessor
{
public:
    // fields

    static const uint16 kByteOrderMark = 0xFEFF;

    // construction

    BinaryAccessor(int byteOrder = CORE_NATIVE_BYTEORDER);

    // methods

    bool isByteSwap() const;
    int getByteOrder() const;
    void setByteOrder(int byteOrder);
    bool writeByteOrder();
    bool readByteOrder();
    virtual int read(void* buffer, int size) = 0;
    virtual int write(const void* buffer, int size) = 0;

    template <typename T>
    int readElements(T buffer[], int count);

    template <typename T>
    int writeElements(const T buffer[], int count);

    bool write(int8 c);
    bool read(int8& c);
    bool write(uint8 uc);
    bool read(uint8& uc);
    bool write(int16 s);
    bool read(int16& s);
    bool write(uint16 us);
    bool read(uint16& us);
    bool write(int32 l);
    bool read(int32& l);
    bool write(uint32 ul);
    bool read(uint32& ul);
    bool write(int64 ll);
    bool read(int64& ll);
    bool write(uint64 ull);
    bool read(uint64& ull);
    bool writeVarLen(uint32 value);
    bool readVarLen(uint32& value);
    bool write(float f);
    bool read(float& f);
    bool write(double f);
    bool read(double& f);
    bool write(char c);
    bool read(char& c);
    bool writeCString(CStringPtr string, bool terminate = true);
    bool readCStringBuffer(char* charBuffer, int bufferSize);
    bool writeFCC(int32 fcc);
    bool readFCC(int32& fcc);
};

// direct descendants

class BinaryStreamAccessor;

Detailed Documentation

Base class for accessing typed binary data.

Fields

static const uint16 kByteOrderMark = 0xFEFF

Byte order marker.

Construction

BinaryAccessor(int byteOrder = CORE_NATIVE_BYTEORDER)

Construct accessor with given byte order.

Methods

bool isByteSwap() const

Check if bytes need to be swapped.

int getByteOrder() const

Get configured byte order.

void setByteOrder(int byteOrder)

Configure byte order.

bool writeByteOrder()

Write byte order marker.

bool readByteOrder()

Read byte order marker.

virtual int read(void* buffer, int size) = 0

Read data from underlying storage, to be implemented by derived class.

virtual int write(const void* buffer, int size) = 0

Write data to underlying storage, to be implemented by derived class.

template <typename T>
int readElements(T buffer[], int count)

Read array of typed elements into buffer.

template <typename T>
int writeElements(const T buffer[], int count)

Write array of typed elements from buffer.

bool writeVarLen(uint32 value)

Write variable-length integer.

bool readVarLen(uint32& value)

Read variable-length integer.

bool writeCString(CStringPtr string, bool terminate = true)

Write C-String with optional null-termination.

bool readCStringBuffer(char* charBuffer, int bufferSize)

Read null-terminated C-String into buffer.

bool writeFCC(int32 fcc)

Write four-character code.

bool readFCC(int32& fcc)

Read four-character code.