Core: Add EmptyStream class
This commit is contained in:
parent
ea8b71407e
commit
35cf05e3bc
|
|
@ -212,6 +212,7 @@ Nazara Engine:
|
|||
- Added ENetPeer::GetTotalByte[Received|Sent]
|
||||
- Added ENetPeer::GetTotalPacketSent
|
||||
- ⚠ ENetHost::GetTotalReceivedPackets now returns the number of commands received (instead of the number of UDP packets received)
|
||||
- Added EmptyStream class, useful to measure how many bytes some writing operations will take
|
||||
|
||||
Nazara Development Kit:
|
||||
- Added ImageWidget (#139)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,46 @@
|
|||
// Copyright (C) 2019 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_EMPTYSTREAM_HPP
|
||||
#define NAZARA_EMPTYSTREAM_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Stream.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_CORE_API EmptyStream : public Stream
|
||||
{
|
||||
public:
|
||||
inline EmptyStream();
|
||||
EmptyStream(const EmptyStream&) = default;
|
||||
EmptyStream(EmptyStream&&) noexcept = default;
|
||||
~EmptyStream() = default;
|
||||
|
||||
void Clear();
|
||||
|
||||
bool EndOfStream() const override;
|
||||
|
||||
UInt64 GetCursorPos() const override;
|
||||
UInt64 GetSize() const override;
|
||||
|
||||
bool SetCursorPos(UInt64 offset) override;
|
||||
|
||||
EmptyStream& operator=(const EmptyStream&) = default;
|
||||
EmptyStream& operator=(EmptyStream&&) noexcept = default;
|
||||
|
||||
private:
|
||||
void FlushStream() override;
|
||||
std::size_t ReadBlock(void* buffer, std::size_t size) override;
|
||||
std::size_t WriteBlock(const void* buffer, std::size_t size) override;
|
||||
|
||||
UInt64 m_size;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/EmptyStream.inl>
|
||||
|
||||
#endif // NAZARA_EMPTYSTREAM_HPP
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
// Copyright (C) 2019 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/EmptyStream.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \ingroup core
|
||||
* \class Nz::EmptyStream
|
||||
* \brief Constructs an EmptyStream object by default
|
||||
*/
|
||||
inline EmptyStream::EmptyStream() :
|
||||
m_size(0)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,99 @@
|
|||
// Copyright (C) 2019 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/EmptyStream.hpp>
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \ingroup core
|
||||
* \class Nz::EmptyStream
|
||||
* \brief Core class that simulate an empty buffer (discarding all content) which can be used to measure size
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \brief Resets the stream size to zero
|
||||
*/
|
||||
void EmptyStream::Clear()
|
||||
{
|
||||
m_size = 0;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether the stream reached the end of the stream
|
||||
* \return Always false
|
||||
*/
|
||||
bool EmptyStream::EndOfStream() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the position of the cursor (which is always zero)
|
||||
* \return Always zero
|
||||
*/
|
||||
UInt64 EmptyStream::GetCursorPos() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the size of the raw memory (how many bytes would have been written on a regular stream)
|
||||
* \return Size occupied until now
|
||||
*/
|
||||
UInt64 EmptyStream::GetSize() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Does nothing
|
||||
* \return true
|
||||
*
|
||||
* \param offset Offset according to the beginning of the stream
|
||||
*/
|
||||
bool EmptyStream::SetCursorPos(UInt64 offset)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Flushes the stream (does nothing)
|
||||
*/
|
||||
void EmptyStream::FlushStream()
|
||||
{
|
||||
// Nothing to flush
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Reads data
|
||||
* \return Number of byte read (always zero)
|
||||
*
|
||||
* Reading from an empty stream does nothing and will always returns zero
|
||||
*
|
||||
* \param buffer Preallocated buffer to contain information read
|
||||
* \param size Size of the read and thus of the buffer
|
||||
*/
|
||||
std::size_t EmptyStream::ReadBlock(void* buffer, std::size_t size)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Writes data
|
||||
* \return size
|
||||
*
|
||||
* \param buffer Dummy parameter
|
||||
* \param size How many bytes will be "written"
|
||||
*/
|
||||
std::size_t EmptyStream::WriteBlock(const void* /*buffer*/, std::size_t size)
|
||||
{
|
||||
m_size += size;
|
||||
|
||||
return size;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue