Change directory structure

This commit is contained in:
jun 2025-03-21 00:22:34 +01:00
parent 275f46226d
commit 7630ecfdcf
17 changed files with 34 additions and 57 deletions

View File

@ -2,11 +2,6 @@ cmake_minimum_required(VERSION 3.12)
set(PROJECT_NAME libguf) set(PROJECT_NAME libguf)
project(${PROJECT_NAME}) 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_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF) set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_C_STANDARD 17) 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) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)
endif () 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) if (NOT DEFINED CMAKE_DEBUG_POSTFIX)
target_include_directories(libguf_example PRIVATE src src/test) set(CMAKE_DEBUG_POSTFIX _dbg)
endif ()
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 MSVC) 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) 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) set(DBG_FLAGS /fsanitize=address)
endif () endif ()
if (NOT DEFINED CMAKE_DEBUG_POSTFIX) 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)
set(CMAKE_DEBUG_POSTFIX _dbg) target_include_directories(libguf_example PRIVATE src src/test)
endif ()
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}) 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) include(CheckIPOSupported)
check_ipo_supported(RESULT ipo_available) check_ipo_supported(RESULT ipo_available)
if (ipo_available AND (CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")) if (ipo_available AND (CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo"))
@ -52,21 +44,13 @@ else()
message(STATUS "LTO disabled") message(STATUS "LTO disabled")
endif() 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} $<$<CONFIG:Debug>: ${DBG_FLAGS}>) target_compile_options(libguf_test PRIVATE ${WARNING_FLAGS_CXX} $<$<CONFIG:Debug>: ${DBG_FLAGS}>)
target_link_options(libguf_test PRIVATE ${WARNING_FLAGS_CXX} $<$<CONFIG:Debug>: ${DBG_FLAGS}> ) target_link_options(libguf_test PRIVATE ${WARNING_FLAGS_CXX} $<$<CONFIG:Debug>: ${DBG_FLAGS}>)
message(STATUS "Configured libguf_test")
message(STATUS "Configured libguf_test")
endif()
if (TARGET libguf_example)
message(STATUS "Configure libguf_example...")
message(STATUS "Configure libguf_example...")
target_compile_options(libguf_example PRIVATE ${WARNING_FLAGS_C} $<$<CONFIG:Debug>: ${DBG_FLAGS}>) target_compile_options(libguf_example PRIVATE ${WARNING_FLAGS_C} $<$<CONFIG:Debug>: ${DBG_FLAGS}>)
target_link_options(libguf_example PRIVATE ${WARNING_FLAGS_C} $<$<CONFIG:Debug>: ${DBG_FLAGS}> ) target_link_options(libguf_example PRIVATE ${WARNING_FLAGS_C} $<$<CONFIG:Debug>: ${DBG_FLAGS}>)
message(STATUS "Configured libguf_example")
message(STATUS "Configured libguf_example")
endif()

View File

@ -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_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_append_cstr(guf_str *str, const char *c_str);
// DONE:
GUF_STR_KWRDS guf_str *guf_str_substr(guf_str* str, size_t pos, size_t count);
// 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_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); 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 guf_str guf_str_new_uninitialised(void);
GUF_STR_KWRDS bool guf_str_is_uninit(const guf_str *str); GUF_STR_KWRDS bool guf_str_is_uninit(const guf_str *str);
#endif #endif
// #define GUF_STR_IMPL_STATIC /* debug */ // #define GUF_STR_IMPL_STATIC /* debug */

View File

