From c1c08ca546271fd6536b26028d807c2c39743db1 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Wed, 13 Nov 2019 15:42:04 +0100 Subject: [PATCH] ~fixed all clang-tidy erros --- .ci/clang-tidy.sh | 2 +- .clang-tidy | 2 ++ CMakeLists.txt | 2 +- src/FontType.cpp | 8 ++------ src/FontType.hpp | 8 +++----- src/GraphicMode.hpp | 2 +- src/SharedMemoryAccess.cpp | 21 ++++++--------------- src/internal.cpp | 2 -- src/internal.hpp | 17 ++++++++++------- src/log.hpp | 2 +- src/vkvm.cpp | 2 +- src/vkvm.hpp | 2 +- 12 files changed, 29 insertions(+), 41 deletions(-) create mode 100644 .clang-tidy diff --git a/.ci/clang-tidy.sh b/.ci/clang-tidy.sh index 2e1b4e7..e5861a2 100755 --- a/.ci/clang-tidy.sh +++ b/.ci/clang-tidy.sh @@ -9,7 +9,7 @@ filelist="$(find . -not \( -path './*build*' -prune \) -not \( -path './include' for file in $filelist; do if echo "$file" | grep -q -E ".*(\.cpp|\.h|\.hpp)$" ; then #Extra check missing dependencies due to clang-tidy doesn't toggle exit code. - clang_tidy_lib_check="$(clang-tidy -warnings-as-errors='*' -header-filter='.*,-cpptoml.hpp' -checks='*,-llvm-header-guard,-fuchsia-statically-constructed-objects,-fuchsia*,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-bounds-constant-array-index,-bugprone-narrowing-conversions,-cppcoreguidelines-narrowing-conversions,-cppcoreguidelines-pro-type-const-cast,-cppcoreguidelines-pro-type-reinterpret-cast,-hicpp-signed-bitwise,-bugprone-exception-escape,-cppcoreguidelines-pro-type-member-init,-cppcoreguidelines-pro-type-cstyle-cast,-hicpp-member-init,-google-readability-namespace-comments,-llvm-namespace-comment' "$file" -- -I. -std=c++14 2>&1)" + clang_tidy_lib_check="$(clang-tidy -warnings-as-errors='*' --color -header-filter='.*,-cpptoml.hpp' "$file" -- -I. -std=c++14 2>&1)" for tidy_line in $clang_tidy_lib_check; do echo "$tidy_line" | grep -q -v -E "^Error while processing*" if [ $? -eq 1 ]; then diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..ab0e4e1 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,2 @@ +Checks: '*,-llvm-header-guard,-fuchsia*,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-bounds-constant-array-index,-bugprone-narrowing-conversions,-cppcoreguidelines-narrowing-conversions,-cppcoreguidelines-pro-type-const-cast,-cppcoreguidelines-pro-type-reinterpret-cast,-hicpp-signed-bitwise,-bugprone-exception-escape,-cppcoreguidelines-pro-type-member-init,-cppcoreguidelines-pro-type-cstyle-cast,-hicpp-member-init,-google-readability-namespace-comments,-llvm-namespace-comment,-cppcoreguidelines-pro-type-vararg,-hicpp-vararg' +WarningsAsErrors: 'true' \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index ba82a8c..2b261c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ set(CMAKE_CXX_STANDARD 14) # enable clang_tidy set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-checks=*") -set(CMAKE_CXX_CLANG_TIDY clang-tidy;-header-filter=.;-checks=*;) +set(CMAKE_CXX_CLANG_TIDY clang-tidy;-header-filter=.;) file(GLOB_RECURSE SOURCES src/*.cpp) diff --git a/src/FontType.cpp b/src/FontType.cpp index 46ebb00..5e69054 100644 --- a/src/FontType.cpp +++ b/src/FontType.cpp @@ -2,11 +2,7 @@ namespace vkvm { - FontType::FontType(int id, std::string name, int height, int width) noexcept { - this->id = id; - this->name = std::move(name); - this->height = height; - this->width = width; + FontType::FontType(int id, const char * name, int height, int width) noexcept : id(id), name(name), height(height), width(width) { } auto FontType::getId() const -> int { @@ -14,7 +10,7 @@ namespace vkvm { } auto FontType::getName() const -> std::string { - return name; + return std::string(name); } auto FontType::getHeight() const -> int { diff --git a/src/FontType.hpp b/src/FontType.hpp index defecf0..349abd1 100644 --- a/src/FontType.hpp +++ b/src/FontType.hpp @@ -10,12 +10,12 @@ namespace vkvm { class FontType { private: int id; - std::string name; + const char * name; int height; int width; public: - FontType(int id, std::string name, int height, int width) noexcept; + FontType(int id, const char * name, int height, int width) noexcept; auto getId() const -> int; @@ -27,9 +27,7 @@ namespace vkvm { }; - - const static FontType font_1 = FontType(1, "DummyFont", 10, 5); - + static const FontType font_1 = FontType(1, "DummyFont", 10, 5); } #endif diff --git a/src/GraphicMode.hpp b/src/GraphicMode.hpp index c28b205..92d51d7 100644 --- a/src/GraphicMode.hpp +++ b/src/GraphicMode.hpp @@ -12,7 +12,7 @@ namespace vkvm { Text = 1, TwoColors = 2, Gray_256 = 3, - TrueColor = 4, + RGB = 4 }; } diff --git a/src/SharedMemoryAccess.cpp b/src/SharedMemoryAccess.cpp index ff68a4d..697b5b0 100644 --- a/src/SharedMemoryAccess.cpp +++ b/src/SharedMemoryAccess.cpp @@ -37,7 +37,7 @@ namespace vkvm { return -1; } /* Semaphor mit 1 initialisieren */ - if (semctl(semId, 0, SETVAL, 1) == -1){ + if (semctl(semId, 0, SETVAL, 1) == -1) { return -1; } } @@ -61,26 +61,17 @@ namespace vkvm { } auto getSharedMemory() -> char * { - bool useLocal = false; - - if(!useLocal){ - int shmId = shmget(impl.sharedMemoryKey, NULL, 0); - if(shmId < 0) { - //no shared memory found - useLocal = true; - } else { - return (char *) shmat(shmId, NULL, 0); - } - } - - if(useLocal) { + int shmId = shmget(impl.sharedMemoryKey, 0, 0); + if (shmId < 0) { //using a local buffer for shared memory testing if (localSharedMemory.empty()) { initSemaphore(); - localSharedMemory.resize(impl.sharedMemorySize * 1024); + constexpr int kilo = 1024; + localSharedMemory.resize(impl.sharedMemorySize * kilo); } return &localSharedMemory[0]; } + return static_cast(shmat(shmId, nullptr, 0)); } auto getSharedMemory(char *address, int size, int offset) -> void { diff --git a/src/internal.cpp b/src/internal.cpp index 88d167a..82b515a 100644 --- a/src/internal.cpp +++ b/src/internal.cpp @@ -3,8 +3,6 @@ #include "vkvm.hpp" #include -#include - namespace vkvm { diff --git a/src/internal.hpp b/src/internal.hpp index af86223..d237f92 100644 --- a/src/internal.hpp +++ b/src/internal.hpp @@ -1,14 +1,14 @@ #ifndef LIBRARY_INTERNAL_HPP #define LIBRARY_INTERNAL_HPP +#include "Color.hpp" #include "EventType.hpp" +#include "GraphicMode.hpp" #include "KeyCode.hpp" #include "LayoutVersion.hpp" -#include "GraphicMode.hpp" -#include "Color.hpp" +#include #include #include -#include namespace vkvm { @@ -17,6 +17,9 @@ namespace vkvm { * @author Julian Hinxlage * @since 0.1.0 */ + +constexpr int keyboardBufferSize = 16; + struct Registers { int layout_version; int trigger_reset; @@ -34,7 +37,7 @@ namespace vkvm { int textMode_font_height; int mouse_pos_x; int mouse_pos_y; - short keyboardBuffer[16]; + std::array keyboardBuffer; int keyboardBuffer_index_write; int keyboardBuffer_index_read; }; @@ -51,8 +54,8 @@ namespace vkvm { int sharedMemoryPid; key_t sharedMemoryKey; int sharedMemorySize; - int interruptEntyCount = 64; - int reservedSize = 1024; + int interruptEntyCount = 64; //NOLINT + int reservedSize = 1024; //NOLINT std::vector> eventTable; }; @@ -76,7 +79,7 @@ namespace vkvm { auto getRegisters() -> Registers *; - auto getTextArea() -> char * ; + auto getTextArea() -> char *; auto getPixelArea() -> char *; diff --git a/src/log.hpp b/src/log.hpp index 311bef8..8d80990 100644 --- a/src/log.hpp +++ b/src/log.hpp @@ -1,8 +1,8 @@ #ifndef LIBRARY_LOG_HPP #define LIBRARY_LOG_HPP -#include #include +#include namespace vkvm { enum LogLevel{ diff --git a/src/vkvm.cpp b/src/vkvm.cpp index 5b0390b..3493667 100644 --- a/src/vkvm.cpp +++ b/src/vkvm.cpp @@ -25,7 +25,7 @@ namespace vkvm { setMousePosition(42, 42);// NOLINT setBackgroundColor(Color(200, 50, 20));// NOLINT setForegroundColor(Color(20, 200, 50));// NOLINT - setMode(GraphicMode::TrueColor);// NOLINT + setMode(GraphicMode::RGB);// NOLINT setRedrawInterval(20);// NOLINT setTimerInterruptInterval(10);// NOLINT } diff --git a/src/vkvm.hpp b/src/vkvm.hpp index e403b29..8f86e7f 100644 --- a/src/vkvm.hpp +++ b/src/vkvm.hpp @@ -3,8 +3,8 @@ #include "Color.hpp" #include "EventType.hpp" -#include "GraphicMode.hpp" #include "FontType.hpp" +#include "GraphicMode.hpp" #include "KeyCode.hpp" #include "LayoutVersion.hpp" #include "log.hpp"