diff --git a/includes/xna/content/lzx/decoder.hpp b/includes/xna/content/lzx/decoder.hpp index fed9568..fcf5398 100644 --- a/includes/xna/content/lzx/decoder.hpp +++ b/includes/xna/content/lzx/decoder.hpp @@ -2,7 +2,7 @@ #define XNA_CONTENT_LZX_LZXDECODE_HPP #include "../../default.hpp" -#include "../../csharp/stream.hpp" +#include "csharp/io/stream.hpp" #include namespace xna { diff --git a/includes/xna/content/manager.hpp b/includes/xna/content/manager.hpp index 9486312..61ffd8d 100644 --- a/includes/xna/content/manager.hpp +++ b/includes/xna/content/manager.hpp @@ -2,7 +2,7 @@ #define XNA_CONTENT_MANAGER_HPP #include "../csharp/service.hpp" -#include "../csharp/stream.hpp" +#include "csharp/io/stream.hpp" #include "../default.hpp" #include "reader.hpp" @@ -10,34 +10,34 @@ namespace xna { //The run-time component which loads managed objects from the binary files produced by the design time content pipeline. class ContentManager : public std::enable_shared_from_this { public: - ContentManager(sptr const& services) : + ContentManager(std::shared_ptr const& services) : rootDirectory("") { serviceProvider = services; }; - ContentManager(sptr const& services, String const& rootDirectory) : + ContentManager(std::shared_ptr const& services, std::string const& rootDirectory) : rootDirectory(rootDirectory){ serviceProvider = services; }; //Gets the service provider associated with the ContentManager. - sptr ServiceProvider() const { + std::shared_ptr ServiceProvider() const { return serviceProvider; } //Gets or sets the root directory associated with this ContentManager. - constexpr String RootDirectory() const { + constexpr std::string RootDirectory() const { return rootDirectory; } //Gets or sets the root directory associated with this ContentManager. - void RootDirectory(String const& value) { + void RootDirectory(std::string const& value) { rootDirectory = value; } //Loads an asset that has been processed by the Content Pipeline. template - auto Load(String const& assetName) { + auto Load(std::string const& assetName) { if (assetName.empty()) { return misc::ReturnDefaultOrNull(); } @@ -69,13 +69,13 @@ namespace xna { } //Gets the service provider associated with the main Game. - static sptr GameServiceProvider() { + static std::shared_ptr GameServiceProvider() { return mainGameService; } protected: template - auto ReadAsset(String const& assetName) { + auto ReadAsset(std::string const& assetName) { auto input = OpenStream(assetName); if (!input) @@ -88,18 +88,18 @@ namespace xna { return asset; } - sptr OpenStream(String const& assetName) const; + std::shared_ptr OpenStream(std::string const& assetName) const; private: friend class ContentReader; friend class Game; - String rootDirectory; - sptr serviceProvider = nullptr; - std::map> loadedAssets; + std::string rootDirectory; + std::shared_ptr serviceProvider = nullptr; + std::map> loadedAssets; - inline static sptr mainGameService = nullptr; - inline const static String contentExtension = ".xnb"; + inline static std::shared_ptr mainGameService = nullptr; + inline const static std::string contentExtension = ".xnb"; }; } diff --git a/includes/xna/content/reader.hpp b/includes/xna/content/reader.hpp index 2b8a782..2b8670c 100644 --- a/includes/xna/content/reader.hpp +++ b/includes/xna/content/reader.hpp @@ -3,17 +3,20 @@ #include "../common/color.hpp" #include "../common/numerics.hpp" -#include "../csharp/binary.hpp" #include "../csharp/type.hpp" #include "../default.hpp" +#include "csharp/io/binary.hpp" #include "typereadermanager.hpp" #include +#include +#include +#include namespace xna { //A worker object that implements most of ContentManager.Load. - class ContentReader : public BinaryReader, public std::enable_shared_from_this { + class ContentReader : public csharp::BinaryReader, public std::enable_shared_from_this { public: - static sptr Create(sptr const& contentManager, sptr& input, String const& assetName); + static std::shared_ptr Create(std::shared_ptr const& contentManager, std::shared_ptr& input, std::string const& assetName); // Reads a single object from the current stream. template @@ -49,12 +52,12 @@ namespace xna { double ReadDouble() override; //Gets the name of the asset currently being read by this ContentReader. - constexpr String AssetName() const { + constexpr std::string AssetName() const { return _assetName; } //Gets the ContentManager associated with the ContentReader. - sptr ContentManager() const; + std::shared_ptr ContentManager() const; // // Internal methods @@ -63,15 +66,15 @@ namespace xna { template auto ReadAsset(); - std::vector ReadByteBuffer(size_t size); + std::vector ReadByteBuffer(size_t size); private: - ContentReader(sptr const& contentManager, sptr& input, String const& assetName, Int graphicsProfile) - : BinaryReader(input), _contentManager(contentManager), _assetName(assetName) {} + ContentReader(std::shared_ptr const& contentManager, std::shared_ptr& input, std::string const& assetName, int32_t graphicsProfile) + : csharp::BinaryReader(input), _contentManager(contentManager), _assetName(assetName) {} - static sptr PrepareStream(sptr& input, String const& assetName, Int& graphicsProfile); + static std::shared_ptr PrepareStream(std::shared_ptr& input, std::string const& assetName, int32_t& graphicsProfile); - Int ReadHeader(); + int32_t ReadHeader(); template auto ReadObjectInternal(std::any& existingInstance); @@ -83,19 +86,19 @@ namespace xna { auto InvokeReader(ContentTypeReader& reader, Object& existingInstance); private: - sptr _contentManager = nullptr; - String _assetName; - std::vector> typeReaders; - Int graphicsProfile{ 0 }; - std::vector byteBuffer; + std::shared_ptr _contentManager = nullptr; + std::string _assetName; + std::vector> typeReaders; + int32_t graphicsProfile{ 0 }; + std::vector byteBuffer; - static constexpr Ushort XnbVersionProfileMask = 32512; - static constexpr Ushort XnbCompressedVersion = 32773; - static constexpr Ushort XnbVersion = 5; - static constexpr Int XnbVersionProfileShift = 8; - static constexpr Char PlatformLabel = 'w'; - static constexpr Int XnbPrologueSize = 10; - static constexpr Int XnbCompressedPrologueSize = 14; + static constexpr uint16_t XnbVersionProfileMask = 32512; + static constexpr uint16_t XnbCompressedVersion = 32773; + static constexpr uint16_t XnbVersion = 5; + static constexpr int32_t XnbVersionProfileShift = 8; + static constexpr char PlatformLabel = 'w'; + static constexpr int32_t XnbPrologueSize = 10; + static constexpr int32_t XnbCompressedPrologueSize = 14; }; template diff --git a/includes/xna/csharp/binary.hpp b/includes/xna/csharp/binary.hpp deleted file mode 100644 index af51fa0..0000000 --- a/includes/xna/csharp/binary.hpp +++ /dev/null @@ -1,154 +0,0 @@ -#ifndef XNA_CSHARP_BINARY_HPP -#define XNA_CSHARP_BINARY_HPP - -#include "stream.hpp" -#include "../default.hpp" - -namespace xna { - //A simplified port of the System.IO.BinaryReader class. - class BinaryReader { - public: - BinaryReader(sptr const& input); - - //Returns the next available character and does not advance the byte or character position. - Int PeekChar(); - //Reads bytes from the underlying stream and advances the current position of the stream. - virtual Int Read(); - //Reads a Boolean value from the current stream and advances the current position of the stream by one byte. - virtual bool ReadBoolean(); - //Reads the next byte from the current stream and advances the current position of the stream by one byte. - virtual Byte ReadByte(); - //Reads a signed byte from this stream and advances the current position of the stream by one byte. - virtual Sbyte ReadSByte(); - //Reads the next character from the current stream and advances the current position of the stream. - virtual Char ReadChar(); - //Reads a 2-byte signed integer from the current stream and advances the current position of the stream by two bytes. - virtual Short ReadInt16(); - //Reads a 2-byte unsigned integer from the current stream and advances the position of the stream by two bytes. - virtual Ushort ReadUInt16(); - //Reads a 4-byte signed integer from the current stream and advances the current position of the stream by four bytes. - virtual Int ReadInt32(); - //Reads a 4-byte unsigned integer from the current stream and advances the position of the stream by four bytes. - virtual Uint ReadUInt32(); - //Reads a 8-byte signed integer from the current stream and advances the current position of the stream by eight bytes. - virtual Long ReadInt64(); - //Reads a 8-byte unsigned integer from the current stream and advances the position of the stream by eight bytes. - virtual Ulong ReadUInt64(); - //Reads a 4-byte floating point value from the current stream and advances the current position of the stream by four bytes. - virtual float ReadSingle(); - //Reads an 8-byte floating point value from the current stream and advances the current position of the stream by eight bytes. - virtual double ReadDouble(); - //Reads a string from the current stream. - virtual std::string ReadString(); - - //Reads chars from the underlying stream and advances the current position of the stream. - virtual Int Read(std::vector& buffer, size_t index, size_t count); - //Reads bytes from the underlying stream and advances the current position of the stream. - virtual Int Read(std::vector& buffer, size_t index, size_t count); - - // Reads the specified number of bytes from the current stream into a byte array - // and advances the current position by that number of bytes. - virtual std::vector ReadBytes(size_t count); - - // Reads a 32-bit integer in compressed format. - // This function may throw a std::format_error exception. - Int Read7BitEncodedInt(); - - // Reads a 64-bit integer in compressed format. - // This function may throw a std::format_error exception. - Long Read7BitEncodedInt64(); - - //Exposes access to the underlying stream of the BinaryReader. - virtual inline sptr BaseStream() const { - return stream; - } - - //Closes the current reader and the underlying stream. - virtual inline void Close() { - stream = nullptr; - } - - protected: - Int InternalReadOneChar(); - void FillBuffer(Int numBytes); - Int InternalReadChars(Char* buffer, size_t bufferSize, size_t index, size_t count); - - private: - static constexpr int maxCharBytesSize = 128; - static constexpr int bufferLength = 16; - sptr stream = nullptr; - std::vector charBytes; - std::vector singleChar; - std::vector buffer; - std::vector charBuffer; - }; - - //A simplified port of the System.IO.BinaryWriter class. - class BinaryWriter { - public: - BinaryWriter(sptr const& stream); - - protected: - BinaryWriter() = default; - - //Sets the position within the current stream. - Long Seek(Int offset, SeekOrigin origin); - - // - // Writes a value to the current stream. - // - - //Writes a value to the current stream. - virtual void Write(bool value); - //Writes a value to the current stream. - virtual void Write(Byte value); - //Writes a value to the current stream. - virtual void Write(Sbyte value); - //Writes a value to the current stream. - virtual void Write(Byte const* buffer, Int bufferLength); - //Writes a value to the current stream. - virtual void Write(std::vector const& buffer); - //Writes a value to the current stream. - virtual void Write(Byte const* buffer, Int bufferLength, Int index, Int count); - //Writes a value to the current stream. - virtual void Write(std::vector const& buffer, Int index, Int count); - //Writes a value to the current stream. - virtual void Write(Char ch); - //Writes a value to the current stream. - virtual void Write(double value); - //Writes a value to the current stream. - virtual void Write(Short value); - //Writes a value to the current stream. - virtual void Write(Ushort value); - //Writes a value to the current stream. - virtual void Write(Int value); - //Writes a value to the current stream. - virtual void Write(Uint value); - //Writes a value to the current stream. - virtual void Write(Long value); - //Writes a value to the current stream. - virtual void Write(Ulong value); - //Writes a value to the current stream. - virtual void Write(float value); - //Writes a value to the current stream. - virtual void Write(std::string const& value); - //Writes a value to the current stream. - virtual void Write(const char* _string, size_t stringLength); - - //Exposes access to the underlying stream of the BinaryWriter. - virtual inline sptr BaseStream() const { - return OutStream; - } - - //Writes a 32-bit integer in a compressed format. - void Write7BitEncodedInt(Int value); - - protected: - sptr OutStream = nullptr; - - private: - std::vector _buffer; - }; -} - -#endif \ No newline at end of file diff --git a/includes/xna/csharp/stream.hpp b/includes/xna/csharp/stream.hpp deleted file mode 100644 index 450cb1f..0000000 --- a/includes/xna/csharp/stream.hpp +++ /dev/null @@ -1,206 +0,0 @@ -#ifndef XNA_CSHARP_STREAM_HPP -#define XNA_CSHARP_STREAM_HPP - -#include -#include -#include -#include -#include "csharp/exception.hpp" - -namespace xna { - // Provides seek reference points. - // To seek to the end of a stream, call stream.Seek(0, SeekOrigin.End). - enum class SeekOrigin { - Begin, - Current, - End, - }; - - // Contains constants for specifying how the OS should open a file. - // These will control whether you overwrite a file, open an existing - // file, or some combination thereof. - // - // To append to a file, use Append (which maps to OpenOrCreate then we seek - // to the end of the file). To truncate a file or create it if it doesn't - // exist, use Create. - enum class FileMode { - // Creates a new file. An exception is raised if the file already exists. - CreateNew, - // Creates a new file. If the file already exists, it is overwritten. - Create, - // Opens an existing file. An exception is raised if the file does not exist. - Open, - // Opens the file if it exists. Otherwise, creates a new file. - OpenOrCreate, - // Opens an existing file. Once opened, the file is truncated so that its - // size is zero bytes. The calling process must open the file with at least - // WRITE access. An exception is raised if the file does not exist. - Truncate, - // Opens the file if it exists and seeks to the end. Otherwise, - // creates a new file. - Append, - }; - - //A simplified port of the System.IO.Stream. - //Provides a generic view of a sequence of bytes. This is an abstract class. - class Stream { - public: - virtual ~Stream(){} - - //When overridden in a derived class, gets a value indicating whether the current stream supports reading. - virtual bool CanRead() { return true; } - //When overridden in a derived class, gets a value indicating whether the current stream supports writing. - virtual bool CanWrite() { return true; } - //When overridden in a derived class, gets a value indicating whether the current stream supports seeking. - virtual bool CanSeek() { return true; } - //Gets a value that determines whether the current stream can time out. - virtual bool CanTimeout() { return false; } - - //Gets the length in bytes of the stream. - virtual int64_t Length() = 0; - //Gets or sets the position within the current stream. - virtual int64_t Position() = 0; - //Gets or sets the position within the current stream. - virtual void Position(int64_t value) { Seek(value, SeekOrigin::Begin); } - - //When overridden in a derived class, sets the length of the current stream. - virtual void SetLength(int64_t value) = 0; - - //Closes the current stream and releases any resources - virtual void Close() = 0; - //Sets the position within the current stream. - virtual int64_t Seek(int64_t offset, SeekOrigin const& origin) = 0; - - //Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read. - virtual int32_t Read(uint8_t* buffer, int32_t bufferLength, int32_t offset, int32_t count) = 0; - //Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read. - virtual int32_t Read(std::vector& buffer, int32_t offset, int32_t count) = 0; - - //Reads a byte from the stream and advances the position within the stream by one byte, or returns -1 if at the end of the stream. - virtual int32_t ReadByte() = 0; - - //Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written. - virtual void Write(uint8_t const* buffer, int32_t bufferLength, int32_t offset, int32_t count) = 0; - //Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written. - virtual void Write(std::vector const& buffer, int32_t offset, int32_t count) = 0; - - //Writes a byte to the current position in the stream and advances the position within the stream by one byte. - virtual void WriteByte(uint8_t value) = 0; - }; - - //A simplified port of the System.IO.MemoryStream. - class MemoryStream : public Stream { - public: - constexpr MemoryStream(){} - - constexpr MemoryStream(std::vector const& bytes): - _buffer(bytes), - _length(static_cast(bytes.size())){} - - ~MemoryStream() override { - Close(); - } - - constexpr MemoryStream(int32_t capacity) : - _buffer(static_cast(capacity)), - _length(capacity > 0 ? capacity : 0){} - - virtual constexpr int64_t Length() override { - if (_closed) - return 0; - - return _length; - } - - virtual constexpr void SetLength(int64_t value) override { - _buffer.reserve(value); - _length = value; - } - - virtual constexpr int64_t Position() override { - if (_closed) - return 0; - - return _position; - } - - virtual constexpr void Close() override { - _closed = true; - _buffer = std::vector(); - - } - - virtual int64_t Seek(int64_t offset, SeekOrigin const& origin) override; - virtual int32_t Read(uint8_t* buffer, int32_t bufferLength, int32_t offset, int32_t count) override; - virtual int32_t Read(std::vector& buffer, int32_t offset, int32_t count) override; - virtual int32_t ReadByte() override; - virtual void Write(uint8_t const* buffer, int32_t bufferLength, int32_t offset, int32_t count) override; - virtual void Write(std::vector const& buffer, int32_t offset, int32_t count) override; - virtual void WriteByte(uint8_t value) override; - - public: - std::vector _buffer; - - private: - int32_t _position{ 0 }; - int32_t _origin{ 0 }; - int64_t _length{ 0 }; - bool _closed{ false }; - }; - - //A simplified port of the System.IO.FileStream. - class FileStream : public Stream { - public: - FileStream(std::string const& path, FileMode fileMode); - FileStream(std::string const& path); - - ~FileStream() override { - Close(); - } - - virtual int64_t Length() override; - virtual int64_t Position() override; - - virtual void SetLength(int64_t value) override { - throw csharp::InvalidOperationException(); - } - - inline virtual void Close() override { - _closed = true; - - if(_fstream.is_open()) - _fstream.close(); - } - - virtual int64_t Seek(int64_t offset, SeekOrigin const& origin) override; - virtual int32_t Read(uint8_t* buffer, int32_t bufferLength, int32_t offset, int32_t count) override; - virtual int32_t Read(std::vector& buffer, int32_t offset, int32_t count) override; - virtual int32_t ReadByte() override; - virtual void Write(uint8_t const* buffer, int32_t bufferLength, int32_t offset, int32_t count) override; - virtual void Write(std::vector const& buffer, int32_t offset, int32_t count) override; - virtual void WriteByte(uint8_t value) override; - - public: - std::fstream _fstream; - - private: - std::streampos _filesize{ 0 }; - bool _closed{ false }; - bool _truncated{ false }; - - int64_t endOfFile() { - if (_closed) - return 0; - - const auto pos = _fstream.tellg(); - _fstream.seekg(0, std::ios_base::end); - - const auto end = _fstream.tellg(); - _fstream.seekg(pos); - - return static_cast(end); - } - }; -} - -#endif \ No newline at end of file diff --git a/includes/xna/framework.hpp b/includes/xna/framework.hpp index 1458237..1629ef1 100644 --- a/includes/xna/framework.hpp +++ b/includes/xna/framework.hpp @@ -17,10 +17,8 @@ #include "content/readers/default.hpp" #include "content/readers/graphics.hpp" #include "content/typereadermanager.hpp" -#include "csharp/binary.hpp" #include "csharp/buffer.hpp" #include "csharp/service.hpp" -#include "csharp/stream.hpp" #include "csharp/timespan.hpp" #include "csharp/type.hpp" #include "csharp/screen.hpp" diff --git a/includes/xna/graphics/texture.hpp b/includes/xna/graphics/texture.hpp index d9525ce..6f73497 100644 --- a/includes/xna/graphics/texture.hpp +++ b/includes/xna/graphics/texture.hpp @@ -1,7 +1,7 @@ #ifndef XNA_GRAPHICS_TEXTURE_HPP #define XNA_GRAPHICS_TEXTURE_HPP -#include "../csharp/stream.hpp" +#include "csharp/io/stream.hpp" #include "gresource.hpp" #include "shared.hpp" #include @@ -51,7 +51,7 @@ namespace xna { void SetData(int32_t level, Rectangle* rect, std::vector const& data, size_t startIndex, size_t elementCount); //Loads texture data from a stream. - static std::shared_ptr FromStream(GraphicsDevice& device, std::shared_ptr const& stream); + static std::shared_ptr FromStream(GraphicsDevice& device, csharp::Stream& stream); //Loads texture data from a file. static std::shared_ptr FromStream(GraphicsDevice& device, std::string const& fileName); //Loads texture data from a data. diff --git a/sources/framework-dx/init.cpp b/sources/framework-dx/init.cpp index bf058b2..7659443 100644 --- a/sources/framework-dx/init.cpp +++ b/sources/framework-dx/init.cpp @@ -28,7 +28,7 @@ namespace xna { insertRegisteredReader("BooleanReader"); insertRegisteredReader("ByteReader"); //insertRegisteredReader("CharReader"); - insertRegisteredReader("CharReader", "Microsoft.Xna.Framework.Content.CharReader`1[[System.Char"); + insertRegisteredReader("CharReader", "Microsoft.Xna.Framework.Content.CharReader"); insertRegisteredReader("ColorReader"); insertRegisteredReader("DoubleReader"); insertRegisteredReader("Int16Reader"); @@ -39,7 +39,7 @@ namespace xna { insertRegisteredReader("QuaternionReader"); //insertRegisteredReader("RectangleReader"); - insertRegisteredReader("RectangleReader", "Microsoft.Xna.Framework.Content.RectangleReadericrosoft.Xna.Framework.Rectangle"); + insertRegisteredReader("RectangleReader", "Microsoft.Xna.Framework.Content.RectangleReader"); insertRegisteredReader("SByteReader"); insertRegisteredReader("SingleReader"); @@ -49,7 +49,7 @@ namespace xna { insertRegisteredReader("UInt64Reader"); insertRegisteredReader("Vector2Reader"); //insertRegisteredReader("Vector3Reader"); - insertRegisteredReader("Vector3Reader", "Microsoft.Xna.Framework.Content.Vector3Reader[Microsoft.Xna.Framework.Vector3"); + insertRegisteredReader("Vector3Reader", "Microsoft.Xna.Framework.Content.Vector3Reader"); insertRegisteredReader("Vector4Reader"); insertRegisteredReader("Texture2DReader"); insertRegisteredReader("SoundEffectReader"); diff --git a/sources/framework-dx/soundeffect.cpp b/sources/framework-dx/soundeffect.cpp index 6bb5276..a1b56d9 100644 --- a/sources/framework-dx/soundeffect.cpp +++ b/sources/framework-dx/soundeffect.cpp @@ -1,5 +1,5 @@ #include "xna-dx/framework.hpp" -#include "xna/csharp/stream.hpp" +#include "csharp/io/stream.hpp" using DxSoundEffect = DirectX::SoundEffect; @@ -35,7 +35,7 @@ namespace xna { return; //We expect 'format' to always be 16 bytes - MemoryStream stream(format); + csharp::MemoryStream stream(format); WORD word = 0; DWORD dword = 0; diff --git a/sources/framework-dx/texture.cpp b/sources/framework-dx/texture.cpp index 28123c1..1a14077 100644 --- a/sources/framework-dx/texture.cpp +++ b/sources/framework-dx/texture.cpp @@ -217,16 +217,16 @@ namespace xna { throw csharp::InvalidOperationException(); } - P_Texture2D Texture2D::FromStream(GraphicsDevice& device, P_Stream const& stream) + P_Texture2D Texture2D::FromStream(GraphicsDevice& device, csharp::Stream& stream) { std::vector data; - const auto lenght = stream->Length(); - stream->Read(data, 0, lenght - 1); + const auto lenght = stream.Length(); + stream.Read(data.data(), data.size(), 0, lenght - 1); return FromStream(device, data); } - sptr Texture2D::FromStream(GraphicsDevice& device, String const& fileName) + sptr Texture2D::FromStream(GraphicsDevice& device, std::string const& fileName) { auto _this = device.shared_from_this(); auto texture2d = snew(_this); diff --git a/sources/framework/CMakeLists.txt b/sources/framework/CMakeLists.txt index 6778e87..6011cec 100644 --- a/sources/framework/CMakeLists.txt +++ b/sources/framework/CMakeLists.txt @@ -4,8 +4,6 @@ # Add source to this project's executable. add_library (Xn65 STATIC -"csharp/stream.cpp" -"csharp/binary.cpp" "game/component.cpp" "game/servicecontainer.cpp" "content/manager.cpp" diff --git a/sources/framework/content/manager.cpp b/sources/framework/content/manager.cpp index 79bce6e..0ee4b24 100644 --- a/sources/framework/content/manager.cpp +++ b/sources/framework/content/manager.cpp @@ -1,10 +1,10 @@ #include "xna/content/manager.hpp" namespace xna { - sptr ContentManager::OpenStream(String const& assetName) const { - const String filePath = rootDirectory + "\\" + assetName + contentExtension; - const auto stream = snew(filePath, FileMode::Open); + std::shared_ptr ContentManager::OpenStream(std::string const& assetName) const { + const auto filePath = rootDirectory + "\\" + assetName + contentExtension; + const auto stream = snew(filePath, csharp::FileMode::Open); - return reinterpret_pointer_cast(stream); + return reinterpret_pointer_cast(stream); } } \ No newline at end of file diff --git a/sources/framework/content/reader.cpp b/sources/framework/content/reader.cpp index 59de6b2..7f874f7 100644 --- a/sources/framework/content/reader.cpp +++ b/sources/framework/content/reader.cpp @@ -3,14 +3,14 @@ #include "xna/content/typereadermanager.hpp" namespace xna { - sptr ContentReader::Create(sptr const& contentManager, sptr& input, String const& assetName) + std::shared_ptr ContentReader::Create(std::shared_ptr const& contentManager, std::shared_ptr& input, String const& assetName) { Int graphicsProfile = 0; input = ContentReader::PrepareStream(input, assetName, graphicsProfile); return std::shared_ptr(new ContentReader(contentManager, input, assetName, graphicsProfile)); } - sptr ContentReader::ContentManager() const { + std::shared_ptr ContentReader::ContentManager() const { return _contentManager; } @@ -101,7 +101,7 @@ namespace xna { Int num = 0; for (size_t index = 0; index < size; index += num) { - num = Read(byteBuffer, index, size - index); + num = Read(byteBuffer.data(), byteBuffer.size(), index, size - index); if (num == 0) { throw std::runtime_error("ContentReader::ReadByteBuffer: Bad xbn."); } @@ -110,7 +110,7 @@ namespace xna { return byteBuffer; } - sptr ContentReader::PrepareStream(sptr& input, String const& assetName, Int& graphicsProfile) + std::shared_ptr ContentReader::PrepareStream(std::shared_ptr& input, String const& assetName, Int& graphicsProfile) { BinaryReader binaryReader = BinaryReader(input); diff --git a/sources/framework/content/typereadermanager.cpp b/sources/framework/content/typereadermanager.cpp index 5ab9d76..f55807d 100644 --- a/sources/framework/content/typereadermanager.cpp +++ b/sources/framework/content/typereadermanager.cpp @@ -115,7 +115,10 @@ namespace xna { type = Type::NameOfRegisteredTypes[readerTypeName]; if (!type) { - throw std::runtime_error("ContentTypeReaderManager::InstantiateTypeReader: registered type is null."); + + std::string error("ContentTypeReaderManager::InstantiateTypeReader: registered type is null. "); + error.append("TypeName: " + readerTypeName); + throw std::runtime_error(error); } if (ContentTypeReaderManager::readerTypeToReader.contains(type)) { diff --git a/sources/framework/csharp/binary.cpp b/sources/framework/csharp/binary.cpp deleted file mode 100644 index 7b936e9..0000000 --- a/sources/framework/csharp/binary.cpp +++ /dev/null @@ -1,600 +0,0 @@ -#include "xna/csharp/binary.hpp" -#include "xna/csharp/buffer.hpp" - -namespace xna { - BinaryReader::BinaryReader(sptr const& input) { - if(!input) - throw csharp::ArgumentNullException("input"); - - stream = input; - buffer = std::vector(bufferLength); - } - - Int BinaryReader::PeekChar() - { - const auto position = stream->Position(); - const auto num = Read(); - - stream->Seek(position, SeekOrigin::Begin); - - return num; - } - - Int BinaryReader::Read() - { - const auto result = InternalReadOneChar(); - - return result; - } - - bool BinaryReader::ReadBoolean() - { - FillBuffer(1); - return buffer[0] > 0; - } - - Byte BinaryReader::ReadByte() - { - const auto num = stream->ReadByte(); - - return static_cast(num); - } - - Sbyte BinaryReader::ReadSByte() - { - FillBuffer(1); - return static_cast(buffer[0]); - } - - Char BinaryReader::ReadChar() - { - auto num = Read(); - - if (num == -1) - return '\0'; - - return static_cast(num); - } - - Short BinaryReader::ReadInt16() - { - FillBuffer(2); - - return static_cast( - static_cast(buffer[0]) - | static_cast(buffer[1]) << 8); - } - - Ushort BinaryReader::ReadUInt16() - { - FillBuffer(2); - - return static_cast( - static_cast(buffer[0]) - | static_cast(buffer[1]) << 8); - } - - Int BinaryReader::ReadInt32() - { - FillBuffer(4); - - return static_cast(buffer[0]) - | static_cast(buffer[1]) << 8 - | static_cast(buffer[2]) << 16 - | static_cast(buffer[3]) << 24; - } - - Uint BinaryReader::ReadUInt32() - { - FillBuffer(4); - - return static_cast( - static_cast(buffer[0]) - | static_cast(buffer[1]) << 8 - | static_cast(buffer[2]) << 16 - | static_cast(buffer[3]) << 24); - } - - Long BinaryReader::ReadInt64() - { - FillBuffer(8); - - const auto num1 = static_cast( - static_cast(buffer[4]) - | static_cast(buffer[5]) << 8 - | static_cast(buffer[6]) << 16 - | static_cast(buffer[7]) << 24); - - const auto num2 = static_cast( - static_cast(buffer[0]) - | static_cast(buffer[1]) << 8 - | static_cast(buffer[2]) << 16 - | static_cast(buffer[3]) << 24); - - return static_cast(num1) << 32 | static_cast(num2); - } - - Ulong BinaryReader::ReadUInt64() - { - FillBuffer(8); - - const auto num1 = static_cast( - static_cast(buffer[4]) - | static_cast(buffer[5]) << 8 - | static_cast(buffer[6]) << 16 - | static_cast(buffer[7]) << 24); - - const auto num2 = static_cast( - static_cast(buffer[0]) - | static_cast(buffer[1]) << 8 - | static_cast(buffer[2]) << 16 - | static_cast(buffer[3]) << 24); - - return static_cast(num1) << 32 | static_cast(num2); - } - - float BinaryReader::ReadSingle() - { - FillBuffer(4); - - const auto num = static_cast( - static_cast(buffer[0]) - | static_cast(buffer[1]) << 8 - | static_cast(buffer[2]) << 16 - | static_cast(buffer[3]) << 24); - - return *(float*)# - } - - double BinaryReader::ReadDouble() - { - FillBuffer(8); - - const auto num1 = static_cast( - static_cast(buffer[4]) - | static_cast(buffer[5]) << 8 - | static_cast(buffer[6]) << 16 - | static_cast(buffer[7]) << 24); - - const auto num2 = static_cast( - static_cast(buffer[0]) - | static_cast(buffer[1]) << 8 - | static_cast(buffer[2]) << 6 - | static_cast(buffer[3]) << 24); - - const auto num3 = static_cast(num1) << 32 | static_cast(num2); - - return *(double*)&num3; - } - - std::string BinaryReader::ReadString() - { - static const auto empty = std::string(); - - Int num = 0; - auto val1 = Read7BitEncodedInt(); - - if (val1 < 0) { - //xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); - return empty; - } - - if (val1 == 0) - return empty; - - if (charBytes.empty()) - charBytes.resize(maxCharBytesSize); - - if (charBuffer.empty()) - charBuffer.resize(maxCharBytesSize); - - std::string sb; - - do { - const auto byteCount = stream->Read(charBytes, 0, val1 - num > 128 ? 128 : val1 - num); - - if (byteCount == 0) { - //xna_error_apply(err, XnaErrorCode::END_OF_FILE); - return empty; - } - - auto data = reinterpret_cast(charBytes.data()); - const auto result = std::string(data); - - if (num == 0 && byteCount == val1) { - return result; - } - - sb.append(result); - num += byteCount; - - } while (num < val1); - - return sb; - } - - Int BinaryReader::InternalReadOneChar() - { - Int num1 = 0; - Long num2 = 0; - Long num3 = stream->Position(); - - if (charBytes.empty()) - charBytes.resize(128); - - if (singleChar.empty()) - singleChar.resize(1); - - while (num1 == 0) - { - //auto byteCount = m2BytesPerChar ? 2 : 1; - auto byteCount = 1; - const auto num4 = stream->ReadByte(); - - charBytes[0] = static_cast(num4); - - if (num4 == -1) - byteCount = 0; - - if (byteCount == 2) { - auto num5 = stream->ReadByte(); - charBytes[1] = static_cast(num5); - - if (num5 == -1) - byteCount = 1; - } - - if (byteCount == 0) { - return -1; - } - - auto data = reinterpret_cast(charBytes.data()); - const auto result = std::string(data, data + byteCount); - - if (!result.empty()) - { - num1 = static_cast(result.size()); - singleChar[0] = result[0]; - } - } - - return num1 == 0 ? -1 : static_cast(singleChar[0]); - } - - void BinaryReader::FillBuffer(Int numBytes) - { - if (numBytes < 0 || numBytes > buffer.size()) { - throw csharp::InvalidOperationException(); - } - - Int bytesRead = 0; - Int n = 0; - - if (numBytes == 1) { - n = stream->ReadByte(); - - if (n == -1){ - throw csharp::InvalidOperationException(); - } - - buffer[0] = static_cast(n); - return; - } - - do { - n = stream->Read(buffer, bytesRead, numBytes - bytesRead); - - if (n == 0) { - throw csharp::InvalidOperationException(); - } - - bytesRead += n; - } while (bytesRead < numBytes); - } - - Int BinaryReader::InternalReadChars(Char* buffer, size_t bufferSize, size_t index, size_t count) - { - auto charCount = count; - - if (charBytes.empty()) - charBytes.resize(128); - - while (charCount > 0) { - auto count1 = charCount; - - if (count1 > 1) - --count1; - - /*if (m2BytesPerChar) - count1 <<= 1;*/ - - if (count1 > 128) - count1 = 128; - - Int position = 0; - Int byteCount; - - std::vector numArray; - - byteCount = stream->Read(charBytes, 0, static_cast(count1)); - numArray = charBytes; - - if (byteCount == 0) - return static_cast(count - charCount); - - if (position < 0 || byteCount < 0 || (position + byteCount) > numArray.size()) { - return -1; - } - - if (index < 0 || charCount < 0 || (index + charCount) > bufferSize) { - return -1; - } - - auto data = reinterpret_cast(charBytes.data()); - auto pChars = reinterpret_cast(buffer); - - //const auto result = std::string((data + position), (pChars + index) + byteCount); - const auto result = std::string((data + position), (data + position) + byteCount); - Buffer::BlockCopy(result.c_str(), position, pChars, index, byteCount); - - buffer = reinterpret_cast(pChars); - - const auto chars = static_cast(result.size()); - - charCount -= chars; - index += chars; - } - - return static_cast(count - charCount); - } - - Int BinaryReader::Read7BitEncodedInt() - { - Uint result = 0; - Byte byteReadJustNow; - - constexpr Int MaxBytesWithoutOverflow = 4; - - for (size_t shift = 0; shift < MaxBytesWithoutOverflow * 7; shift += 7) - { - byteReadJustNow = ReadByte(); - result |= (byteReadJustNow & 0x7Fu) << shift; - - if (byteReadJustNow <= 0x7Fu) - { - return static_cast(result); - } - } - - byteReadJustNow = ReadByte(); - - if (byteReadJustNow > 0b1111u) { - throw std::format_error("Too many bytes in what should have been a 7-bit encoded integer."); - } - - result |= static_cast(byteReadJustNow) << (MaxBytesWithoutOverflow * 7); - return static_cast(result); - } - - Long BinaryReader::Read7BitEncodedInt64() { - Ulong result = 0; - Byte byteReadJustNow; - - constexpr Int MaxBytesWithoutOverflow = 9; - - for (size_t shift = 0; shift < MaxBytesWithoutOverflow * 7; shift += 7) - { - byteReadJustNow = ReadByte(); - result |= (static_cast(byteReadJustNow & 0x7Ful)) << shift; - - if (byteReadJustNow <= 0x7Fu) { - return static_cast(result); - } - } - - byteReadJustNow = ReadByte(); - - if (byteReadJustNow > 0b1u) - { - throw std::format_error("Too many bytes in what should have been a 7-bit encoded integer."); - } - - result |= static_cast(byteReadJustNow) << (MaxBytesWithoutOverflow * 7); - return static_cast(result); - } - - Int BinaryReader::Read(std::vector& buffer, size_t index, size_t count) - { - return InternalReadChars(buffer.data(), buffer.size(), index, count); - } - - Int BinaryReader::Read(std::vector& buffer, size_t index, size_t count) - { - auto data = reinterpret_cast(buffer.data()); - return InternalReadChars(data, buffer.size(), index, count); - } - - std::vector BinaryReader::ReadBytes(size_t count) - { - std::vector result(count); - Int numRead = 0; - - do { - const auto n = stream->Read(result, static_cast(numRead), static_cast(count)); - - if (n == 0) - break; - - numRead += n; - count -= n; - } while (count > 0); - - if (numRead != result.size()) { - std::vector copy(numRead); - Buffer::BlockCopy(result.data(), 0, copy.data(), 0, numRead); - result = copy; - } - - return result; - } - - //Binary Writer - - BinaryWriter::BinaryWriter(sptr const& stream) { - throw csharp::ArgumentNullException("stream"); - - OutStream = stream; - _buffer = std::vector(16); - } - - Long BinaryWriter::Seek(Int offset, SeekOrigin origin) - { - return OutStream->Seek(offset, origin); - } - - void BinaryWriter::Write(bool value) - { - _buffer[0] = value ? static_cast(1) : static_cast(0); - OutStream->Write(_buffer, 0, 1); - } - - void BinaryWriter::Write(Byte value) - { - OutStream->WriteByte(value); - } - - void BinaryWriter::Write(Sbyte value) - { - OutStream->WriteByte(static_cast(value)); - } - - void BinaryWriter::Write(Byte const* buffer, Int bufferLength) - { - OutStream->Write(buffer, bufferLength, 0, bufferLength); - } - - void BinaryWriter::Write(std::vector const& buffer) - { - OutStream->Write(buffer, 0, static_cast(buffer.size())); - } - - void BinaryWriter::Write(Byte const* buffer, Int bufferLength, Int index, Int count) - { - OutStream->Write(buffer, bufferLength, index, count); - } - - void BinaryWriter::Write(std::vector const& buffer, Int index, Int count) - { - OutStream->Write(buffer, index, count); - } - - void BinaryWriter::Write(Char ch) - { - _buffer[0] = static_cast(ch); - OutStream->Write(_buffer, 0, 1); - } - - void BinaryWriter::Write(double value) - { - Ulong num = (Ulong) * (Long*)&value; - _buffer[0] = static_cast(num); - _buffer[1] = static_cast(num >> 8); - _buffer[2] = static_cast(num >> 16); - _buffer[3] = static_cast(num >> 24); - _buffer[4] = static_cast(num >> 32); - _buffer[5] = static_cast(num >> 40); - _buffer[6] = static_cast(num >> 48); - _buffer[7] = static_cast(num >> 56); - - OutStream->Write(_buffer, 0, 8); - } - - void BinaryWriter::Write(Short value) - { - _buffer[0] = static_cast(value); - _buffer[1] = static_cast((Uint)value >> 8); - OutStream->Write(_buffer, 0, 2); - } - - void BinaryWriter::Write(Ushort value) - { - _buffer[0] = static_cast(value); - _buffer[1] = static_cast((Uint)value >> 8); - OutStream->Write(_buffer, 0, 2); - } - - void BinaryWriter::Write(Int value) - { - _buffer[0] = static_cast(value); - _buffer[1] = static_cast(value >> 8); - _buffer[2] = static_cast(value >> 16); - _buffer[3] = static_cast(value >> 24); - OutStream->Write(_buffer, 0, 4); - } - - void BinaryWriter::Write(Uint value) - { - _buffer[0] = static_cast(value); - _buffer[1] = static_cast(value >> 8); - _buffer[2] = static_cast(value >> 16); - _buffer[3] = static_cast(value >> 24); - OutStream->Write(_buffer, 0, 4); - } - - void BinaryWriter::Write(Ulong value) - { - _buffer[0] = static_cast(value); - _buffer[1] = static_cast(value >> 8); - _buffer[2] = static_cast(value >> 16); - _buffer[3] = static_cast(value >> 24); - _buffer[4] = static_cast(value >> 32); - _buffer[5] = static_cast(value >> 40); - _buffer[6] = static_cast(value >> 48); - _buffer[7] = static_cast(value >> 56); - OutStream->Write(_buffer, 0, 8); - } - - void BinaryWriter::Write(float value) - { - Uint num = *(Uint*)&value; - _buffer[0] = static_cast(num); - _buffer[1] = static_cast(num >> 8); - _buffer[2] = static_cast(num >> 16); - _buffer[3] = static_cast(num >> 24); - OutStream->Write(_buffer, 0, 4); - } - - void BinaryWriter::Write(std::string const& value) - { - Write(value.c_str(), value.size()); - } - - void BinaryWriter::Write(const char* _string, size_t stringLength) - { - Write7BitEncodedInt(static_cast(stringLength)); - const auto b = reinterpret_cast(_string); - OutStream->Write(b, static_cast(stringLength), 0, static_cast(stringLength)); - } - - void BinaryWriter::Write7BitEncodedInt(Int value) - { - Uint num; - for (num = static_cast(value); num >= static_cast(128U); num >>= 7) - Write(static_cast(num | static_cast(128U))); - - Write(static_cast(num)); - } - - void BinaryWriter::Write(Long value) - { - _buffer[0] = static_cast(value); - _buffer[1] = static_cast(value >> 8); - _buffer[2] = static_cast(value >> 16); - _buffer[3] = static_cast(value >> 24); - _buffer[4] = static_cast(value >> 32); - _buffer[5] = static_cast(value >> 40); - _buffer[6] = static_cast(value >> 48); - _buffer[7] = static_cast(value >> 56); - OutStream->Write(_buffer, 0, 8); - } -} \ No newline at end of file diff --git a/sources/framework/csharp/stream.cpp b/sources/framework/csharp/stream.cpp deleted file mode 100644 index 401aae9..0000000 --- a/sources/framework/csharp/stream.cpp +++ /dev/null @@ -1,312 +0,0 @@ -#include "xna/csharp/stream.hpp" -#include "xna/csharp/buffer.hpp" -#include "csharp/exception.hpp" -#include - -namespace xna { - int64_t MemoryStream::Seek(int64_t offset, SeekOrigin const& origin) { - int64_t p = 0; - - switch (origin) - { - case SeekOrigin::Begin: - p = _origin + offset; - - if (p < _origin) { - return -1; - } - break; - case SeekOrigin::Current: - p = _position + offset; - - if (p < _origin) { - return -1; - } - break; - case SeekOrigin::End: - p = _length + offset; - - if (p < _origin) { - return -1; - } - break; - default: - return -1; - } - - _position = static_cast(p); - return _position; - } - - int32_t MemoryStream::Read(uint8_t* buffer, int32_t bufferLength, int32_t offset, int32_t count) { - if (buffer == nullptr || offset < 0 || count < 0 || bufferLength - offset < count) { - return -1; - } - - auto off = _length - _position; - if (off > count) off = count; - - if (off <= 0 || _closed) - return 0; - - if (off <= 8) { - auto byteCount = off; - while (--byteCount >= 0) - buffer[offset + byteCount] = _buffer[_position + static_cast(byteCount)]; - } - else { - Buffer::BlockCopy(_buffer.data(), _position, buffer, offset, off); - } - - _position += off; - - return off; - } - - int32_t MemoryStream::Read(std::vector& buffer, int32_t offset, int32_t count) { - return Read(buffer.data(), static_cast(buffer.size()), offset, count); - } - - int32_t MemoryStream::ReadByte() { - if (!_closed) - return 0; - - if (_position >= _length) - return -1; - - return _buffer[_position++]; - } - - void MemoryStream::Write(uint8_t const* buffer, int32_t bufferLength, int32_t offset, int32_t count){ - if (buffer == nullptr || offset < 0 || count < 0 || bufferLength - offset < count) { - return; - } - - if (_closed) - return; - - auto i = _position + count; - - if (i < 0 || i > _length) { - throw csharp::InvalidOperationException("i < 0 || i > _length"); - } - - if (count <= 8) { - auto byteCount = count; - while (--byteCount >= 0) - _buffer[_position + static_cast(byteCount)] = buffer[offset + byteCount]; - } - else - Buffer::BlockCopy(buffer, offset, _buffer.data(), _position, count); - - _position = i; - } - - void MemoryStream::Write(std::vector const& buffer, int32_t offset, int32_t count){ - Write(buffer.data(), static_cast(buffer.size()), offset, count); - } - - void MemoryStream::WriteByte(uint8_t value) { - if (_closed) - return; - - if (_position >= _length) { - return; - } - - _buffer[_position++] = value; - } - - FileStream::FileStream(std::string const& path, FileMode fileMode) { - int flags = std::fstream::in - | std::fstream::out - | std::fstream::binary; - - const auto exists = std::filesystem::exists(path); - - switch (fileMode) - { - //Especifica se deve abrir um arquivo existente. - case FileMode::Open: - if (!exists) - throw csharp::InvalidOperationException("The specified file does not exist."); - break; - //Especifica que se deve abrir um arquivo, se existir; - // caso contrário, um novo arquivo deverá ser criado. - case FileMode::OpenOrCreate: - case FileMode::Create: - if (!exists) - flags |= std::fstream::trunc; - break; - //Especifica que o sistema operacional deve criar um novo arquivo. - //Se o arquivo já existir, não abre o arquivo. - case FileMode::CreateNew: - if (!exists) - flags |= std::fstream::trunc; - else - throw csharp::InvalidOperationException("The specified file already exists."); - break; - //Abre o arquivo, se existir, e busca o final do arquivo ou cria um novo arquivo. - case FileMode::Append: - if (!exists) - flags |= std::fstream::trunc; - else - flags |= std::fstream::app; - break; - //Especifica que se deve abrir um arquivo existente. - //Quando o arquivo for aberto, ele deverá ser truncado - //para que seu tamanho seja zero bytes. - //Tentativa de ler um arquivo truncado retornará 0; - case FileMode::Truncate: - if(!exists) - throw csharp::InvalidOperationException("The specified file does not exist."); - - flags |= std::fstream::trunc; - _truncated = true; - break; - default: - break; - } - - _fstream.open(path.c_str(), flags); - - if (!_fstream.good()) - throw csharp::InvalidOperationException("Failed to open file: " + path); - } - - FileStream::FileStream(std::string const& path) { - int flags = std::fstream::in - | std::fstream::out - | std::fstream::binary; - - const auto exists = std::filesystem::exists(path); - - if (!exists) - flags |= std::fstream::trunc; - - _fstream.open(path.c_str(), flags); - - if (!_fstream.good()) - throw csharp::InvalidOperationException("Failed to open file: " + path); - } - - int64_t FileStream::Length() { - if (_closed) - return 0; - - const auto end = endOfFile(); - return end; - } - - int64_t FileStream::Position() { - if (_closed) - return 0; - - return static_cast(_fstream.tellg()); - } - - int64_t FileStream::Seek(int64_t offset, SeekOrigin const& origin){ - if (_closed) - return 0; - - int seek; - - switch (origin) - { - case SeekOrigin::Begin: - seek = std::ios_base::beg; - break; - case SeekOrigin::Current: - seek = std::ios_base::cur; - break; - case SeekOrigin::End: - seek = std::ios_base::end; - break; - default: - return -1; - } - - _fstream.seekg(offset, seek); - const auto state = _fstream.rdstate(); - - if (state != std::fstream::goodbit) { - return -1; - } - - const auto pos = static_cast(_fstream.tellg()); - return pos; - } - - int32_t FileStream::Read(uint8_t* buffer, int32_t bufferLength, int32_t offset, int32_t count){ - if (buffer == nullptr || offset < 0 || count < 0 || bufferLength - offset < count) { - return -1; - } - - if (_closed || _truncated) - return 0; - - auto _buff = reinterpret_cast(buffer); - _fstream.read(_buff + offset, count); - - if (_fstream.rdstate() != std::fstream::goodbit) { - return -1; - } - - return static_cast(_fstream.gcount()); - } - - int32_t FileStream::Read(std::vector& buffer, int32_t offset, int32_t count){ - return Read(buffer.data(), static_cast(buffer.size()), offset, count); - } - - int32_t FileStream::ReadByte(){ - if (_closed || _truncated) - return 0; - - char c = 0; - - _fstream.read(&c, 1); - - if (_fstream.rdstate() != std::fstream::goodbit) { - return -1; - } - - const auto result = static_cast(c); - - return result; - } - - void FileStream::Write(uint8_t const* buffer, int32_t bufferLength, int32_t offset, int32_t count) { - if (buffer == nullptr || offset < 0 || count < 0 || bufferLength - offset < count) { - return; - } - - if (_closed) - return; - - auto _buff = reinterpret_cast(buffer); - - _fstream.write(_buff + offset, count); - - if (_fstream.rdstate() != std::fstream::goodbit) { - return; - } - } - - void FileStream::Write(std::vector const& buffer, int32_t offset, int32_t count) { - Write(buffer.data(), static_cast(buffer.size()), offset, count); - } - - void FileStream::WriteByte(uint8_t value) { - if (_closed) - return; - - const char c = static_cast(value); - - _fstream.write(&c, 1); - - if (_fstream.rdstate() != std::fstream::goodbit) { - return; - } - } -} \ No newline at end of file