@ -48,7 +48,7 @@
#define GUF_RAND_IMPL_STATIC #define GUF_RAND_IMPL_STATIC
#include "guf_rand.h" #include "guf_rand.h"
#include "guf_dict_impl.h" #include "impls/dict_impl.h"
int main(void) int main(void)
{ {

View File

@ -1,4 +1,4 @@
#include "guf_dbuf_impl.h" #include "dbuf_impl.h"
#define GUF_DBUF_NAME dbuf_int #define GUF_DBUF_NAME dbuf_int
#define GUF_T int #define GUF_T int

View File

@ -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 guf_cstr_const
#define GUF_DICT_KEY_T_EQ guf_cstr_const_eq #define GUF_DICT_KEY_T_EQ guf_cstr_const_eq

View File

@ -1,4 +1,4 @@
#include "guf_sort_impl.h" #include "sort_impl.h"
#define GUF_T float #define GUF_T float
#define GUF_SORT_IMPL #define GUF_SORT_IMPL

View File

@ -1,5 +1,5 @@
#ifndef TEST_HPP #ifndef GUF_TEST_HPP
#define TEST_HPP #define GUF_TEST_HPP
#include <stack> #include <stack>
#include <string> #include <string>
@ -14,11 +14,11 @@
struct Test struct Test
{ {
private: private:
std::chrono::steady_clock::time_point time_start, time_end; std::chrono::steady_clock::time_point time_start, time_end;
protected: protected:
std::stack<std::string> check_name_stack; std::stack<std::string> check_name_stack;
std::string full_check_name = ""; std::string full_check_name = "";
@ -49,7 +49,7 @@ struct Test
return cond; return cond;
} }
public: public:
const std::string name {}; const std::string name {};
std::chrono::duration<float, std::milli> runtime_ms {0}; std::chrono::duration<float, std::milli> runtime_ms {0};

View File

@ -5,7 +5,7 @@
extern "C" extern "C"
{ {
#include "guf_alloc_libc.h" #include "guf_alloc_libc.h"
#include "guf_dbuf_impl.h" #include "impls/dbuf_impl.h"
} }
struct DbufIntTest : public Test struct DbufIntTest : public Test

View File

@ -6,16 +6,15 @@
extern "C" extern "C"
{ {
#include "guf_alloc_libc.h" #include "guf_alloc_libc.h"
#include "guf_dict_impl.h"
#include "guf_str.h" #include "guf_str.h"
#include "impls/dict_impl.h"
} }
struct DictSvToIntTest : public Test struct DictSvToIntTest : public Test
{ {
DictSvToIntTest(const std::string& name) : Test(name) {}; DictSvToIntTest(const std::string& name) : Test(name) {};
private: private:
dbuf_char text_buf {}; dbuf_char text_buf {};
std::vector<char> text_vec {}; std::vector<char> text_vec {};
@ -339,8 +338,7 @@ struct DictSvToIntTest : public Test
text_vec.clear(); text_vec.clear();
} }
public: public:
bool run() override bool run() override
{ {
if (done) { if (done) {

View File

@ -1,20 +1,20 @@
#pragma once
#include <vector> #include <vector>
#include "test.hpp" #include "test.hpp"
extern "C" extern "C"
{ {
#include "guf_alloc_libc.h" #include "guf_alloc_libc.h"
#include "guf_dict_impl.h"
#include "guf_dbuf_impl.h"
#include "guf_str.h" #include "guf_str.h"
#include "impls/dict_impl.h"
#include "impls/dbuf_impl.h"
} }
struct UTF8Test : public Test struct UTF8Test : public Test
{ {
UTF8Test(const std::string& name) : Test(name) {}; UTF8Test(const std::string& name) : Test(name) {};
private: private:
dbuf_char text_buf {}; dbuf_char text_buf {};
std::vector<char> text_vec; std::vector<char> text_vec;
@ -162,7 +162,6 @@ struct UTF8Test : public Test
free_text(); free_text();
} }
void encode_decode() void encode_decode()
{ {
guf_utf8_char utf8 = {0}; guf_utf8_char utf8 = {0};
@ -351,7 +350,7 @@ struct UTF8Test : public Test
TEST_CHECK(invalid_chars == 1 && valid_chars == 2); TEST_CHECK(invalid_chars == 1 && valid_chars == 2);
} }
public: public:
bool run() bool run()
{ {