From d06c7ebeb630f737584d1a1c711f99b5d4086a27 Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Mon, 10 Jul 2023 18:45:43 -0400 Subject: [PATCH] String buffer --- CMakeLists.txt | 4 ++-- CMakeSettings.json | 0 LICENSE | 0 README.md | 0 design.txt | 0 icon.png | Bin icon_large.png | Bin icon_small.png | Bin include/blt/config.h.in | 0 include/blt/math/averages.h | 0 include/blt/math/log_util.h | 0 include/blt/math/math.h | 0 include/blt/math/matrix.h | 0 include/blt/math/vectors.h | 0 include/blt/nbt/nbt.h | 0 include/blt/nbt/nbt_block.h | 0 include/blt/profiling/profiler.h | 0 include/blt/std/binary_tree.h | 0 include/blt/std/filesystem.h | 0 include/blt/std/format.h | 0 include/blt/std/hash_map.h | 0 include/blt/std/loader.h | 0 include/blt/std/logging.h | 0 include/blt/std/map.h | 0 include/blt/std/memory.h | 0 include/blt/std/queue.h | 0 include/blt/std/random.h | 0 include/blt/std/string.h | 25 +++++++++++++++++++++++++ include/blt/std/system.h | 0 include/blt/std/time.h | 0 include/blt/window/window.h | 0 src/blt/nbt/nbt.cpp | 0 src/blt/nbt/nbt_block.cpp | 0 src/blt/profiling/profiler.cpp | 0 src/blt/std/filesystem.cpp | 0 src/blt/std/format.cpp | 0 src/blt/std/loader.cpp | 0 src/blt/std/logging.cpp | 0 src/blt/std/string.cpp | 29 +++++++++++++++++++++++++++++ src/blt/std/system.cpp | 0 src/blt/window/window.cpp | 0 src/tests/binary_trees.h | 0 src/tests/hashmap_tests.h | 0 src/tests/logging.h | 0 src/tests/main.cpp | 0 src/tests/nbt_tests.h | 0 src/tests/profiling_tests.h | 0 src/tests/queue_tests.h | 0 48 files changed, 56 insertions(+), 2 deletions(-) mode change 100644 => 100755 CMakeLists.txt mode change 100644 => 100755 CMakeSettings.json mode change 100644 => 100755 LICENSE mode change 100644 => 100755 README.md mode change 100644 => 100755 design.txt mode change 100644 => 100755 icon.png mode change 100644 => 100755 icon_large.png mode change 100644 => 100755 icon_small.png mode change 100644 => 100755 include/blt/config.h.in mode change 100644 => 100755 include/blt/math/averages.h mode change 100644 => 100755 include/blt/math/log_util.h mode change 100644 => 100755 include/blt/math/math.h mode change 100644 => 100755 include/blt/math/matrix.h mode change 100644 => 100755 include/blt/math/vectors.h mode change 100644 => 100755 include/blt/nbt/nbt.h mode change 100644 => 100755 include/blt/nbt/nbt_block.h mode change 100644 => 100755 include/blt/profiling/profiler.h mode change 100644 => 100755 include/blt/std/binary_tree.h mode change 100644 => 100755 include/blt/std/filesystem.h mode change 100644 => 100755 include/blt/std/format.h mode change 100644 => 100755 include/blt/std/hash_map.h mode change 100644 => 100755 include/blt/std/loader.h mode change 100644 => 100755 include/blt/std/logging.h mode change 100644 => 100755 include/blt/std/map.h mode change 100644 => 100755 include/blt/std/memory.h mode change 100644 => 100755 include/blt/std/queue.h mode change 100644 => 100755 include/blt/std/random.h mode change 100644 => 100755 include/blt/std/string.h mode change 100644 => 100755 include/blt/std/system.h mode change 100644 => 100755 include/blt/std/time.h mode change 100644 => 100755 include/blt/window/window.h mode change 100644 => 100755 src/blt/nbt/nbt.cpp mode change 100644 => 100755 src/blt/nbt/nbt_block.cpp mode change 100644 => 100755 src/blt/profiling/profiler.cpp mode change 100644 => 100755 src/blt/std/filesystem.cpp mode change 100644 => 100755 src/blt/std/format.cpp mode change 100644 => 100755 src/blt/std/loader.cpp mode change 100644 => 100755 src/blt/std/logging.cpp create mode 100755 src/blt/std/string.cpp mode change 100644 => 100755 src/blt/std/system.cpp mode change 100644 => 100755 src/blt/window/window.cpp mode change 100644 => 100755 src/tests/binary_trees.h mode change 100644 => 100755 src/tests/hashmap_tests.h mode change 100644 => 100755 src/tests/logging.h mode change 100644 => 100755 src/tests/main.cpp mode change 100644 => 100755 src/tests/nbt_tests.h mode change 100644 => 100755 src/tests/profiling_tests.h mode change 100644 => 100755 src/tests/queue_tests.h diff --git a/CMakeLists.txt b/CMakeLists.txt old mode 100644 new mode 100755 index e126a88..04af8bd --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,8 @@ option(BUILD_NBT "Build the BLT NBT + eNBT extension" ON) option(BUILD_TESTS "Build the BLT test set" OFF) option(BLT_ENABLE_LOGGING "Enable blt::logging" ON) +configure_file(include/blt/config.h.in config/blt/config.h @ONLY) + if(${BUILD_STD} OR ${BUILD_PROFILING}) file(GLOB_RECURSE STD_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/blt/std/*.cpp") else() @@ -44,8 +46,6 @@ message("Profiler Files ${PROFILING_FILES}") message("Source: ${CMAKE_SOURCE_DIR}") message("Current Source: ${CMAKE_CURRENT_SOURCE_DIR}") -configure_file(include/blt/config.h.in config/blt/config.h @ONLY) - add_library(BLT ${STD_FILES} ${PROFILING_FILES} ${NBT_FILES}) target_include_directories(BLT PUBLIC include/) diff --git a/CMakeSettings.json b/CMakeSettings.json old mode 100644 new mode 100755 diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/design.txt b/design.txt old mode 100644 new mode 100755 diff --git a/icon.png b/icon.png old mode 100644 new mode 100755 diff --git a/icon_large.png b/icon_large.png old mode 100644 new mode 100755 diff --git a/icon_small.png b/icon_small.png old mode 100644 new mode 100755 diff --git a/include/blt/config.h.in b/include/blt/config.h.in old mode 100644 new mode 100755 diff --git a/include/blt/math/averages.h b/include/blt/math/averages.h old mode 100644 new mode 100755 diff --git a/include/blt/math/log_util.h b/include/blt/math/log_util.h old mode 100644 new mode 100755 diff --git a/include/blt/math/math.h b/include/blt/math/math.h old mode 100644 new mode 100755 diff --git a/include/blt/math/matrix.h b/include/blt/math/matrix.h old mode 100644 new mode 100755 diff --git a/include/blt/math/vectors.h b/include/blt/math/vectors.h old mode 100644 new mode 100755 diff --git a/include/blt/nbt/nbt.h b/include/blt/nbt/nbt.h old mode 100644 new mode 100755 diff --git a/include/blt/nbt/nbt_block.h b/include/blt/nbt/nbt_block.h old mode 100644 new mode 100755 diff --git a/include/blt/profiling/profiler.h b/include/blt/profiling/profiler.h old mode 100644 new mode 100755 diff --git a/include/blt/std/binary_tree.h b/include/blt/std/binary_tree.h old mode 100644 new mode 100755 diff --git a/include/blt/std/filesystem.h b/include/blt/std/filesystem.h old mode 100644 new mode 100755 diff --git a/include/blt/std/format.h b/include/blt/std/format.h old mode 100644 new mode 100755 diff --git a/include/blt/std/hash_map.h b/include/blt/std/hash_map.h old mode 100644 new mode 100755 diff --git a/include/blt/std/loader.h b/include/blt/std/loader.h old mode 100644 new mode 100755 diff --git a/include/blt/std/logging.h b/include/blt/std/logging.h old mode 100644 new mode 100755 diff --git a/include/blt/std/map.h b/include/blt/std/map.h old mode 100644 new mode 100755 diff --git a/include/blt/std/memory.h b/include/blt/std/memory.h old mode 100644 new mode 100755 diff --git a/include/blt/std/queue.h b/include/blt/std/queue.h old mode 100644 new mode 100755 diff --git a/include/blt/std/random.h b/include/blt/std/random.h old mode 100644 new mode 100755 diff --git a/include/blt/std/string.h b/include/blt/std/string.h old mode 100644 new mode 100755 index 69412dc..cea9f6a --- a/include/blt/std/string.h +++ b/include/blt/std/string.h @@ -16,6 +16,30 @@ namespace blt::string { + class StringBuffer { + private: + const size_t BLOCK_SIZE = 4096; + size_t front = 0; + size_t size = 0; + char* characterBuffer = nullptr; + + void expand(); + public: + void trim(); + std::string toString(); + + StringBuffer(){ + characterBuffer = static_cast(malloc(BLOCK_SIZE)); + size = BLOCK_SIZE; + } + + StringBuffer& operator<<(char c); + + ~StringBuffer() { + free(characterBuffer); + } + }; + static inline bool starts_with(const std::string& string, const std::string& search){ if (search.length() > string.length()) return false; @@ -153,6 +177,7 @@ namespace blt::string { trim(s); return s; } + } #endif //BLT_STRING_H diff --git a/include/blt/std/system.h b/include/blt/std/system.h old mode 100644 new mode 100755 diff --git a/include/blt/std/time.h b/include/blt/std/time.h old mode 100644 new mode 100755 diff --git a/include/blt/window/window.h b/include/blt/window/window.h old mode 100644 new mode 100755 diff --git a/src/blt/nbt/nbt.cpp b/src/blt/nbt/nbt.cpp old mode 100644 new mode 100755 diff --git a/src/blt/nbt/nbt_block.cpp b/src/blt/nbt/nbt_block.cpp old mode 100644 new mode 100755 diff --git a/src/blt/profiling/profiler.cpp b/src/blt/profiling/profiler.cpp old mode 100644 new mode 100755 diff --git a/src/blt/std/filesystem.cpp b/src/blt/std/filesystem.cpp old mode 100644 new mode 100755 diff --git a/src/blt/std/format.cpp b/src/blt/std/format.cpp old mode 100644 new mode 100755 diff --git a/src/blt/std/loader.cpp b/src/blt/std/loader.cpp old mode 100644 new mode 100755 diff --git a/src/blt/std/logging.cpp b/src/blt/std/logging.cpp old mode 100644 new mode 100755 diff --git a/src/blt/std/string.cpp b/src/blt/std/string.cpp new file mode 100755 index 0000000..0dba300 --- /dev/null +++ b/src/blt/std/string.cpp @@ -0,0 +1,29 @@ +// +// Created by brett on 7/9/23. +// +#include + +void blt::string::StringBuffer::expand() { + size_t multiplier = size / BLOCK_SIZE; + auto newSize = BLOCK_SIZE * (multiplier * 2); + characterBuffer = static_cast(realloc(characterBuffer, newSize)); + size = newSize; +} + +void blt::string::StringBuffer::trim() { + characterBuffer = static_cast(realloc(characterBuffer, front+1)); + size = front+1; + characterBuffer[front] = '\0'; +} + +blt::string::StringBuffer& blt::string::StringBuffer::operator<<(char c) { + characterBuffer[front++] = c; + if (front > size) + expand(); + return *this; +} + +std::string blt::string::StringBuffer::toString() { + trim(); + return std::string{characterBuffer}; +} diff --git a/src/blt/std/system.cpp b/src/blt/std/system.cpp old mode 100644 new mode 100755 diff --git a/src/blt/window/window.cpp b/src/blt/window/window.cpp old mode 100644 new mode 100755 diff --git a/src/tests/binary_trees.h b/src/tests/binary_trees.h old mode 100644 new mode 100755 diff --git a/src/tests/hashmap_tests.h b/src/tests/hashmap_tests.h old mode 100644 new mode 100755 diff --git a/src/tests/logging.h b/src/tests/logging.h old mode 100644 new mode 100755 diff --git a/src/tests/main.cpp b/src/tests/main.cpp old mode 100644 new mode 100755 diff --git a/src/tests/nbt_tests.h b/src/tests/nbt_tests.h old mode 100644 new mode 100755 diff --git a/src/tests/profiling_tests.h b/src/tests/profiling_tests.h old mode 100644 new mode 100755 diff --git a/src/tests/queue_tests.h b/src/tests/queue_tests.h old mode 100644 new mode 100755