diff --git a/src/config.cpp b/src/config.cpp new file mode 100644 index 0000000..a3d98fd --- /dev/null +++ b/src/config.cpp @@ -0,0 +1,25 @@ +#include "config.hpp" +#include +#include +#include +#include +#include + +Config get_config(const std::string &CONFIG_FILE) { + toml::table toml_table; + try { + toml_table = toml::parse_file(CONFIG_FILE); + } catch (const toml::parse_error &err) { + std::cerr << "Parsing failed:" << std::endl << err << std::endl; + } + + Contact contact = { + toml_table["contact"]["author"].value_or(""), + toml_table["contact"]["email"].value_or(""), + toml_table["contact"]["signal"].value_or(""), + }; + + Config config = {contact}; + + return config; +} diff --git a/src/config.hpp b/src/config.hpp new file mode 100644 index 0000000..019ce6f --- /dev/null +++ b/src/config.hpp @@ -0,0 +1,14 @@ +#pragma once +#include + +struct Contact { + std::string author; + std::string email; + std::string signal; +}; + +struct Config { + Contact contact; +}; + +Config get_config(const std::string &CONFIG_FILE); diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..05f0262 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,14 @@ +#include "config.hpp" +#include +#include + +int main() { return 0; } + +void test_config_read() { + const std::string CONFIG_PATH = "../config/config_example.toml"; + Config config = get_config(CONFIG_PATH); + std::cout << "Config" << std::endl; + std::cout << "Author: " << config.contact.author << std::endl; + std::cout << "Email: " << config.contact.email << std::endl; + std::cout << "Signal: " << config.contact.signal << std::endl; +} diff --git a/src/makefile b/src/makefile new file mode 100644 index 0000000..85c9f51 --- /dev/null +++ b/src/makefile @@ -0,0 +1,16 @@ +CXX = g++ +CXXFLAGS = -std=c++17 -Wall + +all: blog + +blog: main.o config.o + $(CXX) $(CXXFLAGS) main.o config.o -o blog + +main.o: main.cpp config.hpp + $(CXX) $(CXXFLAGS) -c main.cpp + +config.o: config.cpp config.hpp + $(CXX) $(CXXFLAGS) -c config.cpp + +clean: + rm -f *.o blog