Compare commits
33 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ea5d73f2ac | |||
| 1eb901fd75 | |||
| 055ad5aaa7 | |||
| a46749a7a6 | |||
| fac5494bee | |||
| f5c2c86eea | |||
| a7aa1601b5 | |||
| 86c05b29dc | |||
| ae43377c57 | |||
| 77b10d5215 | |||
| 7305dc2e1b | |||
| d1d58e4eba | |||
| 7bab49f8d8 | |||
| f2d8d792fe | |||
| 945310d4d7 | |||
| 63f393e07c | |||
| 83794c7531 | |||
| fec9c7a904 | |||
| 14e83f176a | |||
| 02dc51a698 | |||
| b663c74706 | |||
| 1ce9f47c59 | |||
| d70a0f7bad | |||
| 77024c7561 | |||
| 8726aa8bdd | |||
| a475a261ed | |||
| 6230b8f4d4 | |||
| 59907f5b56 | |||
| 698311842f | |||
| 331adada15 | |||
| a7eb469f13 | |||
| 40bb17e2aa | |||
|
|
25f0fc63b9 |
2
.gitmodules
vendored
2
.gitmodules
vendored
@@ -1,3 +1,3 @@
|
|||||||
[submodule "fgl_cmake_modules"]
|
[submodule "fgl_cmake_modules"]
|
||||||
path = fgl_cmake_modules
|
path = fgl_cmake_modules
|
||||||
url = git@github.com:KJNeko/fgl_cmake_modules.git
|
url = https://git.futuregadgetlabs.net/KJ16609/fgl_cmake_modules.git
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
|
|
||||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/fgl_cmake_modules)
|
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/fgl_cmake_modules)
|
||||||
|
|
||||||
|
PreSetup()
|
||||||
|
|
||||||
AddFGLLibrary(libFGL STATIC ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
AddFGLLibrary(libFGL STATIC ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||||
Submodule fgl_cmake_modules updated: 79f64194d6...1e44655a66
16
include/fgl/features.hpp
Normal file
16
include/fgl/features.hpp
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
//
|
||||||
|
// Created by kj16609 on 7/16/25.
|
||||||
|
//
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef __cpp_pp_embed
|
||||||
|
#if __cpp_pp_embed >= 202502L
|
||||||
|
#define FGL_HAS_EMBED 1
|
||||||
|
#else
|
||||||
|
#define FGL_HAS_EMBED 0
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef FGL_HAS_EMBED
|
||||||
|
#define FGL_HAS_EMBED 0
|
||||||
|
#endif
|
||||||
32
include/fgl/reflection/enumFromString.hpp
Normal file
32
include/fgl/reflection/enumFromString.hpp
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
//
|
||||||
|
// Created by kj16609 on 11/24/25.
|
||||||
|
//
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace fgl
|
||||||
|
{
|
||||||
|
template < typename E >
|
||||||
|
consteval E enumFromString( std::string_view s )
|
||||||
|
{
|
||||||
|
constexpr std::meta::info info { ^^E };
|
||||||
|
|
||||||
|
static_assert( std::meta::is_enum_type( info ), "E must be an enum" );
|
||||||
|
|
||||||
|
for ( const auto member : std::meta::enumerators_of( info ) )
|
||||||
|
{
|
||||||
|
const auto name { std::meta::identifier_of( member ) };
|
||||||
|
if ( name == s ) return std::meta::extract< E >( member );
|
||||||
|
}
|
||||||
|
|
||||||
|
throw std::meta::exception( "Unable to map string to enum", info );
|
||||||
|
}
|
||||||
|
|
||||||
|
enum TestEnum
|
||||||
|
{
|
||||||
|
MY_VAR = 1
|
||||||
|
};
|
||||||
|
|
||||||
|
static_assert(
|
||||||
|
enumFromString< TestEnum >( "MY_VAR" ) == TestEnum::MY_VAR, "Enum from string did not get expected output" );
|
||||||
|
|
||||||
|
} // namespace fgl
|
||||||
@@ -3,21 +3,54 @@
|
|||||||
//
|
//
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cmath>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <format>
|
#include <format>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace fgl::size
|
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 < mod * mod ) return std::format( "{}KiB", static_cast< int >( size / mod ) );
|
||||||
|
if ( size < mod * mod * mod ) return std::format( "{}MiB", static_cast< int >( size / ( mod * mod ) ) );
|
||||||
|
if ( size < mod * mod * mod * mod )
|
||||||
|
return std::format( "{}GiB", static_cast< int >( size / ( mod * mod * mod ) ) );
|
||||||
|
return std::format( "{}TiB", static_cast< int >( size / ( mod * mod * mod * mod ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace literals
|
||||||
|
{
|
||||||
|
|
||||||
|
constexpr unsigned long long int operator""_B( const unsigned long long int size )
|
||||||
|
{
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr unsigned long long int operator""_KiB( const unsigned long long int size )
|
||||||
|
{
|
||||||
|
return size * 1024;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr unsigned long long int operator""_MiB( const unsigned long long int size )
|
||||||
|
{
|
||||||
|
return size * 1024_KiB;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr unsigned long long int operator""_GiB( const unsigned long long int size )
|
||||||
|
{
|
||||||
|
return size * 1024_MiB;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::string toString( const unsigned long long int size )
|
||||||
|
{
|
||||||
|
if ( size < 1024_B ) return std::to_string( size ) + " B";
|
||||||
|
if ( size < 1024_KiB ) return std::to_string( size / 1024 ) + " KiB";
|
||||||
|
if ( size < 1024_MiB ) return std::to_string( size / 1024_KiB ) + " MiB";
|
||||||
|
if ( size < 1024_GiB ) return std::to_string( size / 1024_MiB ) + " GiB";
|
||||||
|
return std::to_string( size / 1024_GiB ) + " TiB";
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace literals
|
||||||
|
|
||||||
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
|
} // namespace fgl::size
|
||||||
Reference in New Issue
Block a user