From 9fb0fc7d6d370c45c90aa9643af3832291674dc8 Mon Sep 17 00:00:00 2001 From: kj16609 Date: Sat, 23 Nov 2024 17:17:58 -0500 Subject: [PATCH] Adds defines --- .gitmodules | 3 ++ CMakeLists.txt | 5 +++ fgl_cmake_modules | 1 + include/fgl/defines.hpp | 73 +++++++++++++++++++++++++++++++++++++++++ src/stub.cpp | 1 + 5 files changed, 83 insertions(+) create mode 100644 .gitmodules create mode 160000 fgl_cmake_modules create mode 100644 include/fgl/defines.hpp create mode 100644 src/stub.cpp diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..141e441 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "fgl_cmake_modules"] + path = fgl_cmake_modules + url = git@github.com:KJNeko/fgl_cmake_modules.git diff --git a/CMakeLists.txt b/CMakeLists.txt index e69de29..f29b79d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -0,0 +1,5 @@ + + +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/fgl_cmake_modules) + +AddFGLLibrary(libFGL STATIC ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/include) \ No newline at end of file diff --git a/fgl_cmake_modules b/fgl_cmake_modules new file mode 160000 index 0000000..11a7071 --- /dev/null +++ b/fgl_cmake_modules @@ -0,0 +1 @@ +Subproject commit 11a70712800e66fb13233b98e6cd2d81c98ff4d7 diff --git a/include/fgl/defines.hpp b/include/fgl/defines.hpp new file mode 100644 index 0000000..1bb1e0f --- /dev/null +++ b/include/fgl/defines.hpp @@ -0,0 +1,73 @@ +// +// Created by kj16609 on 11/23/24. +// +#pragma once + +#define FGL_DELETE_DEFAULT_CTOR( ClassName ) ClassName() = delete; +#define FGL_DELETE_COPY_ASSIGN( ClassName ) ClassName& operator=( const ClassName& ) = delete; +#define FGL_DELETE_COPY_CTOR( ClassName ) ClassName( const ClassName& ) = delete; +#define FGL_DELETE_MOVE_ASSIGN( ClassName ) ClassName& operator=( ClassName&& ) = delete; +#define FGL_DELETE_MOVE_CTOR( ClassName ) ClassName( ClassName&& ) = delete; +#define FGL_DELETE_COPY( ClassName ) FGL_DELETE_COPY_CTOR( ClassName ) FGL_DELETE_COPY_ASSIGN( ClassName ) +#define FGL_DELETE_MOVE( ClassName ) FGL_DELETE_MOVE_CTOR( ClassName ) FGL_DELETE_MOVE_ASSIGN( ClassName ) +#define FGL_DELETE_ALL_RO5( ClassName ) \ + FGL_DELETE_DEFAULT_CTOR( ClassName ) FGL_DELETE_COPY( ClassName ) FGL_DELETE_MOVE( ClassName ) + +#define FGL_DEFAULT_DEFAULT_CTOR( ClassName ) ClassName() = default; +#define FGL_DEFAULT_COPY_ASSIGN( ClassName ) ClassName& operator=( const ClassName& ) = default; +#define FGL_DEFAULT_COPY_CTOR( ClassName ) ClassName( const ClassName& ) = default; +#define FGL_DEFAULT_MOVE_ASSIGN( ClassName ) ClassName& operator=( ClassName&& ) = default; +#define FGL_DEFAULT_MOVE_CTOR( ClassName ) ClassName( ClassName&& ) = default; +#define FGL_DEFAULT_COPY( ClassName ) FGL_DEFAULT_COPY_CTOR( ClassName ) FGL_DEFAULT_COPY_ASSIGN( ClassName ) +#define FGL_DEFAULT_MOVE( ClassName ) FGL_DEFAULT_MOVE_CTOR( ClassName ) FGL_DEFAULT_MOVE_ASSIGN( ClassName ) +#define FGL_DEFAULT_ALL_RO5( ClassName ) \ + FGL_DEFAULT_DEFAULT_CTOR( ClassName ) FGL_DEFAULT_COPY( ClassName ) FGL_DEFAULT_MOVE( ClassName ) + +#define FGL_PACKED __attribute__( ( packed ) ) +#define FGL_PACKED_ALIGNED( al ) __attribute__( ( packed, aligned( al ) ) ) +#define FGL_FLATTEN [[gnu::flatten]] +#define FGL_ARTIFICIAL [[gnu::artificial]] +#define FGL_HOT [[gnu::hot]] +#define FGL_COLD [[gnu::cold]] +#define FGL_FLATTEN_HOT FGL_FLATTEN FGL_HOT +#define FGL_FORCE_INLINE [[gnu::always_inline]] +#define FGL_FORCE_INLINE_FLATTEN FGL_FLATTEN FGL_FORCE_INLINE + +#define FGL_UNINITALIZED [[indeterminate]] + +#ifndef NDEBUG +#define FGL_ASSUME( ... ) \ + FGL_ASSERT( ( __VA_ARGS__ ), "FGL_ASSUME: Check failed!" ); \ + [[gnu::assume( __VA_ARGS__ )]]; +#else +#define FGL_ASSUME( ... ) [[gnu::assume( __VA_ARGS__ )]] +#endif + +#define FGL_ALIGN( bytesize ) [[gnu::alligned( bitsize )]] + +#define FGL_FUNC_CLEANUP( func ) [[gnu::cleanup( func )]] + +//! Warns if the variable is used as a string (strlen) +#define FGL_NONSTRING_DATA [[gnu::nonstring]] + +//! Warns if the structure field is not alligned with a set number of bytes +#define FGL_STRICT_ALIGNMENT( bytesize ) [[gnu::warn_if_not_aligned( bytesize )]] + +#ifndef NDEBUG +#include +#define FGL_ASSERT( test, msg ) assert( ( test ) && "msg" ); +//if ( !( test ) ) throw std::runtime_error( msg ); +#else +#define FGL_ASSERT( test, msg ) +#endif + +#define FGL_UNIMPLEMENTED() FGL_ASSERT( false, "unimplemented" ); + +#ifndef NDEBUG +#include +#define FGL_UNREACHABLE() \ + FGL_ASSERT( false, "Should have been unreachable!" ); \ + std::unreachable() +#else +#define FGL_UNREACHABLE() std::unreachable() +#endif diff --git a/src/stub.cpp b/src/stub.cpp new file mode 100644 index 0000000..dcbf2b3 --- /dev/null +++ b/src/stub.cpp @@ -0,0 +1 @@ +// fgl libs need at least a single source file \ No newline at end of file