~ fixed all clang-tidy errors

This commit is contained in:
Julian Hinxlage 2019-11-27 13:39:16 +01:00
parent 0eee01d4c6
commit 39a9fd4bbf
8 changed files with 31 additions and 32 deletions

View File

@ -23,6 +23,7 @@ include_directories(test)
add_library(library ${SOURCES} ${HEADERS}) add_library(library ${SOURCES} ${HEADERS})
file(COPY "${CMAKE_SOURCE_DIR}/src/" file(COPY "${CMAKE_SOURCE_DIR}/src/"
DESTINATION "${CMAKE_SOURCE_DIR}/include" DESTINATION "${CMAKE_SOURCE_DIR}/include"
FILES_MATCHING FILES_MATCHING

View File

@ -8,8 +8,6 @@ namespace vkvm {
Color::Color(unsigned char red, unsigned char green, unsigned char blue) noexcept Color::Color(unsigned char red, unsigned char green, unsigned char blue) noexcept
: red(red), green(green), blue(blue) {} : red(red), green(green), blue(blue) {}
Color::Color(const Color &color) noexcept = default;
Color::Color(unsigned int hex) noexcept { Color::Color(unsigned int hex) noexcept {
red = (unsigned char) ((hex >> 16 & 0xFF));//NOLINT red = (unsigned char) ((hex >> 16 & 0xFF));//NOLINT
green = (unsigned char) ((hex >> 8u & 0xFF));//NOLINT green = (unsigned char) ((hex >> 8u & 0xFF));//NOLINT

View File

@ -20,10 +20,8 @@ namespace vkvm {
Color(unsigned char red, unsigned char green, unsigned char blue) noexcept; Color(unsigned char red, unsigned char green, unsigned char blue) noexcept;
Color(const Color &color) noexcept;
explicit Color(unsigned int hex) noexcept; explicit Color(unsigned int hex) noexcept;
auto getRed() -> unsigned char; auto getRed() -> unsigned char;
auto getGreen() -> unsigned char; auto getGreen() -> unsigned char;

View File

@ -84,13 +84,13 @@ namespace vkvm {
return getLocalMemory(); return getLocalMemory();
} }
char *ptr = static_cast<char *>(shmat(shmId, nullptr, 0)); char *ptr = static_cast<char *>(shmat(shmId, nullptr, 0));
if((size_t)ptr == (size_t)-1){ if(reinterpret_cast<size_t>(ptr) == static_cast<size_t>(-1)){
log(LogLevel::WARNING, strerror(errno)); log(LogLevel::WARNING, strerror(errno));
return getLocalMemory();
}else{ }else{
impl.sharedMemory = ptr; impl.sharedMemory = ptr;
return ptr; return ptr;
} }
return getLocalMemory();
} }
auto getSharedMemory(char *address, int size, int offset) -> void { auto getSharedMemory(char *address, int size, int offset) -> void {

View File

@ -16,7 +16,7 @@ namespace vkvm {
signal(signalNumber, callback); signal(signalNumber, callback);
} }
auto getInterrupTable() -> InterruptEntry * { auto getInterruptTable() -> InterruptEntry * {
return reinterpret_cast<InterruptEntry *>(getSharedMemory() + sizeof(Registers) + impl.reservedSize); return reinterpret_cast<InterruptEntry *>(getSharedMemory() + sizeof(Registers) + impl.reservedSize);
} }

View File

@ -6,10 +6,10 @@
#include "GraphicMode.hpp" #include "GraphicMode.hpp"
#include "KeyCode.hpp" #include "KeyCode.hpp"
#include "LayoutVersion.hpp" #include "LayoutVersion.hpp"
#include <array>
#include <functional> #include <functional>
#include <sys/types.h> #include <sys/types.h>
#include <vector> #include <vector>
#include <array>
namespace vkvm { namespace vkvm {

View File

@ -22,8 +22,8 @@ namespace vkvm {
setMode(GraphicMode::RGB); setMode(GraphicMode::RGB);
setCharactersPerRow(60);// NOLINT setCharactersPerRow(60);// NOLINT
setCharactersPerColumn(20);// NOLINT setCharactersPerColumn(20);// NOLINT
setHeight(60);// NOLINT setHeight(600);// NOLINT
setWidth(80);// NOLINT setWidth(800);// NOLINT
setMousePosition(42, 42);// NOLINT setMousePosition(42, 42);// NOLINT
setBackgroundColor(black); setBackgroundColor(black);
setForegroundColor(white); setForegroundColor(white);
@ -65,46 +65,47 @@ namespace vkvm {
auto setPixel(int x, int y, Color color) -> bool { auto setPixel(int x, int y, Color color) -> bool {
lockSharedMemory(); lockSharedMemory();
auto reg = getRegisters(); auto reg = getRegisters();
const int bitsPerPixel = 8;
switch(reg->graphicMode) { switch(reg->graphicMode) {
case Text: { case Text: {
int pixelIndex = (y * getWidth() + x); int pixelIndex = (y * getWidth() + x);
unsigned char *ptr = reinterpret_cast<unsigned char *>(getPixelArea()) + (pixelIndex / 8); unsigned char *ptr = reinterpret_cast<unsigned char *>(getPixelArea()) + (pixelIndex / bitsPerPixel);
if(color == reg->foreground_color){ if(color == reg->foreground_color){
//set bit to 1 //set bit to 1
ptr[0] |= (1 << (pixelIndex % 8)); ptr[0] |= (1 << (pixelIndex % bitsPerPixel));
} }
else{ else{
//set bit to 0 //set bit to 0
ptr[0] &= ~(1 << (pixelIndex % 8)); ptr[0] &= ~(1 << (pixelIndex % bitsPerPixel));
} }
break; break;
} }
case TwoColors: { case TwoColors: {
int pixelIndex = (y * getWidth() + x); int pixelIndex = (y * getWidth() + x);
unsigned char *ptr = reinterpret_cast<unsigned char *>(getPixelArea()) + (pixelIndex / 8); unsigned char *ptr = reinterpret_cast<unsigned char *>(getPixelArea()) + (pixelIndex / bitsPerPixel);
if(color == reg->foreground_color){ if(color == reg->foreground_color){
//set bit to 1 //set bit to 1
ptr[0] |= (1 << (pixelIndex % 8)); ptr[0] |= (1 << (pixelIndex % bitsPerPixel));
} }
else{ else{
//set bit to 0 //set bit to 0
ptr[0] &= ~(1 << (pixelIndex % 8)); ptr[0] &= ~(1 << (pixelIndex % bitsPerPixel));
} }
break; break;
} }
case Gray_256: { case Gray_256: {
unsigned char *ptr = reinterpret_cast<unsigned char *>(getPixelArea()) + (y * getWidth() + x) * 1; unsigned char *ptr = reinterpret_cast<unsigned char *>(getPixelArea()) + (y * getWidth() + x);
int avg = color.getRed() + color.getGreen() + color.getBlue(); int avg = color.getRed() + color.getGreen() + color.getBlue();
avg /= 3; avg /= 3;
ptr[0] = (unsigned char)avg; ptr[0] = avg;
break; break;
} }
case RGB: { case RGB: {
unsigned char *ptr = reinterpret_cast<unsigned char *>(getPixelArea()) + (y * getWidth() + x) * 3; unsigned char *ptr = reinterpret_cast<unsigned char *>(getPixelArea()) + (y * getWidth() + x) * 3;
ptr[0] = (unsigned char)color.getRed(); ptr[0] = color.getRed();
ptr[1] = (unsigned char)color.getGreen(); ptr[1] = color.getGreen();
ptr[2] = (unsigned char)color.getBlue(); ptr[2] = color.getBlue();
break; break;
} }
} }
@ -115,12 +116,13 @@ namespace vkvm {
auto getPixel(int x, int y) -> Color { auto getPixel(int x, int y) -> Color {
Color color = Color(0,0,0); Color color = Color(0,0,0);
auto reg = getRegisters(); auto reg = getRegisters();
const int bitsPerPixel = 8;
switch(reg->graphicMode) { switch(reg->graphicMode) {
case Text: { case Text: {
int pixelIndex = (y * getWidth() + x); int pixelIndex = (y * getWidth() + x);
unsigned char *ptr = reinterpret_cast<unsigned char *>(getPixelArea()) + pixelIndex / 8; unsigned char *ptr = reinterpret_cast<unsigned char *>(getPixelArea()) + pixelIndex / bitsPerPixel;
bool bit = (bool)(ptr[0] & (1 << (pixelIndex % 8))); bool bit = static_cast<bool>(ptr[0] & (1 << (pixelIndex % bitsPerPixel)));
if(bit){ if(bit){
color = reg->foreground_color; color = reg->foreground_color;
}else{ }else{
@ -130,8 +132,8 @@ namespace vkvm {
} }
case TwoColors: { case TwoColors: {
int pixelIndex = (y * getWidth() + x); int pixelIndex = (y * getWidth() + x);
unsigned char *ptr = reinterpret_cast<unsigned char *>(getPixelArea()) + (pixelIndex / 8); unsigned char *ptr = reinterpret_cast<unsigned char *>(getPixelArea()) + (pixelIndex / bitsPerPixel);
bool bit = (bool)(ptr[0] & (1 << (pixelIndex % 8))); bool bit = static_cast<bool>(ptr[0] & (1 << (pixelIndex % bitsPerPixel)));
if(bit){ if(bit){
color = reg->foreground_color; color = reg->foreground_color;
}else{ }else{
@ -260,7 +262,7 @@ namespace vkvm {
return getRegisters()->background_color; return getRegisters()->background_color;
} }
auto setBackgroundColor(Color newValue) -> void { auto setBackgroundColor(const Color &newValue) -> void {
lockSharedMemory(); lockSharedMemory();
getRegisters()->background_color = newValue; getRegisters()->background_color = newValue;
unlockSharedMemory(); unlockSharedMemory();
@ -270,7 +272,7 @@ namespace vkvm {
return getRegisters()->foreground_color; return getRegisters()->foreground_color;
} }
auto setForegroundColor(Color newValue) -> void { auto setForegroundColor(const Color &newValue) -> void {
lockSharedMemory(); lockSharedMemory();
getRegisters()->foreground_color = newValue; getRegisters()->foreground_color = newValue;
unlockSharedMemory(); unlockSharedMemory();
@ -302,10 +304,10 @@ namespace vkvm {
auto getLastPressedKey() -> KeyCode { auto getLastPressedKey() -> KeyCode {
lockSharedMemory(); lockSharedMemory();
KeyCode keyCode = KeyCode(0); auto keyCode = KeyCode(0);
auto reg = getRegisters(); auto reg = getRegisters();
if(reg->keyboardBuffer_index_read != reg->keyboardBuffer_index_write) { if(reg->keyboardBuffer_index_read != reg->keyboardBuffer_index_write) {
keyCode = (KeyCode) reg->keyboardBuffer[reg->keyboardBuffer_index_read++]; keyCode = static_cast<KeyCode>(reg->keyboardBuffer[reg->keyboardBuffer_index_read++]);
if (reg->keyboardBuffer_index_read >= sizeof(reg->keyboardBuffer)) { if (reg->keyboardBuffer_index_read >= sizeof(reg->keyboardBuffer)) {
reg->keyboardBuffer_index_read = 0; reg->keyboardBuffer_index_read = 0;
} }

View File

@ -153,7 +153,7 @@ namespace vkvm {
* set background color in two color mode. * set background color in two color mode.
* @param newValue new background color. * @param newValue new background color.
*/ */
auto setBackgroundColor(Color newValue) -> void; auto setBackgroundColor(const Color &newValue) -> void;
/** /**
* get foreground color in two color mode. * get foreground color in two color mode.
@ -165,7 +165,7 @@ namespace vkvm {
* set foreground color in two color mode. * set foreground color in two color mode.
* @param newValue new foreground color. * @param newValue new foreground color.
*/ */
auto setForegroundColor(Color newValue) -> void; auto setForegroundColor(const Color &newValue) -> void;
//text mode //text mode