From dfb0ce0b4faa2cb8f6dd3105fdfefa28d3fbda1a Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Thu, 15 May 2014 00:41:54 -0700 Subject: [PATCH] * Add fill to Stream --- include/Athena/BinaryWriter.hpp | 3 +++ include/Athena/Global.hpp | 2 +- include/Athena/Stream.hpp | 2 ++ src/Athena/BinaryWriter.cpp | 11 +++++++++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/include/Athena/BinaryWriter.hpp b/include/Athena/BinaryWriter.hpp index 8f52e18..8b6e97e 100644 --- a/include/Athena/BinaryWriter.hpp +++ b/include/Athena/BinaryWriter.hpp @@ -272,6 +272,9 @@ public: */ void writeString(const std::string& str); + void fill(Uint8 val, Uint64 length); + void fill(Int8 val, Uint64 length); + void setProgressCallback(std::function cb); protected: void loadData(); diff --git a/include/Athena/Global.hpp b/include/Athena/Global.hpp index 5b26583..ba19e5b 100644 --- a/include/Athena/Global.hpp +++ b/include/Athena/Global.hpp @@ -63,7 +63,7 @@ namespace Sakura template class Vector2D -{ifndef +{ public: T x; T y; diff --git a/include/Athena/Stream.hpp b/include/Athena/Stream.hpp index bcbadd9..aab052e 100644 --- a/include/Athena/Stream.hpp +++ b/include/Athena/Stream.hpp @@ -74,6 +74,8 @@ protected: virtual void writeBool (bool){THROW_NOT_IMPLEMENTED_EXCEPTION();} virtual void writeString(const std::string&){THROW_NOT_IMPLEMENTED_EXCEPTION();} virtual void writeUnicode(const std::string&){THROW_NOT_IMPLEMENTED_EXCEPTION();} + virtual void fill(Uint8, Uint64) {THROW_NOT_IMPLEMENTED_EXCEPTION();} + virtual void fill(Int8, Uint64) {THROW_NOT_IMPLEMENTED_EXCEPTION();} }; } #endif // STREAM_HPP diff --git a/src/Athena/BinaryWriter.cpp b/src/Athena/BinaryWriter.cpp index 65a5ef7..56d580f 100644 --- a/src/Athena/BinaryWriter.cpp +++ b/src/Athena/BinaryWriter.cpp @@ -460,6 +460,17 @@ void BinaryWriter::writeString(const std::string& str) writeUByte(0); } +void BinaryWriter::fill(Uint8 val, Uint64 length) +{ + while ((length--) > 0) + writeUByte(val); +} + +void BinaryWriter::fill(Int8 val, Uint64 length) +{ + fill((Uint8)val, length); +} + void BinaryWriter::setProgressCallback(std::function cb) { m_progressCallback = cb;