Toml eingebunden, Configfile erstellt und configuriert, Bugfix

This commit is contained in:
@Nurullah.Damla 2019-11-21 12:54:50 +01:00
parent 4a63787d11
commit b39a194319
4 changed files with 68 additions and 0 deletions

View File

@ -10,6 +10,8 @@ set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "bin" "doc" "
project(Shared_Memory)
set(CMAKE_CXX_STANDARD 14)
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
set(CMAKE_CXX_COMPILER "clang++")
file(GLOB_RECURSE SOURCES src/*.cpp)
file(GLOB_RECURSE HEADERS src/*.hpp)
@ -32,3 +34,6 @@ target_link_libraries(UnitTests Catch2::Catch2)
include(CTest)
include(Catch)
catch_discover_tests(UnitTests)
#toml
include_directories(lib/toml)

15
res/config.toml Normal file
View File

@ -0,0 +1,15 @@
#defaultKey = 12345
newKey = 0
layoutVersion = 0
width = 0
height = 0
mode = 0
redrawInterval = 0
timerInterruptInterval = 0
backgroundColor = 0
foregroundColor = 0
charactersPerRow = 0
charactersPerColumn = 0
font = 0
mousePositionX = 0
mousePositionY = 0

View File

@ -2,6 +2,11 @@
#include "SharedMemory.h"
#include <iostream>
#include <fstream>
#include <cpptoml.h>
#include <vkvm.hpp>
key_t changedKey()
{
@ -15,6 +20,10 @@ key_t changedKey()
std::cout <<"New Key is -> " << newKey << std::endl;
keyFile << newKey;
keyFile.close();
auto config = cpptoml::parse_file("res/config.toml");
newKey = config->get_as<int>("newKey").value_or(0); //toml
return key_t(newKey);
}
@ -83,3 +92,40 @@ void deleteSharedMemory(void)
}
}
void getConfig(){
auto config = cpptoml::parse_file("res/config.toml");
int layoutVersion = config->get_as<int>("layoutVersion").value_or(0);
int width = config->get_as<int>("width").value_or(0);
int height = config->get_as<int>("height").value_or(0);
int mode = config->get_as<int>("mode").value_or(0);
int timerInterruptInterval = config->get_as<int>("timerInterruptInterval").value_or(0);
int backgroundColor = config->get_as<int>("backgroundColor").value_or(0);
int foregroundColor = config->get_as<int>("foregroundColor").value_or(0);
int charactersPerRow = config->get_as<int>("charactersPerRow").value_or(0);
int charactersPerColumn = config->get_as<int>("charactersPerColumn").value_or(0);
int font = config->get_as<int>("font").value_or(0);
int mousePositionX = config->get_as<int>("mousePositionX").value_or(0);
int mousePositionY = config->get_as<int>("mousePositionY").value_or(0);
/*
//convert to hex
std::string result;
std::stringstream ss;
ss << std::hex << result;
ss >> result;
*/
vkvm::setLayoutVersion((vkvm::LayoutVersion) layoutVersion);
vkvm::setWidth(width);
vkvm::setHeight(height);
vkvm::setMode((vkvm::GraphicMode) mode);
vkvm::setTimerInterruptInterval(timerInterruptInterval);
vkvm::setBackgroundColor(vkvm::Color(backgroundColor));
vkvm::setForegroundColor(vkvm::Color(foregroundColor));
vkvm::setCharactersPerRow(charactersPerRow);
vkvm::setCharactersPerColumn(charactersPerColumn);
vkvm::setFont(vkvm::FontType(font,"",0,0));
vkvm::setMousePosition(mousePositionX, mousePositionY);
}

View File

@ -14,4 +14,6 @@ void deleteSharedMemory(void);
void initSharedMemory(void);
key_t changedKey();
std::string getAnswerFromUser();
//Config File
#define configFile "res/config.toml";
#endif //SHARED_MEMORY_H