This commit is contained in:
parent
b30ccb46d9
commit
1e84b30477
12 changed files with 130 additions and 30 deletions
|
@ -1,2 +1,3 @@
|
|||
add_subdirectory(utilities/preliminary)
|
||||
add_subdirectory(universal_pch)
|
||||
|
||||
add_subdirectory(light)
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
add_executable(light ${CMAKE_CURRENT_SOURCE_DIR}/src/entrypoint.cpp)
|
||||
|
||||
target_link_libraries(light PRIVATE preliminary)
|
||||
target_link_libraries(light PRIVATE universal_pch errors)
|
||||
|
|
|
@ -1,6 +1,17 @@
|
|||
auto main() -> lt::i32
|
||||
auto main() -> int32_t
|
||||
try
|
||||
{
|
||||
std::cout << "Light built and ran fine...";
|
||||
|
||||
return 0;
|
||||
}
|
||||
catch (const std::exception &exp)
|
||||
{
|
||||
std::cout << "\n\nUnhandled std exception: " << exp.what() << std::endl; // NOLINT
|
||||
return -1;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cout << "\n\nUnhandled exception" << std::endl; // NOLINT
|
||||
return -1;
|
||||
}
|
||||
|
|
2
modules/universal_pch/CMakeLists.txt
Normal file
2
modules/universal_pch/CMakeLists.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
add_library_module(universal_pch)
|
||||
target_precompile_headers(universal_pch INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/src/pch.hpp)
|
|
@ -0,0 +1,55 @@
|
|||
#pragma once
|
||||
|
||||
#include <universal_pch/error_handling/types.hpp>
|
||||
#include <universal_pch/module_configs.hpp>
|
||||
|
||||
namespace lt {
|
||||
|
||||
namespace details {
|
||||
|
||||
inline void throw_if_false(bool condition, std::source_location location)
|
||||
{
|
||||
if (!condition)
|
||||
{
|
||||
throw Error { "Failed runtime assertion", location };
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace details
|
||||
|
||||
/** Throws lt::Error if \a condition is false, otherwise returns without side-effects.
|
||||
*
|
||||
* @throws lt::Error
|
||||
*
|
||||
* @note Only runs when LIGHT_ENABLE_CHECK is enabled, which is enabled by default on debug builds.
|
||||
*
|
||||
* @warn The successful execution of the contract of the using code should NOT depend on the
|
||||
* execution of this function as it may or may NOT be executed--based on project configuration.
|
||||
*/
|
||||
inline void check(bool condition, std::source_location location = std::source_location::current())
|
||||
{
|
||||
if constexpr (light_enabled_check)
|
||||
{
|
||||
details::throw_if_false(condition, location);
|
||||
}
|
||||
}
|
||||
|
||||
/** Throws lt::Error if \a condition is false, otherwise returns without side-effects.
|
||||
*
|
||||
* @throws lt::Error
|
||||
*
|
||||
* @note Only runs when LIGHT_ENABLE_ENSURE is enabled, which is enabled by default on debug and
|
||||
* release builds.
|
||||
*
|
||||
* @warn The successful execution of the contract of the using code should NOT depend on the
|
||||
* execution of this function as it may or may NOT be executed--based on project configuration.
|
||||
*/
|
||||
inline void ensure(bool condition, std::source_location location = std::source_location::current())
|
||||
{
|
||||
if constexpr (light_enabled_ensure)
|
||||
{
|
||||
details::throw_if_false(condition, location);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace lt
|
|
@ -0,0 +1,31 @@
|
|||
#pragma once
|
||||
|
||||
namespace lt {
|
||||
|
||||
class Error: public std::exception
|
||||
{
|
||||
public:
|
||||
Error(std::string_view reason, std::source_location location): m_reason(reason)
|
||||
{
|
||||
std::ignore = location;
|
||||
}
|
||||
|
||||
Error(const Error &prev, std::string_view reason, std::source_location location)
|
||||
: m_reason(reason)
|
||||
{
|
||||
std::ignore = location;
|
||||
std::ignore = prev;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto what() const noexcept -> const char * override
|
||||
{
|
||||
return "Idk fuck all";
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_reason;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
using Expected = std::expected<T, Error>;
|
||||
} // namespace lt
|
|
@ -0,0 +1,15 @@
|
|||
namespace lt {
|
||||
|
||||
#ifdef LIGHT_ENABLE_CHECK
|
||||
constexpr bool light_enabled_check = true;
|
||||
#else
|
||||
constexpr bool light_enabled_check = false;
|
||||
#endif
|
||||
|
||||
#ifdef LIGHT_ENABLE_ENSURE
|
||||
constexpr bool light_enabled_ensure = true;
|
||||
#else
|
||||
constexpr bool light_enabled_ensure = false;
|
||||
#endif
|
||||
|
||||
} // namespace lt
|
|
@ -1,6 +1,4 @@
|
|||
#pragma once
|
||||
|
||||
#include <preliminary/types.hpp>
|
||||
// NOLINTBEGIN
|
||||
|
||||
/* utilities */
|
||||
#include <any>
|
||||
|
@ -10,6 +8,8 @@
|
|||
#include <cstdint>
|
||||
#include <ctime>
|
||||
#include <exception>
|
||||
#include <expected>
|
||||
#include <format>
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
|
@ -64,3 +64,5 @@
|
|||
|
||||
/* filesystem */
|
||||
#include <filesystem>
|
||||
|
||||
// NOLINTEND
|
7
modules/universal_pch/src/pch.hpp
Normal file
7
modules/universal_pch/src/pch.hpp
Normal file
|
@ -0,0 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <universal_pch/std_headers.hpp>
|
||||
|
||||
/* error_handling */
|
||||
#include <universal_pch/error_handling/checks.hpp>
|
||||
#include <universal_pch/error_handling/types.hpp>
|
|
@ -1,3 +0,0 @@
|
|||
add_library(preliminary INTERFACE)
|
||||
target_precompile_headers(preliminary INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/src/pch.hpp)
|
||||
target_include_directories(preliminary INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include/)
|
|
@ -1,21 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
|
||||
namespace lt {
|
||||
|
||||
using i8 = int8_t;
|
||||
using i16 = int16_t;
|
||||
using i32 = int32_t;
|
||||
using i64 = int64_t;
|
||||
|
||||
using u8 = uint8_t;
|
||||
using u16 = uint16_t;
|
||||
using u32 = uint32_t;
|
||||
using u64 = uint64_t;
|
||||
|
||||
template<typename T>
|
||||
using vec = std::vector<T>;
|
||||
|
||||
} // namespace lt
|
Loading…
Add table
Reference in a new issue