~ 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})
file(COPY "${CMAKE_SOURCE_DIR}/src/"
DESTINATION "${CMAKE_SOURCE_DIR}/include"
FILES_MATCHING

View File

@ -8,8 +8,6 @@ namespace vkvm {
Color::Color(unsigned char red, unsigned char green, unsigned char blue) noexcept
: red(red), green(green), blue(blue) {}
Color::Color(const Color &color) noexcept = default;
Color::Color(unsigned int hex) noexcept {
red = (unsigned char) ((hex >> 16 & 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(const Color &color) noexcept;
explicit Color(unsigned int hex) noexcept;
auto getRed() -> unsigned char;
auto getGreen() -> unsigned char;

View File

@ -84,13 +84,13 @@ namespace vkvm {
return getLocalMemory();
}
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));
return getLocalMemory();
}else{
impl.sharedMemory = ptr;
return ptr;
}
return getLocalMemory();
}
auto getSharedMemory(char *address, int size, int offset) -> void {

View File

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

View File

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

View File

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

View File

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