added cmake option

This commit is contained in:
2026-01-04 23:02:58 +03:00
parent eae10d92ca
commit d2e418c50b
2 changed files with 21 additions and 14 deletions

View File

@@ -27,7 +27,7 @@ option(OMATH_SUPRESS_SAFETY_CHECKS "Supress some safety checks in release build
option(OMATH_USE_UNITY_BUILD "Will enable unity build to speed up compilation" OFF) option(OMATH_USE_UNITY_BUILD "Will enable unity build to speed up compilation" OFF)
option(OMATH_ENABLE_LEGACY "Will enable legacy classes that MUST be used ONLY for backward compatibility" ON) option(OMATH_ENABLE_LEGACY "Will enable legacy classes that MUST be used ONLY for backward compatibility" ON)
option(OMATH_ENABLE_COVERAGE "Enable coverage" OFF) option(OMATH_ENABLE_COVERAGE "Enable coverage" OFF)
option(OMATH_ENABLE_FORCE_INLINE "Will for compiler to make some functions to be force inlined no matter what" ON)
if (VCPKG_MANIFEST_FEATURES) if (VCPKG_MANIFEST_FEATURES)
foreach (omath_feature IN LISTS VCPKG_MANIFEST_FEATURES) foreach (omath_feature IN LISTS VCPKG_MANIFEST_FEATURES)
if (omath_feature STREQUAL "imgui") if (omath_feature STREQUAL "imgui")
@@ -112,6 +112,10 @@ if (OMATH_ENABLE_LEGACY)
target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_ENABLE_LEGACY) target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_ENABLE_LEGACY)
endif () endif ()
if (OMATH_ENABLE_FORCE_INLINE)
target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_ENABLE_FORCE_INLINE)
endif ()
set_target_properties(${PROJECT_NAME} PROPERTIES set_target_properties(${PROJECT_NAME} PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}" ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}" LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"

View File

@@ -6,11 +6,14 @@
#include <cstddef> #include <cstddef>
#include <cstdint> #include <cstdint>
#include <span> #include <span>
#ifdef OMATH_ENABLE_FORCE_INLINE
#ifdef _MSC_VER #ifdef _MSC_VER
#define OMATH_FORCEINLINE __forceinline #define OMATH_FORCE_INLINE __forceinline
#else #else
#define OMATH_FORCEINLINE __attribute__((always_inline)) inline #define OMATH_FORCE_INLINE __attribute__((always_inline)) inline
#endif
#else
#define OMATH_FORCE_INLINE
#endif #endif
namespace omath::detail namespace omath::detail
@@ -111,7 +114,7 @@ namespace omath
bool m_is_encrypted; bool m_is_encrypted;
T m_data; T m_data;
OMATH_FORCEINLINE constexpr void xor_contained_var_by_key() OMATH_FORCE_INLINE constexpr void xor_contained_var_by_key()
{ {
std::span bytes{reinterpret_cast<std::uint8_t*>(&m_data), sizeof(m_data)}; std::span bytes{reinterpret_cast<std::uint8_t*>(&m_data), sizeof(m_data)};
@@ -121,7 +124,7 @@ namespace omath
} }
public: public:
OMATH_FORCEINLINE constexpr explicit EncryptedVariable(const T& data): m_is_encrypted(false), m_data(data) OMATH_FORCE_INLINE constexpr explicit EncryptedVariable(const T& data): m_is_encrypted(false), m_data(data)
{ {
encrypt(); encrypt();
} }
@@ -129,14 +132,14 @@ namespace omath
{ {
return m_is_encrypted; return m_is_encrypted;
} }
OMATH_FORCEINLINE constexpr void decrypt() OMATH_FORCE_INLINE constexpr void decrypt()
{ {
if (!m_is_encrypted) if (!m_is_encrypted)
return; return;
xor_contained_var_by_key(); xor_contained_var_by_key();
m_is_encrypted = false; m_is_encrypted = false;
} }
OMATH_FORCEINLINE constexpr void encrypt() OMATH_FORCE_INLINE constexpr void encrypt()
{ {
if (m_is_encrypted) if (m_is_encrypted)
return; return;
@@ -144,21 +147,21 @@ namespace omath
m_is_encrypted = true; m_is_encrypted = true;
} }
[[nodiscard]] [[nodiscard]]
OMATH_FORCEINLINE constexpr T& value() OMATH_FORCE_INLINE constexpr T& value()
{ {
return m_data; return m_data;
} }
[[nodiscard]] [[nodiscard]]
OMATH_FORCEINLINE constexpr const T& value() const OMATH_FORCE_INLINE constexpr const T& value() const
{ {
return m_data; return m_data;
} }
OMATH_FORCEINLINE ~EncryptedVariable() OMATH_FORCE_INLINE ~EncryptedVariable()
{ {
decrypt(); decrypt();
} }
[[nodiscard]] [[nodiscard]]
OMATH_FORCEINLINE auto drop_anchor() OMATH_FORCE_INLINE auto drop_anchor()
{ {
return VarAnchor{*this}; return VarAnchor{*this};
} }
@@ -168,11 +171,11 @@ namespace omath
{ {
public: public:
// ReSharper disable once CppNonExplicitConvertingConstructor // ReSharper disable once CppNonExplicitConvertingConstructor
OMATH_FORCEINLINE constexpr VarAnchor(EncryptedVarType& var): m_var(var) // NOLINT(*-explicit-constructor) OMATH_FORCE_INLINE constexpr VarAnchor(EncryptedVarType& var): m_var(var) // NOLINT(*-explicit-constructor)
{ {
m_var.decrypt(); m_var.decrypt();
} }
OMATH_FORCEINLINE constexpr ~VarAnchor() OMATH_FORCE_INLINE constexpr ~VarAnchor()
{ {
m_var.encrypt(); m_var.encrypt();
} }