From 7630ecfdcf429bdf8dad9d9a58c89b2c213905a5 Mon Sep 17 00:00:00 2001 From: jun <83899451+zeichensystem@users.noreply.github.com> Date: Fri, 21 Mar 2025 00:22:34 +0100 Subject: [PATCH] Change directory structure --- CMakeLists.txt | 46 ++++++------------- src/guf_str.h | 6 +-- src/test/example.c | 2 +- .../{guf_dbuf_impl.c => impls/dbuf_impl.c} | 2 +- .../{guf_dbuf_impl.h => impls/dbuf_impl.h} | 0 .../{guf_dict_impl.c => impls/dict_impl.c} | 2 +- .../{guf_dict_impl.h => impls/dict_impl.h} | 0 .../{guf_init_impl.c => impls/init_impl.c} | 0 .../linalg_impl.c} | 0 .../{guf_rand_impl.c => impls/rand_impl.c} | 0 .../{guf_sort_impl.c => impls/sort_impl.c} | 2 +- .../{guf_sort_impl.h => impls/sort_impl.h} | 0 src/test/{guf_str_impl.c => impls/str_impl.c} | 0 src/test/test.hpp | 10 ++-- src/test/test_dbuf.hpp | 2 +- src/test/test_dict.hpp | 8 ++-- src/test/test_utf8.hpp | 11 ++--- 17 files changed, 34 insertions(+), 57 deletions(-) rename src/test/{guf_dbuf_impl.c => impls/dbuf_impl.c} (97%) rename src/test/{guf_dbuf_impl.h => impls/dbuf_impl.h} (100%) rename src/test/{guf_dict_impl.c => impls/dict_impl.c} (97%) rename src/test/{guf_dict_impl.h => impls/dict_impl.h} (100%) rename src/test/{guf_init_impl.c => impls/init_impl.c} (100%) rename src/test/{guf_linalg_impl.c => impls/linalg_impl.c} (100%) rename src/test/{guf_rand_impl.c => impls/rand_impl.c} (100%) rename src/test/{guf_sort_impl.c => impls/sort_impl.c} (90%) rename src/test/{guf_sort_impl.h => impls/sort_impl.h} (100%) rename src/test/{guf_str_impl.c => impls/str_impl.c} (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index ffc11f4..9677ebf 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,11 +2,6 @@ cmake_minimum_required(VERSION 3.12) set(PROJECT_NAME libguf) project(${PROJECT_NAME}) -# set(SOURCES src/guf_str.c) -# add_library(${PROJECT_NAME} STATIC ${SOURCES}) -# target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}}/lib/guf) -# target_include_directories(${PROJECT_NAME} PRIVATE src) - set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_C_EXTENSIONS OFF) set(CMAKE_C_STANDARD 17) @@ -18,11 +13,9 @@ if (NOT DEFINED CMAKE_RUNTIME_OUTPUT_DIRECTORY) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin) endif () -add_executable(libguf_example src/test/example.c src/test/guf_str_impl.c src/test/guf_dict_impl.c src/test/guf_linalg_impl.c) -target_include_directories(libguf_example PRIVATE src src/test) - -add_executable(libguf_test src/test/test.cpp src/test/guf_init_impl.c src/test/guf_dbuf_impl.c src/test/guf_str_impl.c src/test/guf_dict_impl.c src/test/guf_rand_impl.c src/test/guf_sort_impl.c src/test/guf_linalg_impl.c) -target_include_directories(libguf_test PRIVATE src src/test) +if (NOT DEFINED CMAKE_DEBUG_POSTFIX) + set(CMAKE_DEBUG_POSTFIX _dbg) +endif () if (NOT DEFINED MSVC) set(WARNING_FLAGS_C -Wall -Wextra -Wpedantic -Wvla -Wshadow -Wundef -Wmisleading-indentation -Wnull-dereference -Wswitch-default -Wconversion -Wno-sign-conversion -Wdouble-promotion -Wno-unused-function) @@ -34,15 +27,14 @@ else () set(DBG_FLAGS /fsanitize=address) endif () -if (NOT DEFINED CMAKE_DEBUG_POSTFIX) - set(CMAKE_DEBUG_POSTFIX _dbg) -endif () +add_executable(libguf_example src/test/example.c src/test/impls/str_impl.c src/test/impls/dict_impl.c src/test/impls/linalg_impl.c) +target_include_directories(libguf_example PRIVATE src src/test) + +add_executable(libguf_test src/test/test.cpp src/test/impls/init_impl.c src/test/impls/dbuf_impl.c src/test/impls/str_impl.c src/test/impls/dict_impl.c src/test/impls/rand_impl.c src/test/impls/sort_impl.c src/test/impls/linalg_impl.c) +target_include_directories(libguf_test PRIVATE src src/test) set_target_properties(libguf_example libguf_test PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}) -target_compile_definitions(libguf_test PUBLIC TEST_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/src/test/data/") - - include(CheckIPOSupported) check_ipo_supported(RESULT ipo_available) if (ipo_available AND (CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")) @@ -52,21 +44,13 @@ else() message(STATUS "LTO disabled") endif() -if (TARGET libguf_test) - message(STATUS "Configure libguf_test...") +message(STATUS "Configure libguf_test...") + target_compile_definitions(libguf_test PUBLIC TEST_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/src/test/data/") target_compile_options(libguf_test PRIVATE ${WARNING_FLAGS_CXX} $<$: ${DBG_FLAGS}>) - target_link_options(libguf_test PRIVATE ${WARNING_FLAGS_CXX} $<$: ${DBG_FLAGS}> ) - - message(STATUS "Configured libguf_test") -endif() - -if (TARGET libguf_example) - message(STATUS "Configure libguf_example...") + target_link_options(libguf_test PRIVATE ${WARNING_FLAGS_CXX} $<$: ${DBG_FLAGS}>) +message(STATUS "Configured libguf_test") +message(STATUS "Configure libguf_example...") target_compile_options(libguf_example PRIVATE ${WARNING_FLAGS_C} $<$: ${DBG_FLAGS}>) - target_link_options(libguf_example PRIVATE ${WARNING_FLAGS_C} $<$: ${DBG_FLAGS}> ) - - message(STATUS "Configured libguf_example") -endif() - - + target_link_options(libguf_example PRIVATE ${WARNING_FLAGS_C} $<$: ${DBG_FLAGS}>) +message(STATUS "Configured libguf_example") diff --git a/src/guf_str.h b/src/guf_str.h index f678ae0..8101f9d 100644 --- a/src/guf_str.h +++ b/src/guf_str.h @@ -109,10 +109,7 @@ GUF_STR_KWRDS guf_str *guf_str_append(guf_str *str, guf_str_view sv); GUF_STR_KWRDS guf_str *guf_str_try_append_cstr(guf_str *str, const char *c_str, guf_err *err); GUF_STR_KWRDS guf_str *guf_str_append_cstr(guf_str *str, const char *c_str); - -GUF_STR_KWRDS guf_str *guf_str_substr(guf_str* str, size_t pos, size_t count); - -// DONE +// DONE: GUF_STR_KWRDS guf_str *guf_str_try_reserve(guf_str *str, ptrdiff_t min_capacity, guf_err *err); GUF_STR_KWRDS guf_str *guf_str_reserve(guf_str *str, ptrdiff_t min_capacity); @@ -144,7 +141,6 @@ GUF_STR_KWRDS bool guf_str_is_valid(const guf_str *str); GUF_STR_KWRDS guf_str guf_str_new_uninitialised(void); GUF_STR_KWRDS bool guf_str_is_uninit(const guf_str *str); - #endif // #define GUF_STR_IMPL_STATIC /* debug */ diff --git a/src/test/example.c b/src/test/example.c index ec187d8..7e948f9 100644 --- a/src/test/example.c +++ b/src/test/example.c @@ -48,7 +48,7 @@ #define GUF_RAND_IMPL_STATIC #include "guf_rand.h" -#include "guf_dict_impl.h" +#include "impls/dict_impl.h" int main(void) { diff --git a/src/test/guf_dbuf_impl.c b/src/test/impls/dbuf_impl.c similarity index 97% rename from src/test/guf_dbuf_impl.c rename to src/test/impls/dbuf_impl.c index 1b565d7..f490d8c 100644 --- a/src/test/guf_dbuf_impl.c +++ b/src/test/impls/dbuf_impl.c @@ -1,4 +1,4 @@ -#include "guf_dbuf_impl.h" +#include "dbuf_impl.h" #define GUF_DBUF_NAME dbuf_int #define GUF_T int diff --git a/src/test/guf_dbuf_impl.h b/src/test/impls/dbuf_impl.h similarity index 100% rename from src/test/guf_dbuf_impl.h rename to src/test/impls/dbuf_impl.h diff --git a/src/test/guf_dict_impl.c b/src/test/impls/dict_impl.c similarity index 97% rename from src/test/guf_dict_impl.c rename to src/test/impls/dict_impl.c index 9d82f57..d45360b 100644 --- a/src/test/guf_dict_impl.c +++ b/src/test/impls/dict_impl.c @@ -1,4 +1,4 @@ -#include "guf_dict_impl.h" +#include "dict_impl.h" #define GUF_DICT_KEY_T guf_cstr_const #define GUF_DICT_KEY_T_EQ guf_cstr_const_eq diff --git a/src/test/guf_dict_impl.h b/src/test/impls/dict_impl.h similarity index 100% rename from src/test/guf_dict_impl.h rename to src/test/impls/dict_impl.h diff --git a/src/test/guf_init_impl.c b/src/test/impls/init_impl.c similarity index 100% rename from src/test/guf_init_impl.c rename to src/test/impls/init_impl.c diff --git a/src/test/guf_linalg_impl.c b/src/test/impls/linalg_impl.c similarity index 100% rename from src/test/guf_linalg_impl.c rename to src/test/impls/linalg_impl.c diff --git a/src/test/guf_rand_impl.c b/src/test/impls/rand_impl.c similarity index 100% rename from src/test/guf_rand_impl.c rename to src/test/impls/rand_impl.c diff --git a/src/test/guf_sort_impl.c b/src/test/impls/sort_impl.c similarity index 90% rename from src/test/guf_sort_impl.c rename to src/test/impls/sort_impl.c index 3cef8cc..778a00a 100644 --- a/src/test/guf_sort_impl.c +++ b/src/test/impls/sort_impl.c @@ -1,4 +1,4 @@ -#include "guf_sort_impl.h" +#include "sort_impl.h" #define GUF_T float #define GUF_SORT_IMPL diff --git a/src/test/guf_sort_impl.h b/src/test/impls/sort_impl.h similarity index 100% rename from src/test/guf_sort_impl.h rename to src/test/impls/sort_impl.h diff --git a/src/test/guf_str_impl.c b/src/test/impls/str_impl.c similarity index 100% rename from src/test/guf_str_impl.c rename to src/test/impls/str_impl.c diff --git a/src/test/test.hpp b/src/test/test.hpp index a5f8b52..c4528c5 100644 --- a/src/test/test.hpp +++ b/src/test/test.hpp @@ -1,5 +1,5 @@ -#ifndef TEST_HPP -#define TEST_HPP +#ifndef GUF_TEST_HPP +#define GUF_TEST_HPP #include #include @@ -14,11 +14,11 @@ struct Test { - private: +private: std::chrono::steady_clock::time_point time_start, time_end; - protected: +protected: std::stack check_name_stack; std::string full_check_name = ""; @@ -49,7 +49,7 @@ struct Test return cond; } - public: +public: const std::string name {}; std::chrono::duration runtime_ms {0}; diff --git a/src/test/test_dbuf.hpp b/src/test/test_dbuf.hpp index d35d99a..14432da 100644 --- a/src/test/test_dbuf.hpp +++ b/src/test/test_dbuf.hpp @@ -5,7 +5,7 @@ extern "C" { #include "guf_alloc_libc.h" - #include "guf_dbuf_impl.h" + #include "impls/dbuf_impl.h" } struct DbufIntTest : public Test diff --git a/src/test/test_dict.hpp b/src/test/test_dict.hpp index 33d524c..b40446a 100644 --- a/src/test/test_dict.hpp +++ b/src/test/test_dict.hpp @@ -6,16 +6,15 @@ extern "C" { #include "guf_alloc_libc.h" - #include "guf_dict_impl.h" #include "guf_str.h" + #include "impls/dict_impl.h" } struct DictSvToIntTest : public Test { DictSvToIntTest(const std::string& name) : Test(name) {}; - private: - +private: dbuf_char text_buf {}; std::vector text_vec {}; @@ -339,8 +338,7 @@ struct DictSvToIntTest : public Test text_vec.clear(); } - public: - +public: bool run() override { if (done) { diff --git a/src/test/test_utf8.hpp b/src/test/test_utf8.hpp index 0ffbf45..40d3c4a 100644 --- a/src/test/test_utf8.hpp +++ b/src/test/test_utf8.hpp @@ -1,20 +1,20 @@ +#pragma once #include #include "test.hpp" extern "C" { #include "guf_alloc_libc.h" - #include "guf_dict_impl.h" - #include "guf_dbuf_impl.h" #include "guf_str.h" + #include "impls/dict_impl.h" + #include "impls/dbuf_impl.h" } struct UTF8Test : public Test { - UTF8Test(const std::string& name) : Test(name) {}; - private: +private: dbuf_char text_buf {}; std::vector text_vec; @@ -162,7 +162,6 @@ struct UTF8Test : public Test free_text(); } - void encode_decode() { guf_utf8_char utf8 = {0}; @@ -351,7 +350,7 @@ struct UTF8Test : public Test TEST_CHECK(invalid_chars == 1 && valid_chars == 2); } - public: +public: bool run() {