diff --git a/fgl_cmake_modules b/fgl_cmake_modules index 1d3efaf..79f6419 160000 --- a/fgl_cmake_modules +++ b/fgl_cmake_modules @@ -1 +1 @@ -Subproject commit 1d3efaf2bcdcefd7ff312733e1eda7933e8c24d6 +Subproject commit 79f64194d69c1b0c09169fe7bff3471bb8f9ad64 diff --git a/include/fgl/defines.hpp b/include/fgl/defines.hpp index 1bb1e0f..c8e90a8 100644 --- a/include/fgl/defines.hpp +++ b/include/fgl/defines.hpp @@ -55,8 +55,12 @@ #ifndef NDEBUG #include -#define FGL_ASSERT( test, msg ) assert( ( test ) && "msg" ); -//if ( !( test ) ) throw std::runtime_error( msg ); +#define FGL_ASSERT( test, msg ) \ + if ( !( test ) ) \ + { \ + throw std::runtime_error( msg ); \ + std::abort(); \ + } #else #define FGL_ASSERT( test, msg ) #endif diff --git a/include/fgl/size.hpp b/include/fgl/size.hpp new file mode 100644 index 0000000..fe59746 --- /dev/null +++ b/include/fgl/size.hpp @@ -0,0 +1,23 @@ +// +// Created by kj16609 on 3/21/25. +// +#pragma once + +#include +#include +#include +#include + +namespace fgl::size +{ + +std::string toHuman( std::size_t size ) +{ + constexpr std::size_t mod { 1024 }; + if ( size < mod ) return std::format( "{}B", size ); + if ( size < std::pow( mod, 2 ) ) return std::format( "{}KiB", static_cast< int >( size / mod ) ); + if ( size < std::pow( mod, 3 ) ) return std::format( "{}MiB", static_cast< int >( size / std::pow( mod, 2 ) ) ); + if ( size < std::pow( mod, 4 ) ) return std::format( "{}GiB", static_cast< int >( size / std::pow( mod, 3 ) ) ); + return std::format( "{}TiB", static_cast< int >( size / std::pow( mod, 4 ) ) ); +} +} // namespace fgl::size \ No newline at end of file