replaced log.h with common.h, added easier shorthand for int types

This commit is contained in:
Noel Berry
2021-03-20 17:33:04 -07:00
parent 9f9ed08007
commit d73241e8fe
58 changed files with 416 additions and 408 deletions

View File

@ -12,9 +12,9 @@ namespace Blah
BufferStream& operator=(BufferStream&& bs) noexcept;
~BufferStream();
virtual int64_t length() const override { return m_length; }
virtual int64_t position() const override { return m_position; }
virtual int64_t seek(int64_t seekTo) override { return m_position = (seekTo < 0 ? 0 : (seekTo > m_length ? m_length : seekTo)); }
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 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; }
@ -25,13 +25,13 @@ namespace Blah
const char* data() const { return m_buffer; }
protected:
virtual int64_t read_into(void* ptr, int64_t length) override;
virtual int64_t write_from(const void* ptr, int64_t length) override;
virtual i64 read_into(void* ptr, i64 length) override;
virtual i64 write_from(const void* ptr, i64 length) override;
private:
char* m_buffer;
int64_t m_capacity;
int64_t m_length;
int64_t m_position;
i64 m_capacity;
i64 m_length;
i64 m_position;
};
}

View File

@ -13,17 +13,17 @@ namespace Blah
FileStream& operator=(FileStream&& fs) noexcept;
~FileStream();
virtual int64_t length() const override;
virtual int64_t position() const override;
virtual int64_t seek(int64_t seekTo) override;
virtual i64 length() const override;
virtual i64 position() const override;
virtual i64 seek(i64 seekTo) override;
virtual bool is_open() const override { return m_handle != nullptr; }
virtual bool is_readable() const override { return m_handle != nullptr && (m_mode == FileMode::ReadWrite || m_mode == FileMode::Read); }
virtual bool is_writable() const override { return m_handle != nullptr && (m_mode == FileMode::ReadWrite || m_mode == FileMode::Write); }
virtual void close() override;
protected:
virtual int64_t read_into(void* ptr, int64_t length) override;
virtual int64_t write_from(const void* ptr, int64_t length) override;
virtual i64 read_into(void* ptr, i64 length) override;
virtual i64 write_from(const void* ptr, i64 length) override;
private:
FileMode m_mode;

View File

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

View File

@ -1,5 +1,5 @@
#pragma once
#include <inttypes.h>
#include <blah/core/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 int64_t length() const = 0;
virtual i64 length() const = 0;
// returns the position of the stream
virtual int64_t position() const = 0;
virtual i64 position() const = 0;
// seeks the position of the stream
virtual int64_t seek(int64_t seek_to) = 0;
virtual i64 seek(i64 seek_to) = 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 tream to another stream
int64_t pipe(Stream& to, int64_t length);
i64 pipe(Stream& to, i64 length);
// reads the amount of bytes into the given buffer, and returns the amount read
int64_t read(void* buffer, int64_t length) { return read_into(buffer, length); }
i64 read(void* buffer, i64 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
int64_t write(const void* buffer, int64_t length);
i64 write(const void* buffer, i64 length);
// writes the contents of a string to the stream
int64_t write(const String& string);
i64 write(const String& string);
// writes a number
template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
int64_t write(const T& value)
i64 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>
int64_t write(const T& value, Endian endian)
i64 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 int64_t read_into(void* buffer, int64_t length) = 0;
virtual i64 read_into(void* buffer, i64 length) = 0;
// writes from the stream from the given buffer, and returns the number of bytes written
virtual int64_t write_from(const void* buffer, int64_t length) = 0;
virtual i64 write_from(const void* buffer, i64 length) = 0;
};
}