Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

79 clang format #80

Merged
merged 4 commits into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
Language: Cpp
BasedOnStyle: Google
AccessModifierOffset: -1
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: None
AlignOperands: Align
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
AllowShortLambdasOnASingleLine: Inline
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: true
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterStruct: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
ColumnLimit: 120
CompactNamespaces: false
ContinuationIndentWidth: 0
Cpp11BracedListStyle: true
DerivePointerAlignment: false
EmptyLineBeforeAccessModifier: LogicalBlock
FixNamespaceComments: true
IncludeBlocks: Preserve
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 2
InsertBraces: false
KeepEmptyLinesAtTheStartOfBlocks: true
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PointerAlignment: Left
ReflowComments: false
SeparateDefinitionBlocks: Always
SortIncludes: CaseSensitive
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: Custom
SpaceBeforeParensOptions:
AfterControlStatements: false
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: c++20
TabWidth: 2
UseTab: Never
27 changes: 27 additions & 0 deletions .github/workflows/clang-format-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Clang Format Check

on:
pull_request:
paths:
- '**.cpp'
- '**.h'
- '**.hpp'
push:
branches: [ main ]
paths:
- '**.cpp'
- '**.h'
- '**.hpp'

jobs:
formatting-check:
name: Formatting Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run clang-format style check
uses: jidicula/[email protected]
with:
clang-format-version: '16'
check-path: '.'
fallback-style: 'Google'
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "external/googletest"]
path = external/googletest
url = https://github.com/google/googletest.git
[submodule "external/doxygen-awesome-css"]
path = external/doxygen-awesome-css
url = https://github.com/jothepro/doxygen-awesome-css.git
1 change: 0 additions & 1 deletion external/googletest
Submodule googletest deleted from 1f643f
65 changes: 40 additions & 25 deletions include/core/macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include <string>
#include <type_traits>


namespace Disa {

// ---------------------------------------------------------------------------------------------------------------------
Expand All @@ -43,7 +42,7 @@ enum class Log_Level : uint8_t {
Warning,
Info,
Debug,
};//Log_Level
}; //Log_Level

