diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index 29d34be..d38d3f7 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -12,12 +12,25 @@ add_module( hash.cppm utils.cppm scope.cppm - bitwise.cppm + chrono.cppm thread.cppm + bitwise.cppm + concepts.cppm + algorithm.cppm + filesystem.cppm primitives.cppm + exceptions.cppm src_location.cppm + math/algebra.cppm + math/trig.cppm + math/vec2.cppm + math/vec3.cppm + math/vec4.cppm + math/mat4.cppm ) + add_module(NAME logger INTERFACES logger.cppm DEPENDENCIES lsd) + add_module( NAME test @@ -31,10 +44,9 @@ add_module( lsd logger ) -return() -add_module(NAME env INTERFACES constants.cppm) -add_module(NAME memory INTERFACES null_on_move.cppm reference.cppm scope.cppm) -add_module(NAME time INTERFACES timer.cppm) +add_module(NAME env INTERFACES constants.cppm DEPENDENCIES lsd) +# add_module(NAME memory INTERFACES reference.cppm scope.cppm) +add_module(NAME time INTERFACES timer.cppm DEPENDENCIES lsd) add_module( NAME @@ -42,23 +54,10 @@ add_module( ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/debug INTERFACES - instrumentor.cppm assertions.cppm DEPENDENCIES logger -) - -add_module( - NAME - math - INTERFACES - algebra.cppm - mat4.cppm - trig.cppm - vec2.cppm - vec3.cppm - vec4.cppm - components.cppm + lsd ) add_module( @@ -80,6 +79,7 @@ add_module( INTERFACES bakers.cppm DEPENDENCIES + lsd assets logger lt_debug @@ -88,7 +88,15 @@ add_module( # add_executable(asset_baker entrypoint.cpp) target_link_libraries(asset_baker # PRIVATE libasset_baker) -add_module(NAME camera INTERFACES components.cppm DEPENDENCIES math) +add_module( + NAME + camera + INTERFACES + components.cppm + DEPENDENCIES + math + lsd +) add_module( NAME @@ -96,10 +104,9 @@ add_module( INTERFACES application.cppm system.cppm - DEPENDENCIES - memory PRIVATE_DEPENDENCIES lt_debug + lsd ) add_module( @@ -112,9 +119,11 @@ add_module( DEPENDENCIES logger lt_debug - memory + lsd ) +return() + if(WIN32) add_module( NAME diff --git a/modules/app/application.cppm b/modules/app/application.cppm index 5c3cfaa..3308635 100644 --- a/modules/app/application.cppm +++ b/modules/app/application.cppm @@ -1,8 +1,6 @@ export module app; import app.system; -import memory.reference; -import memory.scope; -import std; +import lsd; namespace lt::app { @@ -25,19 +23,19 @@ public: void game_loop(); - void register_system(memory::Ref system); + void register_system(lsd::ref system); - void unregister_system(memory::Ref system); + void unregister_system(lsd::ref system); protected: Application() = default; private: - std::vector> m_systems; + lsd::vec> m_systems; - std::vector> m_systems_to_be_unregistered; + lsd::vec> m_systems_to_be_unregistered; - std::vector> m_systems_to_be_registered; + lsd::vec> m_systems_to_be_registered; }; } // namespace lt::app @@ -52,11 +50,11 @@ void Application::game_loop() for (auto &system : m_systems) { const auto &last_tick = system->get_last_tick_result(); - const auto now = std::chrono::steady_clock::now(); + const auto now = lsd::chrono::steady_clock::now(); system->tick(TickInfo { .delta_time = now - last_tick.end_time, - .budget = std::chrono::milliseconds { 10 }, + .budget = lsd::chrono::milliseconds { 10 }, .start_time = now, }); } @@ -69,7 +67,7 @@ void Application::game_loop() for (auto &system : m_systems_to_be_unregistered) { m_systems.erase( - std::remove(m_systems.begin(), m_systems.end(), system), + lsd::remove(m_systems.begin(), m_systems.end(), system), m_systems.end() ); } @@ -81,14 +79,14 @@ void Application::game_loop() } } -void Application::register_system(memory::Ref system) +void Application::register_system(lsd::ref system) { - m_systems.emplace_back(std::move(system)); + m_systems.emplace_back(lsd::move(system)); } -void Application::unregister_system(memory::Ref system) +void Application::unregister_system(lsd::ref system) { - m_systems_to_be_unregistered.emplace_back(std::move(system)); + m_systems_to_be_unregistered.emplace_back(lsd::move(system)); } } // namespace lt::app diff --git a/modules/app/system.cppm b/modules/app/system.cppm index f0a731e..d066f9c 100644 --- a/modules/app/system.cppm +++ b/modules/app/system.cppm @@ -1,6 +1,6 @@ export module app.system; import logger; -import std; +import lsd; namespace lt::app { @@ -9,9 +9,9 @@ namespace lt::app { */ export struct TickInfo { - using Timepoint_T = std::chrono::time_point; + using Timepoint_T = lsd::chrono::time_point; - using Duration_T = std::chrono::duration; + using Duration_T = lsd::chrono::duration; /** Duration since previous tick's end_time to current tick's start_time. */ Duration_T delta_time {}; @@ -32,9 +32,9 @@ export struct TickInfo /** Information about how a system's tick performed */ export struct TickResult { - using Timepoint_T = std::chrono::time_point; + using Timepoint_T = lsd::chrono::time_point; - using Duration_T = std::chrono::duration; + using Duration_T = lsd::chrono::duration; /** The info supplied to the system for ticking. */ TickInfo info; @@ -48,7 +48,7 @@ export struct TickResult export struct SystemDiagnosis { - enum class Severity : std::uint8_t + enum class Severity : u8 { verbose, info, @@ -57,9 +57,9 @@ export struct SystemDiagnosis fatal, }; - std::string message; + lsd::str message; - std::string code; + lsd::str code; Severity severity; }; @@ -69,9 +69,9 @@ export class SystemStats public: void push_diagnosis(SystemDiagnosis &&diagnosis) { - auto &diag = m_diagnosis.emplace_back(std::move(diagnosis)); + auto &diag = m_diagnosis.emplace_back(lsd::move(diagnosis)); - log::info("message: {}", std::string { diag.message }); + log::info("message: {}", lsd::str { diag.message }); } [[nodiscard]] auto empty_diagnosis() const -> bool @@ -80,7 +80,7 @@ public: } private: - std::vector m_diagnosis; + lsd::vec m_diagnosis; }; export class ISystem diff --git a/modules/asset_baker/bakers.cppm b/modules/asset_baker/bakers.cppm index 522ce59..0bfc7d3 100644 --- a/modules/asset_baker/bakers.cppm +++ b/modules/asset_baker/bakers.cppm @@ -1,32 +1,33 @@ export module bakers; - import debug.assertions; import assets.metadata; import assets.shader; import logger; -import std; +import lsd; + +namespace lt { export void bake_shader( - const std::filesystem::path &in_path, - const std::filesystem::path &out_path, - lt::assets::ShaderAsset::Type type + const lsd::file::path &in_path, + const lsd::file::path &out_path, + assets::ShaderAsset::Type type ) { - using lt::assets::ShaderAsset; - using enum lt::assets::ShaderAsset::Type; + using assets::ShaderAsset; + using enum assets::ShaderAsset::Type; - auto glsl_path = std::string { in_path.string() }; - auto spv_path = std::format("{}.spv", glsl_path); - lt::log::trace( + auto glsl_path = lsd::str { in_path.string() }; + auto spv_path = lsd::format("{}.spv", glsl_path); + log::trace( "Compiling {} shader {} -> {}", type == vertex ? "vertex" : "fragment", - std::string { glsl_path }, - std::string { spv_path } + lsd::str { glsl_path }, + lsd::str { spv_path } ); // Don't bother linking to shaderc, just invoke the command with a system call. // NOLINTNEXTLINE(concurrency-mt-unsafe) - std::system(std::format( + lsd::system(lsd::format( "glslc --target-env=vulkan1.4 -std=450core -fshader-stage={} {} -o {}", type == vertex ? "vert" : "frag", glsl_path, @@ -34,33 +35,35 @@ export void bake_shader( ) .c_str()); - auto stream = std::ifstream(spv_path, std::ios::binary); - lt::debug::ensure( + auto stream = lsd::file::in_stream(spv_path, lsd::file::ios_binary); + debug::ensure( stream.is_open(), "Failed to open compiled {} shader at: {}", type == vertex ? "vert" : "frag", spv_path ); - stream.seekg(0, std::ios::end); + stream.seekg(0, lsd::file::ios_end); const auto size = stream.tellg(); - auto bytes = std::vector(size); - stream.seekg(0, std::ios::beg); + auto bytes = lsd::vec(size); + stream.seekg(0, lsd::file::ios_beg); stream.read((char *)bytes.data(), size); // NOLINT - lt::log::debug("BYTES: {}", bytes.size()); + log::debug("BYTES: {}", bytes.size()); stream.close(); - std::filesystem::remove(spv_path); + lsd::file::remove(spv_path); ShaderAsset::pack( out_path, - lt::assets::AssetMetadata { - .version = lt::assets::current_version, + assets::AssetMetadata { + .version = assets::current_version, .type = ShaderAsset::asset_type_identifier, }, ShaderAsset::Metadata { .type = type, }, - std::move(bytes) + lsd::move(bytes) ); } + +} // namespace lt diff --git a/modules/assets/shader.cppm b/modules/assets/shader.cppm index 48c4a0b..5cd038f 100644 --- a/modules/assets/shader.cppm +++ b/modules/assets/shader.cppm @@ -2,7 +2,7 @@ export module assets.shader; import assets.metadata; import debug.assertions; -import std; +import lsd; export namespace lt::assets { @@ -16,7 +16,7 @@ public: code, }; - enum class Type : std::uint8_t + enum class Type : u8 { vertex, fragment, @@ -30,15 +30,15 @@ public: }; static void pack( - const std::filesystem::path &destination, + const lsd::file::path &destination, AssetMetadata asset_metadata, Metadata metadata, Blob code_blob ); - ShaderAsset(const std::filesystem::path &path); + ShaderAsset(const lsd::file::path &path); - void unpack_to(BlobTag tag, std::span destination) const; + void unpack_to(BlobTag tag, lsd::span destination) const; [[nodiscard]] auto unpack(BlobTag tag) const -> Blob; @@ -57,7 +57,7 @@ public: debug::ensure( tag == BlobTag::code, "Invalid blob tag for shader asset: {}", - std::to_underlying(tag) + lsd::to_underlying(tag) ); return m_code_blob_metadata; @@ -88,15 +88,15 @@ constexpr auto total_metadata_size = // + sizeof(BlobMetadata::compressed_size) // + sizeof(BlobMetadata::uncompressed_size); -ShaderAsset::ShaderAsset(const std::filesystem::path &path): m_stream(path) +ShaderAsset::ShaderAsset(const lsd::file::path &path): m_stream(path) { debug::ensure(m_stream.is_open(), "Failed to open shader asset at: {}", path.string()); const auto read = [this](auto &field) { - m_stream.read(std::bit_cast(&field), sizeof(field)); + m_stream.read(bit_cast(&field), sizeof(field)); }; m_stream.seekg(0, std::ifstream::end); - const auto file_size = static_cast(m_stream.tellg()); + const auto file_size = static_cast(m_stream.tellg()); debug::ensure( file_size > total_metadata_size, "Failed to open shader asset at: {}, file smaller than metadata: {} < {}", @@ -132,14 +132,14 @@ ShaderAsset::ShaderAsset(const std::filesystem::path &path): m_stream(path) ); debug::ensure( - std::to_underlying(m_metadata.type) <= std::to_underlying(Type::compute), + lsd::to_underlying(m_metadata.type) <= std::to_underlying(Type::compute), "Failed to open shader asset at: {}, invalid shader type: {}", path.string(), - std::to_underlying(m_metadata.type) + lsd::to_underlying(m_metadata.type) ); debug::ensure( - m_code_blob_metadata.tag == std::to_underlying(BlobTag::code), + m_code_blob_metadata.tag == lsd::to_underlying(BlobTag::code), "Failed to open shader asset at: {}, invalid blob tag: {}", path.string(), m_code_blob_metadata.tag @@ -156,7 +156,7 @@ ShaderAsset::ShaderAsset(const std::filesystem::path &path): m_stream(path) } /* static */ void ShaderAsset::pack( - const std::filesystem::path &destination, + const lsd::file::path &destination, AssetMetadata asset_metadata, Metadata metadata, Blob code_blob @@ -168,7 +168,7 @@ ShaderAsset::ShaderAsset(const std::filesystem::path &path): m_stream(path) }; const auto code_blob_metadata = BlobMetadata { - .tag = std::to_underlying(BlobTag::code), + .tag = lsd::to_underlying(BlobTag::code), .offset = total_metadata_size, .compression_type = CompressionType::none, .compressed_size = code_blob.size(), @@ -177,7 +177,7 @@ ShaderAsset::ShaderAsset(const std::filesystem::path &path): m_stream(path) debug::ensure(stream.is_open(), "Failed to pack shader asset to {}", destination.string()); const auto write = [&stream](auto &field) { - stream.write(std::bit_cast(&field), sizeof(field)); + stream.write(bit_cast(&field), sizeof(field)); }; write(asset_metadata.type); write(asset_metadata.version); @@ -187,31 +187,31 @@ ShaderAsset::ShaderAsset(const std::filesystem::path &path): m_stream(path) write(code_blob_metadata.compression_type); write(code_blob_metadata.compressed_size); write(code_blob_metadata.uncompressed_size); - stream.write(std::bit_cast(code_blob.data()), static_cast(code_blob.size())); + stream.write(bit_cast(code_blob.data()), static_cast(code_blob.size())); } -void ShaderAsset::unpack_to(BlobTag tag, std::span destination) const +void ShaderAsset::unpack_to(BlobTag tag, lsd::span destination) const { debug::ensure( tag == BlobTag::code, "Invalid blob tag for shader asset: {}", - std::to_underlying(tag) + lsd::to_underlying(tag) ); debug::ensure( destination.size() >= m_code_blob_metadata.uncompressed_size, "Failed to unpack shader blob {} to destination ({}) of size {} since it's smaller " "than the blobl's uncompressed size: {}", - std::to_underlying(tag), - std::bit_cast(destination.data()), + lsd::to_underlying(tag), + bit_cast(destination.data()), destination.size(), m_code_blob_metadata.uncompressed_size ); - m_stream.seekg(static_cast(m_code_blob_metadata.offset)); + m_stream.seekg(static_cast(m_code_blob_metadata.offset)); m_stream.read( - std::bit_cast(destination.data()), - static_cast(m_code_blob_metadata.uncompressed_size) + bit_cast(destination.data()), + static_cast(m_code_blob_metadata.uncompressed_size) ); } @@ -220,7 +220,7 @@ void ShaderAsset::unpack_to(BlobTag tag, std::span destination) const debug::ensure( tag == BlobTag::code, "Invalid blob tag for shader asset: {}", - std::to_underlying(tag) + lsd::to_underlying(tag) ); auto blob = Blob(m_code_blob_metadata.uncompressed_size); diff --git a/modules/camera/components.cppm b/modules/camera/components.cppm index 883813b..fab5dbb 100644 --- a/modules/camera/components.cppm +++ b/modules/camera/components.cppm @@ -1,19 +1,19 @@ export module camera.components; -import math.vec4; +import lsd; -namespace lt::camera::components { +export namespace lt::camera::components { -export struct PerspectiveCamera +struct PerspectiveCamera { - float vertical_fov {}; + f32 vertical_fov {}; - float near_plane {}; + f32 near_plane {}; - float far_plane {}; + f32 far_plane {}; - float aspect_ratio {}; + f32 aspect_ratio {}; - math::vec4 background_color; + lsd::vec4 background_color; bool is_primary {}; }; diff --git a/modules/debug/assertions.cppm b/modules/debug/assertions.cppm index 1666d10..f3d4bb6 100644 --- a/modules/debug/assertions.cppm +++ b/modules/debug/assertions.cppm @@ -1,43 +1,36 @@ export module debug.assertions; -import std; +import lsd; -namespace lt::debug { +export namespace lt::debug { -/////////////////////////////////////// -// ----------* INTERFACE *--------- // -///////////////////////////////////// -export template +template struct ensure { ensure( const Expression_T &expression, - std::format_string fmt, + lsd::format_str fmt, Args_T &&...args, - const std::source_location &location = std::source_location::current() + const lsd::src_location &location = lsd::src_location::current() ); }; -export template -ensure(Expression_T, std::format_string, Args_T &&...) - -> ensure; +template +ensure(Expression_T, lsd::format_str, Args_T &&...) -> ensure; -/////////////////////////////////////// -// * IMPLEMENTATION -- TEMPLATES * // -///////////////////////////////////// template ensure::ensure( const Expression_T &expression, - std::format_string fmt, + lsd::format_str fmt, Args_T &&...args, - const std::source_location &location + const lsd::src_location &location ) { if (!static_cast(expression)) { - throw std::runtime_error { std::format( + throw lsd::runtime_error { lsd::format( "exception: {}\nlocation: {}:{}", - std::format(fmt, std::forward(args)...), + lsd::format(fmt, lsd::forward(args)...), location.file_name(), location.line() ) }; diff --git a/modules/debug/instrumentor.cppm b/modules/debug/instrumentor.cppm deleted file mode 100644 index 8978a58..0000000 --- a/modules/debug/instrumentor.cppm +++ /dev/null @@ -1,146 +0,0 @@ -export module debug.instrumentor; - -import std; -import logger; - -namespace lt::debug { - -struct ScopeProfileResult -{ - std::string name; - long long start, duration; - std::uint32_t threadID; -}; - -class Instrumentor -{ -public: - static auto instance() -> Instrumentor & - { - static auto instance = Instrumentor {}; - return instance; - } - - static void begin_session(const std::string &outputPath) - { - instance().begin_session_impl(outputPath); - } - static void end_session() - { - instance().end_session_impl(); - } - - static void submit_scope_profile(const ScopeProfileResult &profileResult) - { - instance().submit_scope_profile_impl(profileResult); - } - -private: - std::ofstream m_output_file_stream; - - unsigned int m_current_session_count { 0u }; - - Instrumentor() = default; - - void begin_session_impl(const std::string &outputPath); - - void end_session_impl(); - - void submit_scope_profile_impl(const ScopeProfileResult &profileResult); -}; - -class InstrumentorTimer -{ -public: - InstrumentorTimer(const std::string &scopeName); - - ~InstrumentorTimer(); - -private: - ScopeProfileResult m_result; - - std::chrono::time_point m_start; -}; - -} // namespace lt::debug - -/* scope */ -#define lt_profile_scope(name) lt_profile_scope_no_redifinition(name, __LINE__) -#define lt_profile_scope_no_redifinition(name, line) lt_profile_scope_no_redifinition2(name, line) -#define lt_profile_scope_no_redifinition2(name, line) InstrumentorTimer timer##line(name) - -/* function */ -#define LT_PROFILE_FUNCTION lt_profile_scope(__FUNCSIG__) - -/* session */ -#define lt_profile_begin_session(outputPath) ::lt::Instrumentor::begin_session(outputPath) -#define lt_profile_end_session() ::lt::Instrumentor::end_session() - -module :private; -namespace lt::debug { - -void Instrumentor::begin_session_impl(const std::string &outputPath) -{ - std::filesystem::create_directory(outputPath.substr(0, outputPath.find_last_of('/') + 1)); - - m_output_file_stream.open(outputPath); - m_output_file_stream << "{\"traceEvents\":["; -} - -void Instrumentor::end_session_impl() -{ - if (m_current_session_count == 0u) - { - log::warn("0 profiling for the ended session"); - } - - m_current_session_count = 0u; - - m_output_file_stream << "]}"; - m_output_file_stream.flush(); - m_output_file_stream.close(); -} - -void Instrumentor::submit_scope_profile_impl(const ScopeProfileResult &profileResult) -{ - if (m_current_session_count++ == 0u) - { - m_output_file_stream << "{"; - } - else - { - m_output_file_stream << ",{"; - } - - m_output_file_stream << R"("name":")" << profileResult.name << "\","; - m_output_file_stream << R"("cat": "scope",)"; - m_output_file_stream << R"("ph": "X",)"; - m_output_file_stream << "\"ts\":" << profileResult.start << ","; - m_output_file_stream << "\"dur\":" << profileResult.duration << ","; - m_output_file_stream << "\"pid\":0,"; - m_output_file_stream << "\"tid\":" << profileResult.threadID << ""; - m_output_file_stream << "}"; -} - -InstrumentorTimer::InstrumentorTimer(const std::string &scopeName) - : m_result({ .name = scopeName, .start = 0, .duration = 0, .threadID = 0 }) - , m_start(std::chrono::steady_clock::now()) -{ -} - -InstrumentorTimer::~InstrumentorTimer() -{ - auto end = std::chrono::steady_clock::now(); - - m_result.start = std::chrono::time_point_cast(m_start) - .time_since_epoch() - .count(); - - m_result.duration = std::chrono::time_point_cast(end) - .time_since_epoch() - .count() - - m_result.start; - - Instrumentor::submit_scope_profile(m_result); -} -} // namespace lt::debug diff --git a/modules/ecs/sparse_set.cppm b/modules/ecs/sparse_set.cppm index 340a760..511b85a 100644 --- a/modules/ecs/sparse_set.cppm +++ b/modules/ecs/sparse_set.cppm @@ -1,13 +1,13 @@ export module ecs.sparse_set; import debug.assertions; -import std; +import lsd; -namespace lt::ecs { +export namespace lt::ecs { /** * @ref https://programmingpraxis.com/2012/03/09/sparse-sets/ */ -export template +template class TypeErasedSparseSet { public: @@ -26,17 +26,17 @@ public: virtual void remove(Identifier_T identifier) = 0; }; -export template +template class SparseSet: public TypeErasedSparseSet { public: using Dense_T = std::pair; - static constexpr auto max_capacity = std::size_t { 1'000'000 }; + static constexpr auto max_capacity = size_t { 1'000'000 }; - static constexpr auto null_identifier = std::numeric_limits().max(); + static constexpr auto null_identifier = lsd::numeric_limits().max(); - explicit SparseSet(std::size_t initial_capacity = 1) + explicit SparseSet(size_t initial_capacity = 1) { debug::ensure( initial_capacity <= max_capacity, @@ -53,10 +53,7 @@ public: { if (m_sparse.size() < identifier + 1) { - auto new_capacity = std::max( - static_cast(identifier + 1), - m_sparse.size() * 2 - ); + auto new_capacity = std::max(static_cast(identifier + 1), m_sparse.size() * 2); new_capacity = std::min(new_capacity, max_capacity); // log::debug("Increasing sparse vector size:", m_dead_count); @@ -122,12 +119,12 @@ public: && m_dense[m_sparse[identifier]].first == identifier; } - auto begin() -> std::vector::iterator + auto begin() -> lsd::vector::iterator { return m_dense.begin(); } - auto end() -> std::vector::iterator + auto end() -> lsd::vector::iterator { return m_dense.end(); } @@ -146,15 +143,15 @@ public: [[nodiscard]] auto &&operator[](this auto &&self, Identifier_T identifier) { using Self_T = decltype(self); - return std::forward(self).m_dense[std::forward(self).m_sparse[identifier]]; + return lsd::forward(self).m_dense[lsd::forward(self).m_sparse[identifier]]; } - [[nodiscard]] auto get_size() const noexcept -> std::size_t + [[nodiscard]] auto get_size() const noexcept -> size_t { return m_alive_count; } - [[nodiscard]] auto get_capacity() const noexcept -> std::size_t + [[nodiscard]] auto get_capacity() const noexcept -> size_t { return m_sparse.capacity(); } @@ -165,13 +162,13 @@ public: } private: - std::vector m_dense; + lsd::vector m_dense; - std::vector m_sparse; + lsd::vector m_sparse; - std::size_t m_alive_count {}; + size_t m_alive_count {}; - std::size_t m_dead_count {}; + size_t m_dead_count {}; }; } // namespace lt::ecs diff --git a/modules/env/constants.cppm b/modules/env/constants.cppm index 8c1b40f..a13022d 100644 --- a/modules/env/constants.cppm +++ b/modules/env/constants.cppm @@ -1,10 +1,9 @@ export module env; +import lsd; -import std; +export namespace lt { -namespace lt { - -enum class Platform : std::uint8_t +enum class Platform : u8 { /** The GNU/Linux platform. * Tested on the following distros: arch-x86_64 @@ -26,7 +25,7 @@ enum class Platform : std::uint8_t }; /** The compiler that was used for compiling the project. */ -enum class Compiler : std::uint8_t +enum class Compiler : u8 { clang, gcc, @@ -36,19 +35,25 @@ enum class Compiler : std::uint8_t namespace constants { +#define lt_windows_only(x) +#define lt_linux_only(x) +#define lt_mac_only(x) + #if defined(LIGHT_PLATFORM_WINDOWS) - #define lt_win(x) + // NOLINTNEXTLINE + #define lt_windows_only(x) x constexpr auto platform = Platform::windows; constexpr auto platform_name = "windows"; - #undef LIGHT_PLATFORM_WINDOWS - #elif defined(LIGHT_PLATFORM_LINUX) + // NOLINTNEXTLINE + #define lt_linux_only(x) x constexpr auto platform = Platform::gnu_linux; constexpr auto platform_name = "gnu_linux"; #elif defined(LIGHT_PLATFORM_MAC) - #define lt_mac(x) x + // NOLINTNEXTLINE + #define lt_mac_only(x) x constexpr auto platform = Platform::mac; constexpr auto platform_name = "mac"; diff --git a/modules/logger/logger.cppm b/modules/logger/logger.cppm index b962d93..eb87e30 100644 --- a/modules/logger/logger.cppm +++ b/modules/logger/logger.cppm @@ -65,7 +65,7 @@ struct [[maybe_unused]] print lsd::unreachable(); }; - const auto path = lsd::filesystem::path { location.file_name() }; + const auto path = lsd::file::path { location.file_name() }; lsd::println( "{} {} ==> {}", diff --git a/modules/lsd/algorithm.cppm b/modules/lsd/algorithm.cppm new file mode 100644 index 0000000..a8e6647 --- /dev/null +++ b/modules/lsd/algorithm.cppm @@ -0,0 +1,9 @@ +export module lsd.algorithm; +import std; + +export namespace lt::lsd { + +using ::std::remove; +using ::std::remove_if; + +} // namespace lt::lsd diff --git a/modules/lsd/chrono.cppm b/modules/lsd/chrono.cppm new file mode 100644 index 0000000..2d17c8f --- /dev/null +++ b/modules/lsd/chrono.cppm @@ -0,0 +1,13 @@ +export module lsd.chrono; +import std; + +export namespace lt::lsd::chrono { + +using std::chrono::duration; +using std::chrono::steady_clock; +using std::chrono::time_point; +using std::chrono::time_point_cast; + +using std::chrono::milliseconds; + +} // namespace lt::lsd::chrono diff --git a/modules/lsd/concepts.cppm b/modules/lsd/concepts.cppm new file mode 100644 index 0000000..ff085f9 --- /dev/null +++ b/modules/lsd/concepts.cppm @@ -0,0 +1,9 @@ +export module lsd.concepts; + +import std; + +export namespace lt::lsd { + +using std::invocable; + +} diff --git a/modules/lsd/exceptions.cppm b/modules/lsd/exceptions.cppm new file mode 100644 index 0000000..7be1dba --- /dev/null +++ b/modules/lsd/exceptions.cppm @@ -0,0 +1,10 @@ +export module lsd.exceptions; + +import std; + +export namespace lt::lsd { + +using std::exception; +using std::runtime_error; + +} // namespace lt::lsd diff --git a/modules/lsd/filesystem.cppm b/modules/lsd/filesystem.cppm new file mode 100644 index 0000000..5f688b9 --- /dev/null +++ b/modules/lsd/filesystem.cppm @@ -0,0 +1,16 @@ +export module lsd.filesystem; +import std; + +export namespace lt::lsd::file { + +using path = ::std::filesystem::path; +using ::std::filesystem::remove; +using in_stream = ::std::ifstream; +using out_stream = ::std::ofstream; + +constexpr auto ios_binary = std::ios::binary; +constexpr auto ios_end = std::ios::end; +constexpr auto ios_beg = std::ios::beg; + + +} // namespace lt::lsd::file diff --git a/modules/lsd/lsd.cppm b/modules/lsd/lsd.cppm index f367c45..f2ec078 100644 --- a/modules/lsd/lsd.cppm +++ b/modules/lsd/lsd.cppm @@ -7,8 +7,21 @@ export import lsd.hash; export import lsd.span; export import lsd.utils; export import lsd.thread; +export import lsd.chrono; export import lsd.ref_ptr; export import lsd.bitwise; +export import lsd.concepts; export import lsd.scope_ptr; +export import lsd.exceptions; export import lsd.primitives; +export import lsd.filesystem; export import lsd.src_location; + +export import lsd.math.vec2; +export import lsd.math.vec3; +export import lsd.math.vec4; +export import lsd.math.mat4; +export import lsd.math.algebra; +export import lsd.math.trig; + +export import lsd.algorithm; diff --git a/modules/math/algebra.cppm b/modules/lsd/math/algebra.cppm similarity index 80% rename from modules/math/algebra.cppm rename to modules/lsd/math/algebra.cppm index 5513e8e..36bdf2b 100644 --- a/modules/math/algebra.cppm +++ b/modules/lsd/math/algebra.cppm @@ -1,8 +1,8 @@ -export module math.algebra; -import math.mat4; -import std; +export module lsd.math.algebra; +import lsd.math.mat4; +import lsd.math.trig; -export namespace lt::math { +export namespace lt::lsd { /** * let... @@ -37,19 +37,19 @@ export namespace lt::math { template constexpr auto perspective(T field_of_view, T aspect_ratio, T z_near, T z_far) { - const T half_fov_tan = std::tan(field_of_view / static_cast(2)); + const T half_fov_tan = tan(field_of_view / static_cast(2u)); auto result = mat4_impl::identity(); - result[0][0] = T { 1 } / (aspect_ratio * half_fov_tan); + result[0][0] = T { 1u } / (aspect_ratio * half_fov_tan); // - result[1][1] = T { 1 } / (half_fov_tan); + result[1][1] = T { 1u } / (half_fov_tan); // // result[2][2] = -(z_far + z_near) / (z_far - z_near); // result[2][2] = z_far / (z_far - z_near); // - result[2][3] = -T { 1 }; + result[2][3] = -T { 1u }; // // result[3][2] = -(T { 2 } * z_far * z_near) / (z_far - z_near); result[3][2] = -(z_far * z_near) / (z_far - z_near); @@ -57,4 +57,4 @@ constexpr auto perspective(T field_of_view, T aspect_ratio, T z_near, T z_far) return result; } -} // namespace lt::math +} // namespace lt::lsd diff --git a/modules/math/components.cppm b/modules/lsd/math/components.cppm similarity index 100% rename from modules/math/components.cppm rename to modules/lsd/math/components.cppm diff --git a/modules/math/mat4.cppm b/modules/lsd/math/mat4.cppm similarity index 65% rename from modules/math/mat4.cppm rename to modules/lsd/math/mat4.cppm index 3e0544b..690cc53 100644 --- a/modules/math/mat4.cppm +++ b/modules/lsd/math/mat4.cppm @@ -1,24 +1,27 @@ -export module math.mat4; -import math.vec3; -import math.vec4; -import std; +export module lsd.math.mat4; +import lsd.math.vec2; +import lsd.math.vec3; +import lsd.math.vec4; +import lsd.primitives; +import lsd.arr; +import lsd.str; -namespace lt::math { +export namespace lt::lsd { -export template +template struct mat4_impl { using Column_T = vec4_impl; + constexpr mat4_impl() = default; + constexpr explicit mat4_impl(T scalar = 0) - : values( - { - Column_T { scalar }, - Column_T { scalar }, - Column_T { scalar }, - Column_T { scalar }, - } - ) + : values({ + Column_T { scalar }, + Column_T { scalar }, + Column_T { scalar }, + Column_T { scalar }, + }) { } @@ -54,12 +57,12 @@ struct mat4_impl }; } - [[nodiscard]] constexpr auto operator[](std::size_t idx) -> Column_T & + [[nodiscard]] constexpr auto operator[](size_t idx) -> Column_T & { return values[idx]; } - [[nodiscard]] constexpr auto operator[](std::size_t idx) const -> const Column_T & + [[nodiscard]] constexpr auto operator[](size_t idx) const -> const Column_T & { return values[idx]; } @@ -74,37 +77,37 @@ struct mat4_impl return vec4_impl {}; } - std::array values; // NOLINT + lsd::arr values; // NOLINT }; -export template +template [[nodiscard]] auto translate(const vec3_impl &value) -> mat4_impl { return mat4_impl {}; } -export template -[[nodiscard]] auto rotate(float value, const vec3_impl &xyz) -> mat4_impl +template +[[nodiscard]] auto rotate(f32 value, const vec3_impl &xyz) -> mat4_impl { return mat4_impl {}; } -export template +template [[nodiscard]] auto scale(const vec3_impl &value) -> mat4_impl { return mat4_impl {}; } -export template +template [[nodiscard]] auto inverse(const mat4_impl &value) -> mat4_impl { return mat4_impl {}; } -export using mat4 = mat4_impl; +using mat4 = mat4_impl; -export using imat4 = mat4_impl; +using imat4 = mat4_impl; -export using umat4 = mat4_impl; +using umat4 = mat4_impl; -} // namespace lt::math +} // namespace lt::lsd diff --git a/modules/math/trig.cppm b/modules/lsd/math/trig.cppm similarity index 76% rename from modules/math/trig.cppm rename to modules/lsd/math/trig.cppm index acea076..2bd6ee2 100644 --- a/modules/math/trig.cppm +++ b/modules/lsd/math/trig.cppm @@ -1,6 +1,11 @@ -export module math.trig; +export module lsd.math.trig; +import std; -export namespace lt::math { +export namespace lt::lsd { + +using ::std::cos; +using ::std::sin; +using ::std::tan; [[nodiscard]] constexpr auto radians(float degrees) -> float { @@ -23,4 +28,4 @@ export namespace lt::math { } -} // namespace lt::math +} // namespace lt::lsd diff --git a/modules/math/vec2.cppm b/modules/lsd/math/vec2.cppm similarity index 56% rename from modules/math/vec2.cppm rename to modules/lsd/math/vec2.cppm index f59a45b..b7742be 100644 --- a/modules/math/vec2.cppm +++ b/modules/lsd/math/vec2.cppm @@ -1,15 +1,14 @@ -export module math.vec2; +export module lsd.math.vec2; +import lsd.primitives; +import lsd.str; -import std; +export namespace lt::lsd { -namespace lt::math { - -export template +template struct vec2_impl { - constexpr vec2_impl(): x(), y() - { - } + constexpr vec2_impl() = default; + constexpr explicit vec2_impl(T scalar): x(scalar), y(scalar) { @@ -45,7 +44,7 @@ struct vec2_impl }; } - [[nodiscard]] auto operator*(float scalar) const -> vec2_impl + [[nodiscard]] auto operator*(f32 scalar) const -> vec2_impl { return { x * scalar, @@ -59,24 +58,26 @@ struct vec2_impl }; -export using vec2 = vec2_impl; +using vec2 = vec2_impl; -export using ivec2 = vec2_impl; +using dvec2 = vec2_impl; -export using uvec2 = vec2_impl; +using ivec2 = vec2_impl; -} // namespace lt::math +using uvec2 = vec2_impl; + +} // namespace lt::lsd export template -struct std::formatter> +struct lt::lsd::formatter> { - constexpr auto parse(std::format_parse_context &context) + constexpr auto parse(lt::lsd::format_parse_context &context) { return context.begin(); } - auto format(const lt::math::vec2_impl &val, std::format_context &context) const + auto format(const lt::lsd::vec2_impl &val, lt::lsd::format_context &context) const { - return std::format_to(context.out(), "{}, {}", val.x, val.y); + return lt::lsd::format_to(context.out(), "{}, {}", val.x, val.y); } }; diff --git a/modules/math/vec3.cppm b/modules/lsd/math/vec3.cppm similarity index 52% rename from modules/math/vec3.cppm rename to modules/lsd/math/vec3.cppm index 9ee5036..a597753 100644 --- a/modules/math/vec3.cppm +++ b/modules/lsd/math/vec3.cppm @@ -1,16 +1,16 @@ -export module math.vec3; +export module lsd.math.vec3; -import math.vec2; -import std; +import lsd.math.vec2; +import lsd.primitives; +import lsd.str; -namespace lt::math { +export namespace lt::lsd { -export template +template struct vec3_impl { - constexpr vec3_impl(): x(), y(), z() - { - } + constexpr vec3_impl() = default; + constexpr explicit vec3_impl(T scalar): x(scalar), y(scalar), z(scalar) { @@ -48,11 +48,11 @@ struct vec3_impl }; } - friend auto operator<<(std::ostream &stream, vec3_impl value) -> std::ostream & - { - stream << value.x << ", " << value.y << ", " << value.z; - return stream; - } + // friend auto operator<<(std::ostream &stream, vec3_impl value) -> std::ostream & + // { + // stream << value.x << ", " << value.y << ", " << value.z; + // return stream; + // } T x; // NOLINT @@ -61,24 +61,26 @@ struct vec3_impl T z; // NOLINT }; -export using vec3 = vec3_impl; +using vec3 = vec3_impl; -export using ivec3 = vec3_impl; +using dvec3 = vec3_impl; -export using uvec3 = vec3_impl; +using ivec3 = vec3_impl; -} // namespace lt::math +using uvec3 = vec3_impl; + +} // namespace lt::lsd template -struct std::formatter> +struct lt::lsd::formatter> { - constexpr auto parse(std::format_parse_context &context) + constexpr auto parse(lt::lsd::format_parse_context &context) { return context.begin(); } - auto format(const lt::math::vec3_impl &val, std::format_context &context) const + auto format(const lt::lsd::vec3_impl &val, lt::lsd::format_context &context) const { - return std::format_to(context.out(), "{}, {}, {}", val.x, val.y, val.z); + return lt::lsd::format_to(context.out(), "{}, {}, {}", val.x, val.y, val.z); } }; diff --git a/modules/lsd/math/vec4.cppm b/modules/lsd/math/vec4.cppm new file mode 100644 index 0000000..f6beee7 --- /dev/null +++ b/modules/lsd/math/vec4.cppm @@ -0,0 +1,104 @@ +export module lsd.math.vec4; +import lsd.math.vec2; +import lsd.math.vec3; +import lsd.primitives; +import lsd.arr; +import lsd.str; + +export namespace lt::lsd { + +template +struct vec4_impl +{ + constexpr vec4_impl() = default; + + constexpr explicit vec4_impl(T scalar): x(scalar), y(scalar), z(scalar), w(scalar) + { + } + + constexpr vec4_impl(T x, T y, T z, T w): x(x), y(y), z(z), w(w) + { + } + + [[nodiscard]] auto operator==(const vec4_impl &other) const -> bool + { + return x == other.x && y == other.y && z == other.z && w == other.w; + } + + [[nodiscard]] auto operator!=(const vec4_impl &other) const -> bool + + { + return !(*this == other); + } + + [[nodiscard]] constexpr auto operator-(const vec4_impl &other) const -> vec4_impl + { + return { + x - other.x, + y - other.y, + z - other.z, + w - other.w, + }; + } + + [[nodiscard]] constexpr auto operator[](size_t idx) -> T & + { + return values[idx]; + } + + [[nodiscard]] constexpr auto operator[](size_t idx) const -> const T & + { + return values[idx]; + } + + // NOLINTNEXTLINE + union + { + struct + { + T x; + + T y; + + T z; + + T w; + }; + struct + { + T r; + + T g; + + T b; + + T a; + }; + struct + { + lsd::arr values; + }; + }; +}; + +using vec4 = vec4_impl; + +using ivec4 = vec4_impl; + +using uvec4 = vec4_impl; + +} // namespace lt::lsd + +export template +struct lt::lsd::formatter> +{ + constexpr auto parse(lt::lsd::format_parse_context &context) + { + return context.begin(); + } + + auto format(const lt::lsd::vec4_impl &val, lt::lsd::format_context &context) const + { + return lt::lsd::format_to(context.out(), "{}, {}, {}, {}", val.x, val.y, val.z, val.w); + } +}; diff --git a/modules/lsd/numeric_limits.cppm b/modules/lsd/numeric_limits.cppm new file mode 100644 index 0000000..e31b9cf --- /dev/null +++ b/modules/lsd/numeric_limits.cppm @@ -0,0 +1,8 @@ +export module lsd.numeric_limits; +import std; + +export namespace lt::lsd { + +using ::std::numeric_limits; + +} diff --git a/modules/lsd/primitives.cppm b/modules/lsd/primitives.cppm index 56dac2e..1effd19 100644 --- a/modules/lsd/primitives.cppm +++ b/modules/lsd/primitives.cppm @@ -5,19 +5,30 @@ import std; THAT HAS NO SUB-NAMESPACE IDENTIFIER. */ export namespace lt { -using u8 = std::uint8_t; -using u16 = std::uint16_t; -using u32 = std::uint32_t; -using u64 = std::uint64_t; +using byte = ::std::byte; -using i8 = std::int8_t; -using i16 = std::int16_t; -using i32 = std::int32_t; -using i64 = std::int64_t; +using u8 = ::std::uint8_t; +using u16 = ::std::uint16_t; +using u32 = ::std::uint32_t; +using u64 = ::std::uint64_t; + +using i8 = ::std::int8_t; +using i16 = ::std::int16_t; +using i32 = ::std::int32_t; +using i64 = ::std::int64_t; using f32 = float; using f64 = double; -using size_t = std::size_t; +using size_t = ::std::size_t; + +using stream_size = ::std::streamsize; + +// The fact that bit_cast is a part of the standard library, +// rather than a builtin like static_cast is language quirk. +// +// From the end-user's perspective, it would be convenient +// for the bit_cast to be a language keyword. +using ::std::bit_cast; } // namespace lt diff --git a/modules/lsd/ref.cppm b/modules/lsd/ref.cppm index 603d268..9545500 100644 --- a/modules/lsd/ref.cppm +++ b/modules/lsd/ref.cppm @@ -10,23 +10,23 @@ export namespace lt::lsd { * @ref https://en.cppreference.com/w/cpp/memory/shared_ptr.html */ template -using Ref = std::shared_ptr; +using ref = std::shared_ptr; /** Allocates memory for an `Underlying_T` and directly constructs it there. * * @return A Ref to the constructed object. */ template -constexpr Ref create_ref(Args &&...args) +constexpr auto create_ref(Args &&...args) -> ref { return std::make_shared(std::forward(args)...); } /** Converts c-style pointer of type `Underlying_T` to a `Ref`. */ template -constexpr Ref make_ref(Underlying_T *raw_pointer) +constexpr auto make_ref(Underlying_T *raw_pointer) -> ref { - return Ref(raw_pointer); + return ref(raw_pointer); } } // namespace lt::lsd diff --git a/modules/lsd/scope.cppm b/modules/lsd/scope.cppm index b3d1d31..3a1e11f 100644 --- a/modules/lsd/scope.cppm +++ b/modules/lsd/scope.cppm @@ -9,23 +9,23 @@ export namespace lt::lsd { * @ref https://en.cppreference.com/w/cpp/memory/unique_ptr.html */ template -using Scope = std::unique_ptr; +using scope = std::unique_ptr; /** Allocates memory for an `Underlying_T` and directly constructs it there. * * @return A Scope to the constructed object. */ template -constexpr Scope create_scope(Args &&...args) +constexpr auto create_scope(Args &&...args) -> scope { return std::make_unique(std::forward(args)...); } /** Converts c-style pointer of type `Underlying_T` to a `Scope`. */ template -constexpr Scope make_scope(Underlying_T *raw_pointer) +constexpr auto make_scope(Underlying_T *raw_pointer) -> scope { - return Scope(raw_pointer); + return scope(raw_pointer); } } // namespace lt::lsd diff --git a/modules/lsd/str.cppm b/modules/lsd/str.cppm index dd95143..5bb066d 100644 --- a/modules/lsd/str.cppm +++ b/modules/lsd/str.cppm @@ -12,4 +12,9 @@ using str_view = std::string_view; template using format_str = std::format_string; +using std::format_context; +using std::format_parse_context; +using std::format_to; +using std::formatter; + } // namespace lt::lsd diff --git a/modules/lsd/utils.cppm b/modules/lsd/utils.cppm index e0c1a72..bb3802f 100644 --- a/modules/lsd/utils.cppm +++ b/modules/lsd/utils.cppm @@ -16,17 +16,15 @@ export namespace lt::lsd { } // NOLINTBEGIN +using ::std::bit_cast; using ::std::declval; using ::std::format; using ::std::forward; using ::std::move; using ::std::println; +using ::std::system; +using ::std::to_underlying; -namespace filesystem { - -using ::std::filesystem::path; - -} // NOLINTEND } // namespace lt::lsd diff --git a/modules/math/vec4.cppm b/modules/math/vec4.cppm deleted file mode 100644 index d96ab81..0000000 --- a/modules/math/vec4.cppm +++ /dev/null @@ -1,109 +0,0 @@ -export module math.vec4; -import math.vec2; -import math.vec3; -import std; - -namespace lt::math { - -export template -struct vec4_impl -{ - constexpr vec4_impl(): x(), y(), z(), w() - { - } - - constexpr explicit vec4_impl(T scalar): x(scalar), y(scalar), z(scalar), w(scalar) - { - } - - constexpr vec4_impl(T x, T y, T z, T w): x(x), y(y), z(z), w(w) - { - } - - [[nodiscard]] auto operator==(const vec4_impl &other) const -> bool - { - return x == other.x && y == other.y && z == other.z && w == other.w; - } - - [[nodiscard]] auto operator!=(const vec4_impl &other) const -> bool - { - return !(*this == other); - } - - [[nodiscard]] constexpr auto operator-(const vec4_impl &other) const -> vec4_impl - { - return { - x - other.x, - y - other.y, - z - other.z, - w - other.w, - }; - } - - [[nodiscard]] constexpr auto operator[](std::size_t idx) -> T & - { - return values[idx]; - } - - [[nodiscard]] constexpr auto operator[](std::size_t idx) const -> const T & - { - return values[idx]; - } - - friend auto operator<<(std::ostream &stream, vec4_impl value) -> std::ostream & - { - stream << value.x << ", " << value.y << ", " << value.z << ", " << value.w; - return stream; - } - - // NOLINTNEXTLINE - union - { - struct - { - T x; - - T y; - - T z; - - T w; - }; - struct - { - T r; - - T g; - - T b; - - T a; - }; - struct - { - std::array values; - }; - }; -}; - -export using vec4 = vec4_impl; - -export using ivec4 = vec4_impl; - -export using uvec4 = vec4_impl; - -} // namespace lt::math - -export template -struct std::formatter> -{ - constexpr auto parse(std::format_parse_context &context) - { - return context.begin(); - } - - auto format(const lt::math::vec4_impl &val, std::format_context &context) const - { - return std::format_to(context.out(), "{}, {}, {}, {}", val.x, val.y, val.z, val.w); - } -}; diff --git a/modules/test/entrypoint.cpp b/modules/test/entrypoint.cpp index f4ec802..0b122b5 100644 --- a/modules/test/entrypoint.cpp +++ b/modules/test/entrypoint.cpp @@ -7,23 +7,18 @@ import lsd; using namespace ::lt; using namespace ::lt::test; -constexpr lsd::str_view operator""_sv(const char *str, unsigned long len) noexcept -{ - return lsd::str_view { str, len }; -} - void parse_option(lsd::str_view argument, Registry::Options &options) { constexpr auto case_str = lsd::str_view { "--case=" }; constexpr auto suite_str = lsd::str_view { "--suite=" }; - if (argument == "--stop-on-fail"_sv) + if (argument == "--stop-on-fail") { options.stop_on_fail = true; return; } - if (argument.starts_with("--mode="_sv) && argument.substr(7ul) == "stats") + if (argument.starts_with("--mode=") && argument.substr(7ul) == "stats") { options.execution_policy = Registry::ExecutionPolicy::stats; return; @@ -91,7 +86,7 @@ try return static_cast(Registry::run_all(options)); } -catch (const std::exception &exp) +catch (const lsd::exception &exp) { lt::log::critical("Terminated due to uncaught exception:"); lt::log::critical("\twhat: {}", exp.what()); diff --git a/modules/test/test.cppm b/modules/test/test.cppm index 6d0c96b..47f9998 100644 --- a/modules/test/test.cppm +++ b/modules/test/test.cppm @@ -1,8 +1,9 @@ export module test.test; -import std; import test.expects; import test.registry; +import std; +import lsd; /////////////////////////////////////// // ----------* INTERFACE *--------- // @@ -12,16 +13,16 @@ namespace lt::test { class TestCase { public: - TestCase(std::string_view name); + TestCase(lsd::str_view name); // NOLINTNEXTLINE(misc-unconventional-assign-operator) - auto operator=(std::invocable auto test) const -> void; + auto operator=(lsd::invocable auto test) const -> void; private: - void run_normal(std::invocable auto test) const; + void run_normal(lsd::invocable auto test) const; private: - std::string_view m_name; + lsd::str_view m_name; }; struct TestSuite @@ -38,25 +39,25 @@ struct TestFuzzHarness export using Case = const TestCase; export using Suite = const TestSuite; export using FuzzHarness = const TestFuzzHarness; -export auto operator""_suite(const char *name, std::size_t size) -> TestSuite; +export auto operator""_suite(const char *name, size_t size) -> TestSuite; /////////////////////////////////////// // * IMPLEMENTATION -- TEMPLATES * // ///////////////////////////////////// // NOLINTNEXTLINE(misc-unconventional-assign-operator) -auto TestCase::operator=(std::invocable auto test) const -> void +auto TestCase::operator=(lsd::invocable auto test) const -> void { using enum Registry::ExecutionPolicy; switch (Registry::get_options().execution_policy) { - case normal: run_normal(std::move(test)); break; + case normal: run_normal(lsd::move(test)); break; case stats: Registry::increment_total_case_count(); break; } } -void TestCase::run_normal(std::invocable auto test) const +void TestCase::run_normal(lsd::invocable auto test) const { Registry::increment_total_case_count(); @@ -68,16 +69,16 @@ void TestCase::run_normal(std::invocable auto test) const } Registry::increment_matched_case_count(); - std::println("[Running-----------] --> "); - std::println("{}", m_name); + lsd::println("[Running-----------] --> "); + lsd::println("{}", m_name); try { test(); } catch (const std::exception &exp) { - std::println("{}", exp.what()); - std::println("[-----------FAIL !!]"); + lsd::println("{}", exp.what()); + lsd::println("[-----------FAIL !!]"); Registry::increment_failed_case_count(); if (Registry::should_return_on_failure()) @@ -89,7 +90,7 @@ void TestCase::run_normal(std::invocable auto test) const } Registry::increment_passed_case_count(); - std::println("[--------SUCCESS :D]"); + lsd::println("[--------SUCCESS :D]"); } TestSuite::TestSuite(auto body) @@ -106,7 +107,7 @@ constexpr TestFuzzHarness::TestFuzzHarness(auto body) #endif }; -auto operator""_suite(const char *name, std::size_t size) -> TestSuite +auto operator""_suite(const char *name, size_t size) -> TestSuite { Registry::set_last_suite_name(name); return {}; @@ -120,7 +121,7 @@ auto operator""_suite(const char *name, std::size_t size) -> TestSuite module :private; namespace lt::test { -TestCase::TestCase(std::string_view name): m_name(name) +TestCase::TestCase(lsd::str_view name): m_name(name) { } diff --git a/modules/time/timer.cppm b/modules/time/timer.cppm index 18d8dd2..42dc48b 100644 --- a/modules/time/timer.cppm +++ b/modules/time/timer.cppm @@ -1,5 +1,5 @@ export module time; -import std; +import lsd; namespace lt::time { @@ -7,11 +7,11 @@ namespace lt::time { export class Timer { public: - using Clock = std::chrono::steady_clock; + using Clock = lsd::chrono::steady_clock; - using Duration = std::chrono::duration; + using Duration = lsd::chrono::duration; - using Timepoint = std::chrono::time_point; + using Timepoint = lsd::chrono::time_point; Timer(Timepoint start = Clock::now()); @@ -39,7 +39,7 @@ void Timer::reset(Timepoint start) [[nodiscard]] auto Timer::elapsed_time() const -> Duration { - return { std::chrono::steady_clock::now() - m_start }; + return { lsd::chrono::steady_clock::now() - m_start }; } } // namespace lt::time