From 2bb3827a83e60b22bd5b06fe94a077e58f8c771f Mon Sep 17 00:00:00 2001 From: Joshua Ashton Date: Sun, 19 Jun 2022 02:28:57 +0000 Subject: [PATCH] Result + span stuff --- include/Orange/Core/FileSystem.h | 14 +++++++++++--- include/Orange/Core/Result.h | 4 +++- include/Orange/Core/SmallVector.h | 9 +++------ include/Orange/Core/Span.h | 10 ++++++++++ include/Orange/Formats/BSP/Quake2.h | 4 +++- src/Core/meson.build | 0 src/meson.build | 1 + 7 files changed, 31 insertions(+), 11 deletions(-) create mode 100644 src/Core/meson.build diff --git a/include/Orange/Core/FileSystem.h b/include/Orange/Core/FileSystem.h index e26986a..275bc71 100644 --- a/include/Orange/Core/FileSystem.h +++ b/include/Orange/Core/FileSystem.h @@ -1,12 +1,20 @@ #pragma once +#include #include namespace orange::fs { - class File + enum class FileSystemErrorCode : ErrorCodeBaseType { - + Invalid = -1, + Failed = -2, + + Success = 0, }; - //Result + + template + using FileResult = Result; + + FileResult OpenFileIntoBuffer(const char *path); } diff --git a/include/Orange/Core/Result.h b/include/Orange/Core/Result.h index 399db29..4e6fcab 100644 --- a/include/Orange/Core/Result.h +++ b/include/Orange/Core/Result.h @@ -6,7 +6,9 @@ namespace orange { - enum class BasicErrorCode : int32_t + using ErrorCodeBaseType = int32_t; + + enum class BasicErrorCode : ErrorCodeBaseType { Invalid = -1, Failed = -2, diff --git a/include/Orange/Core/SmallVector.h b/include/Orange/Core/SmallVector.h index ad511e3..c2b7304 100644 --- a/include/Orange/Core/SmallVector.h +++ b/include/Orange/Core/SmallVector.h @@ -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; } diff --git a/include/Orange/Core/Span.h b/include/Orange/Core/Span.h index a8334bf..a572388 100644 --- a/include/Orange/Core/Span.h +++ b/include/Orange/Core/Span.h @@ -29,4 +29,14 @@ namespace orange T* data; size_t size; }; + + using BufferView = Span; + using StringView = Span; + + struct Buffer : public BufferView + { + using BufferView::Span; + + ~Buffer() { delete[] data; } + }; } diff --git a/include/Orange/Formats/BSP/Quake2.h b/include/Orange/Formats/BSP/Quake2.h index 0456088..7ef47d2 100644 --- a/include/Orange/Formats/BSP/Quake2.h +++ b/include/Orange/Formats/BSP/Quake2.h @@ -1,13 +1,15 @@ #pragma once #include +#include 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; diff --git a/src/Core/meson.build b/src/Core/meson.build new file mode 100644 index 0000000..e69de29 diff --git a/src/meson.build b/src/meson.build index 9cf7eec..c63ab69 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1 +1,2 @@ +subdir('Core') subdir('Apps') \ No newline at end of file