Result + span stuff

This commit is contained in:
Joshua Ashton 2022-06-19 02:28:57 +00:00
parent 4e86a20238
commit 2bb3827a83
7 changed files with 31 additions and 11 deletions

View File

@ -1,12 +1,20 @@
#pragma once
#include <Orange/Core/Types.h>
#include <Orange/Core/Result.h>
namespace orange::fs
{
class File
enum class FileSystemErrorCode : ErrorCodeBaseType
{
Invalid = -1,
Failed = -2,
Success = 0,
};
//Result<File>
template <typename T>
using FileResult = Result<T, FileSystemErrorCode>;
FileResult<Buffer> OpenFileIntoBuffer(const char *path);
}

View File

@ -6,7 +6,9 @@
namespace orange
{
enum class BasicErrorCode : int32_t
using ErrorCodeBaseType = int32_t;
enum class BasicErrorCode : ErrorCodeBaseType
{
Invalid = -1,
Failed = -2,

View File

@ -24,11 +24,6 @@ namespace orange
delete[] u.m_ptr;
}
size_t Size() const
{
return m_size;
}
void Reserve(size_t n)
{
n = PickCapacity(n);
@ -51,6 +46,8 @@ namespace orange
u.m_ptr = data;
}
size_t Size() const { return m_size; }
const T* Data() const { return Ptr(0); }
T* Data() { return Ptr(0); }
@ -125,7 +122,7 @@ namespace orange
size_t capacity = m_capacity;
while (capacity < n)
capacity *= 2;
capacity = (capacity * 2) + 2;
return capacity;
}

View File

@ -29,4 +29,14 @@ namespace orange
T* data;
size_t size;
};
using BufferView = Span<uint8_t>;
using StringView = Span<char>;
struct Buffer : public BufferView
{
using BufferView::Span;
~Buffer() { delete[] data; }
};
}

View File

@ -1,13 +1,15 @@
#pragma once
#include <Orange/Core/Types.h>
#include <Orange/Core/Span.h>
namespace orange
{
// A minimal span-wrapper for parsing a BSP.
class Quake2BSP
{
public:
Quake2BSP(const void* data, size_t size);
Quake2BSP(BufferView data);
private:
static constexpr uint32_t LumpCount = 19;
static constexpr uint32_t MaxLightmapStyles = 4;

0
src/Core/meson.build Normal file
View File

View File

@ -1 +1,2 @@
subdir('Core')
subdir('Apps')