/**
* \brief Adds additional information to messages about to be printed to screen, such as file and line numbers.
Expand All @@ -53,9 +52,9 @@ enum class Log_Level : uint8_t {
*/
inline std::basic_string<char> console_format(const Log_Level level, const std::source_location& location) {
auto const iter = std::basic_string_view<char>(location.file_name()).find_last_of('/');
const auto suffix = std::basic_string<char>(location.file_name()).substr(iter + 1) + "::"
+ std::to_string(location.line()) + "]: ";
switch (level) {
const auto suffix =
std::basic_string<char>(location.file_name()).substr(iter + 1) + "::" + std::to_string(location.line()) + "]: ";
switch(level) {
case Log_Level::Debug:
return "[Debug|" + std::basic_string(suffix);
case Log_Level::Info:
Expand All @@ -65,45 +64,58 @@ inline std::basic_string<char> console_format(const Log_Level level, const std::
case Log_Level::Error:
return "[Error|" + std::basic_string(suffix);
default:
std::cout<<"[Error|" + std::basic_string(suffix) + " Unrecognised log level parsed.";
std::cout << "[Error|" + std::basic_string(suffix) + " Unrecognised log level parsed.";
exit(1);
}
}//console_format
} //console_format

#ifdef DISA_DEBUG
/**
* \brief Debug level console write out.
* \param[in] message The message to print to the output stream.
*/
#define DEBUG(message) std::cout<<"\n"<<console_format(Disa::Log_Level::Debug, std::source_location::current())<<(message)<<std::flush
#define DEBUG(message) \
std::cout << "\n" \
<< console_format(Disa::Log_Level::Debug, std::source_location::current()) << (message) << std::flush
#else
#define DEBUG(message) {}
#define DEBUG(message) \
{}
#endif

/**
* \brief General information level console write out.
* \param[in] message The message to print to the output stream.
*/
#define INFO(message) std::cout<<"\n"<<console_format(Disa::Log_Level::Info, std::source_location::current())<<(message)<<std::flush
#define INFO(message) \
std::cout << "\n" << console_format(Disa::Log_Level::Info, std::source_location::current()) << (message) << std::flush

/**
* \brief Warning level console write out.
* \param[in] message The message to print to the output stream.
*/
#define WARNING(message) std::cout<<"\n"<<console_format(Disa::Log_Level::Warning, std::source_location::current())<<(message)<<std::flush
#define WARNING(message) \
std::cout << "\n" \
<< console_format(Disa::Log_Level::Warning, std::source_location::current()) << (message) << std::flush

/**
* \brief Error level console write out, writes to std::cerr.
* \param[in] message The message to print to the error stream.
*/
#define ERROR(message) std::cerr<<"\n"<<console_format(Disa::Log_Level::Error, std::source_location::current())<<(message)<<std::endl
#define ERROR(message) \
std::cerr << "\n" << console_format(Disa::Log_Level::Error, std::source_location::current()) << (message) << std::endl

/**
* \brief Checks for a true condition, if not, writes an error message to screen and exits the program.
* \param[in] condition The condition to check.
* \param[in] message The error message to print to the error stream if the condition is false.
*/
#define ASSERT(condition, message) do {if(!(condition)) {ERROR((message)); exit(1);} } while(0)
#define ASSERT(condition, message) \
do { \
if(!(condition)) { \
ERROR((message)); \
exit(1); \
} \
} while(0)

#ifdef DISA_DEBUG
/**
Expand All @@ -113,14 +125,16 @@ inline std::basic_string<char> console_format(const Log_Level level, const std::
*/
#define ASSERT_DEBUG(condition, message) ASSERT(condition, message)
#else
#define ASSERT_DEBUG(condition, exception) {}
#define ASSERT_DEBUG(condition, exception) \
{}
#endif

// ---------------------------------------------------------------------------------------------------------------------
// Types
// ---------------------------------------------------------------------------------------------------------------------

using s_size_t = std::make_signed<std::size_t>::type; //!< Used for static casting where needed, and to prevent compile warnings (if you are using a signed type for size_t, you are doing something wrong).
using s_size_t = std::make_signed<std::size_t>::
type; //!< Used for static casting where needed, and to prevent compile warnings (if you are using a signed type for size_t, you are doing something wrong).

// ---------------------------------------------------------------------------------------------------------------------
// Looping Macros
Expand All @@ -129,14 +143,15 @@ using s_size_t = std::make_signed<std::size_t>::type; //!< Used for static ca
/**
* \brief Maco to select the correct macro based on the number of arguments (allows macro overloading).
*/
#define GET_MACRO(_1, _2, _3, NAME,...) NAME
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME

/**
* \brief Traditional integer type for-loop macro, will start at 0, and end at max_iter - 1.
* \param[in, out] index The for loop index.
* \param[in] max_iter Maximum number of iterations.
*/
#define FOR_INDEX(index, max_iter) for(auto (index) = static_cast<decltype(max_iter)>(0); (index) < (max_iter); ++(index))
#define FOR_INDEX(index, max_iter) \
for(auto(index) = static_cast<decltype(max_iter)>(0); (index) < (max_iter); ++(index))

/**
* \brief Traditional integer type for loop, by loops between two values either incrementally or decrementally .
Expand All @@ -146,7 +161,8 @@ using s_size_t = std::make_signed<std::size_t>::type; //!< Used for static ca
*
* Note if the start < end the loop will increment, else decrement.
*/
#define FOR_INDEX_RANGE(index, start, end) for(auto (index) = (start); (index) != (end); (start) < (end) ? ++(index) : --(index))
#define FOR_INDEX_RANGE(index, start, end) \
for(auto(index) = (start); (index) != (end); (start) < (end) ? ++(index) : --(index))

/**
* \brief Selects either the index or ranged index for loop macros, see descriptions.
Expand All @@ -158,30 +174,29 @@ using s_size_t = std::make_signed<std::size_t>::type; //!< Used for static ca
* \param[in, out] element Constant reference to the elements in the container.
* \param[in] container Container to loop over
*/
#define FOR_EACH(element, container) for(const auto& (element) : (container))
#define FOR_EACH(element, container) for(const auto&(element) : (container))

/**
* \brief Range based for-loop macro
* \param[in, out] element reference to the elements in the container.
* \param[in] container Container to loop over
*/
#define FOR_EACH_REF(element, container) for(auto& (element) : (container))
#define FOR_EACH_REF(element, container) for(auto&(element) : (container))

/**
* \brief Iterator based for-loop macro
* \param[in, out] iter Constant reference to the elements in the container.
* \param[in] container Container acquire the iterator from, must have cbegin() and cend() functions.
*/
#define FOR_ITER(iter, container) for(auto (iter) = (container).cbegin(); (iter) != (container).cend(); ++(iter))
#define FOR_ITER(iter, container) for(auto(iter) = (container).cbegin(); (iter) != (container).cend(); ++(iter))

/**
* \brief Iterator based for-loop macro
* \param[in, out] iter Reference to the elements in the container.
* \param[in] container Container acquire the iterator from, must have cbegin() and cend() functions.
*/
#define FOR_ITER_REF(iter, container) for(auto (iter) = (container).begin(); (iter) != (container).end(); ++(iter))

#define FOR_ITER_REF(iter, container) for(auto(iter) = (container).begin(); (iter) != (container).end(); ++(iter))

}//Disa
} // namespace Disa

#endif //DISA_MACROS_H
#endif //DISA_MACROS_H
Loading
Loading