large organizational & cleanup refactor

This commit is contained in:
Noel Berry
2021-05-09 17:23:02 -07:00
parent e65752f30b
commit e615b9d7e4
91 changed files with 3188 additions and 3224 deletions

View File

@ -12,28 +12,28 @@ namespace Blah
BufferStream& operator=(BufferStream&& bs) noexcept;
~BufferStream();
virtual i64 length() const override { return m_length; }
virtual i64 position() const override { return m_position; }
virtual i64 seek(i64 seekTo) override { return m_position = (seekTo < 0 ? 0 : (seekTo > m_length ? m_length : seekTo)); }
virtual size_t length() const override { return m_length; }
virtual size_t position() const override { return m_position; }
virtual size_t seek(size_t seekTo) override { return m_position = (seekTo < 0 ? 0 : (seekTo > m_length ? m_length : seekTo)); }
virtual bool is_open() const override { return m_buffer != nullptr; }
virtual bool is_readable() const override { return true; }
virtual bool is_writable() const override { return true; }
virtual void close() override;
void resize(i64 length);
void resize(size_t length);
void clear() { m_length = m_position = 0; }
char* data() { return m_buffer; }
const char* data() const { return m_buffer; }
protected:
virtual i64 read_into(void* ptr, i64 length) override;
virtual i64 write_from(const void* ptr, i64 length) override;
virtual size_t read_into(void* ptr, size_t length) override;
virtual size_t write_from(const void* ptr, size_t length) override;
private:
char* m_buffer;
i64 m_capacity;
i64 m_length;
i64 m_position;
size_t m_capacity;
size_t m_length;
size_t m_position;
};
}

View File

@ -1,6 +1,6 @@
#pragma once
#include <blah/streams/stream.h>
#include <blah/core/filesystem.h>
#include <blah/filesystem.h>
namespace Blah
{
@ -11,22 +11,21 @@ namespace Blah
FileStream(const FilePath& path, FileMode mode);
FileStream(FileStream&& fs) noexcept;
FileStream& operator=(FileStream&& fs) noexcept;
~FileStream();
i64 length() const override;
i64 position() const override;
i64 seek(i64 seekTo) override;
size_t length() const override;
size_t position() const override;
size_t seek(size_t position) override;
bool is_open() const override;
bool is_readable() const override;
bool is_writable() const override;
void close() override;
protected:
i64 read_into(void* ptr, i64 length) override;
i64 write_from(const void* ptr, i64 length) override;
size_t read_into(void* ptr, size_t length) override;
size_t write_from(const void* ptr, size_t length) override;
private:
FileMode m_mode;
void* m_handle;
FileRef m_file;
};
}

View File

@ -7,14 +7,14 @@ namespace Blah
{
public:
MemoryStream();
MemoryStream(char* data, i64 length);
MemoryStream(char* data, size_t length);
MemoryStream(MemoryStream&& ms) noexcept;
MemoryStream& operator=(MemoryStream&& ms) noexcept;
~MemoryStream() override { m_data = nullptr; m_length = m_position = 0; }
i64 length() const override { return m_length; }
i64 position() const override { return m_position; }
i64 seek(i64 seekTo) override { return m_position = (seekTo < 0 ? 0 : (seekTo > m_length ? m_length : seekTo)); }
size_t length() const override { return m_length; }
size_t position() const override { return m_position; }
size_t seek(size_t seekTo) override { return m_position = (seekTo < 0 ? 0 : (seekTo > m_length ? m_length : seekTo)); }
bool is_open() const override { return m_data != nullptr; }
bool is_readable() const override { return true; }
bool is_writable() const override { return true; }
@ -24,12 +24,12 @@ namespace Blah
const char* data() const { return m_data; }
protected:
i64 read_into(void* ptr, i64 length) override;
i64 write_from(const void* ptr, i64 length) override;
size_t read_into(void* ptr, size_t length) override;
size_t write_from(const void* ptr, size_t length) override;
private:
char* m_data;
i64 m_length;
i64 m_position;
size_t m_length;
size_t m_position;
};
}

View File

@ -1,5 +1,5 @@
#pragma once
#include <blah/core/common.h>
#include <blah/common.h>
#include <blah/containers/str.h>
#include <blah/streams/endian.h>
#include <string.h>
@ -16,13 +16,13 @@ namespace Blah
virtual ~Stream() = default;
// returns the length of the stream
virtual i64 length() const = 0;
virtual size_t length() const = 0;
// returns the position of the stream
virtual i64 position() const = 0;
virtual size_t position() const = 0;
// seeks the position of the stream
virtual i64 seek(i64 seek_to) = 0;
virtual size_t seek(size_t position) = 0;
// returns true of the stream is open
virtual bool is_open() const = 0;
@ -37,10 +37,10 @@ namespace Blah
virtual void close() = 0;
// pipes the contents of this stream to another stream
i64 pipe(Stream& to, i64 length);
size_t pipe(Stream& to, size_t length);
// reads the amount of bytes into the given buffer, and returns the amount read
i64 read(void* buffer, i64 length) { return read_into(buffer, length); }
size_t read(void* buffer, size_t length) { return read_into(buffer, length); }
// reads a string. if length < 0, assumes null-terminated
String read_string(int length = -1);
@ -67,21 +67,21 @@ namespace Blah
}
// writes the amount of bytes to the stream from the given buffer, and returns the amount written
i64 write(const void* buffer, i64 length);
size_t write(const void* buffer, size_t length);
// writes the contents of a string to the stream
i64 write(const String& string);
size_t write(const String& string);
// writes a number
template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
i64 write(const T& value)
size_t write(const T& value)
{
return write<T>(value, Endian::Little);
}
// writes a number
template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
i64 write(const T& value, Endian endian)
size_t write(const T& value, Endian endian)
{
T writing = value;
@ -93,9 +93,9 @@ namespace Blah
protected:
// reads from the stream into the given buffer, and returns the number of bytes read
virtual i64 read_into(void* buffer, i64 length) = 0;
virtual size_t read_into(void* buffer, size_t length) = 0;
// writes from the stream from the given buffer, and returns the number of bytes written
virtual i64 write_from(const void* buffer, i64 length) = 0;
virtual size_t write_from(const void* buffer, size_t length) = 0;
};
}