Move Endian to IStream

This commit is contained in:
Phillip Stephens 2016-09-17 12:44:32 -07:00
parent 161206fdd9
commit 1ae4af3fb1
4 changed files with 16 additions and 74 deletions

View File

@ -12,21 +12,26 @@ std::ostream& operator<<(std::ostream& os, Endian& endian);
class IStream class IStream
{ {
public: public:
IStream() : m_hasError(false) {} IStream() {}
virtual ~IStream() {} virtual ~IStream() {}
virtual void setEndian(Endian) = 0; inline void setEndian(Endian endian) { m_endian = endian; }
virtual Endian endian() const = 0; inline Endian endian() const { return m_endian; }
virtual bool isBigEndian() const = 0; inline bool isBigEndian() const { return (m_endian == Endian::BigEndian); }
virtual bool isLittleEndian()const = 0; inline bool isLittleEndian() const { return (m_endian == Endian::LittleEndian); }
virtual void seek(atInt64, SeekOrigin) = 0; virtual void seek(atInt64, SeekOrigin) = 0;
virtual bool atEnd() const = 0; virtual bool atEnd() const = 0;
virtual atUint64 position() const = 0; virtual atUint64 position() const = 0;
virtual atUint64 length() const = 0; virtual atUint64 length() const = 0;
bool hasError() const { return m_hasError; } bool hasError() const { return m_hasError; }
protected: protected:
void setError() { m_hasError = true; } void setError() { m_hasError = true; }
bool m_hasError; bool m_hasError = false;
#if __BYTE_ORDER == __BIG_ENDIAN
Endian m_endian = BigEndian;
#else
Endian m_endian = LittleEndian;
#endif
}; };
} }
} }

View File

@ -20,35 +20,6 @@ class IStreamReader : public IStream
public: public:
virtual ~IStreamReader() {} virtual ~IStreamReader() {}
/** @brief Sets the Endianness of the stream
*
* @param endian The Endianness to set
*/
inline void setEndian(Endian endian)
{m_endian = endian;}
/** @brief Returns the current Endianness of the stream
*
* @return The current Stream Endianness
*/
inline Endian endian() const
{return m_endian;}
/** @brief Returns whether the stream is BigEndian
*
* @return bool True for BigEndian; False for LittleEndian
*/
inline bool isBigEndian() const
{return (m_endian == Endian::BigEndian);}
/** @brief Returns whether the stream is LittleEndian
*
* @return True for LittleEndian; False for BigEndian
*/
inline bool isLittleEndian()const
{return (m_endian == Endian::LittleEndian);}
/** @brief Sets the buffers position relative to the specified position.<br /> /** @brief Sets the buffers position relative to the specified position.<br />
* It seeks relative to the current position by default. * It seeks relative to the current position by default.
* @param position where in the buffer to seek * @param position where in the buffer to seek
@ -1255,9 +1226,6 @@ public:
readf(*this, vector.back()); readf(*this, vector.back());
} }
} }
protected:
Endian m_endian;
}; };
template <typename T> template <typename T>
IStreamReader& operator>>(IStreamReader& lhs, T& rhs) IStreamReader& operator>>(IStreamReader& lhs, T& rhs)

View File

@ -13,34 +13,6 @@ class IStreamWriter : public IStream
{ {
public: public:
virtual ~IStreamWriter() {} virtual ~IStreamWriter() {}
/** @brief Sets the Endianness of the stream
*
* @param endian The Endianness to set
*/
inline void setEndian(Endian endian)
{m_endian = endian;}
/** @brief Returns the current Endianness of the stream
*
* @return The current Stream Endianness
*/
inline Endian endian() const
{return m_endian;}
/** @brief Returns whether the stream is BigEndian
*
* @return True for BigEndian; False for LittleEndian
*/
inline bool isBigEndian() const
{return (m_endian == Endian::BigEndian);}
/** @brief Returns whether the stream is LittleEndian
*
* @return True for LittleEndian; False for BigEndian
*/
inline bool isLittleEndian() const
{return (m_endian == Endian::LittleEndian);}
/** @brief Sets the buffers position relative to the specified position.<br /> /** @brief Sets the buffers position relative to the specified position.<br />
* It seeks relative to the current position by default. * It seeks relative to the current position by default.
* @param position where in the buffer to seek * @param position where in the buffer to seek
@ -1106,9 +1078,6 @@ public:
for (const T& item : vector) for (const T& item : vector)
item.write(*this); item.write(*this);
} }
protected:
Endian m_endian;
}; };
template <typename T> template <typename T>

View File

@ -47,9 +47,9 @@ public:
inline atUint64 position() const inline atUint64 position() const
{return m_position;} {return m_position;}
/*! @brief Returns whether or not the stream is at the end. /*! @brief Returns the length of the stream.
* *
* @return bool True if at end; False otherwise. * @return Int64 The length of the stream.
*/ */
inline atUint64 length() const inline atUint64 length() const
{return m_length;} {return m_length;}