Allow inlining more BinaryReader/BinaryWriter functions

This commit is contained in:
Martchus 2019-06-04 19:27:49 +02:00
parent d8a70bb795
commit 0f2f98393f
4 changed files with 66 additions and 64 deletions

View File

@ -22,36 +22,6 @@ using namespace ConversionUtilities;
* \sa For automatic serialization of structs, see https://github.com/Martchus/reflective-rapidjson.
*/
/*!
* \brief Constructs a new BinaryReader.
* \param stream Specifies the stream to read from.
*/
BinaryReader::BinaryReader(istream *stream)
: m_stream(stream)
, m_ownership(false)
{
}
/*!
* \brief Copies the specified BinaryReader.
* \remarks The copy will not take ownership over the stream.
*/
BinaryReader::BinaryReader(const BinaryReader &other)
: m_stream(other.m_stream)
, m_ownership(false)
{
}
/*!
* \brief Destroys the BinaryReader.
*/
BinaryReader::~BinaryReader()
{
if (m_ownership) {
delete m_stream;
}
}
/*!
* \brief Assigns the stream the reader will read from when calling one of the read-methods.
*
@ -59,7 +29,7 @@ BinaryReader::~BinaryReader()
* until a stream is assigned.
*
* \param stream Specifies the stream to be assigned.
* \param giveOwnership Indicated whether the reader should take ownership (default is false).
* \param giveOwnership Specifies whether the reader should take ownership.
*
* \sa setStream()
*/

View File

@ -11,7 +11,7 @@ namespace IoUtilities {
class CPP_UTILITIES_EXPORT BinaryReader {
public:
BinaryReader(std::istream *stream);
BinaryReader(std::istream *stream, bool giveOwnership = false);
BinaryReader(const BinaryReader &other);
BinaryReader &operator=(const BinaryReader &rhs) = delete;
~BinaryReader();
@ -98,6 +98,37 @@ private:
char m_buffer[8];
};
/*!
* \brief Constructs a new BinaryReader.
* \param stream Specifies the stream to read from.
* \param giveOwnership Specifies whether the reader should take ownership.
*/
inline BinaryReader::BinaryReader(std::istream *stream, bool giveOwnership)
: m_stream(stream)
, m_ownership(giveOwnership)
{
}
/*!
* \brief Copies the specified BinaryReader.
* \remarks The copy will not take ownership over the stream.
*/
inline BinaryReader::BinaryReader(const BinaryReader &other)
: m_stream(other.m_stream)
, m_ownership(false)
{
}
/*!
* \brief Destroys the BinaryReader.
*/
inline BinaryReader::~BinaryReader()
{
if (m_ownership) {
delete m_stream;
}
}
/*!
* \brief Returns a pointer to the stream the reader will read from when calling one of the read-methods.
*

View File

@ -16,36 +16,6 @@ using namespace ConversionUtilities;
* \sa For automatic deserialization of structs, see https://github.com/Martchus/reflective-rapidjson.
*/
/*!
* \brief Constructs a new BinaryWriter.
* \param stream Specifies the stream to write to.
*/
BinaryWriter::BinaryWriter(ostream *stream)
: m_stream(stream)
, m_ownership(false)
{
}
/*!
* \brief Copies the specified BinaryWriter.
* \remarks The copy will not take ownership over the stream.
*/
BinaryWriter::BinaryWriter(const BinaryWriter &other)
: m_stream(other.m_stream)
, m_ownership(false)
{
}
/*!
* \brief Destroys the BinaryWriter.
*/
BinaryWriter::~BinaryWriter()
{
if (m_ownership) {
delete m_stream;
}
}
/*!
* \brief Assigns the stream the writer will write to when calling one of the write-methods.
*
@ -53,7 +23,7 @@ BinaryWriter::~BinaryWriter()
* until a stream is assigned.
*
* \param stream Specifies the stream to be assigned.
* \param giveOwnership Indicated whether the reader should take ownership (default is false).
* \param giveOwnership Specifies whether the writer should take ownership.
*
* \sa setStream()
*/

View File

@ -13,7 +13,7 @@ namespace IoUtilities {
class CPP_UTILITIES_EXPORT BinaryWriter {
public:
BinaryWriter(std::ostream *stream);
BinaryWriter(std::ostream *stream, bool giveOwnership = false);
BinaryWriter(const BinaryWriter &other);
BinaryWriter &operator=(const BinaryWriter &rhs) = delete;
~BinaryWriter();
@ -95,6 +95,37 @@ private:
char m_buffer[8];
};
/*!
* \brief Constructs a new BinaryWriter.
* \param stream Specifies the stream to write to.
* \param giveOwnership Specifies whether the writer should take ownership.
*/
inline BinaryWriter::BinaryWriter(std::ostream *stream, bool giveOwnership)
: m_stream(stream)
, m_ownership(giveOwnership)
{
}
/*!
* \brief Copies the specified BinaryWriter.
* \remarks The copy will not take ownership over the stream.
*/
inline BinaryWriter::BinaryWriter(const BinaryWriter &other)
: m_stream(other.m_stream)
, m_ownership(false)
{
}
/*!
* \brief Destroys the BinaryWriter.
*/
inline BinaryWriter::~BinaryWriter()
{
if (m_ownership) {
delete m_stream;
}
}
/*!
* \brief Returns a pointer to the stream the writer will write to when calling one of the write-methods.
*