From b9e96d1b28eb5fa69f5c8e572e13695669354b23 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 7 Jun 2022 16:54:43 +0200 Subject: Renamed internal common to config --- config/CMakeLists.txt | 7 +++++++ config/include/hwd/config.h | 18 ++++++++++++++++++ config/src/config.cpp | 27 +++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 config/CMakeLists.txt create mode 100644 config/include/hwd/config.h create mode 100644 config/src/config.cpp (limited to 'config') diff --git a/config/CMakeLists.txt b/config/CMakeLists.txt new file mode 100644 index 0000000..7fbe117 --- /dev/null +++ b/config/CMakeLists.txt @@ -0,0 +1,7 @@ +project(config CXX) +add_library(${PROJECT_NAME} STATIC + src/config.cpp + ) +target_include_directories(${PROJECT_NAME} + PUBLIC include + ) diff --git a/config/include/hwd/config.h b/config/include/hwd/config.h new file mode 100644 index 0000000..7f42cb5 --- /dev/null +++ b/config/include/hwd/config.h @@ -0,0 +1,18 @@ +#pragma once + +namespace hwd +{ +namespace config +{ + +constexpr int default_port = 4236; +constexpr const char * default_host = "127.0.0.1"; + +constexpr const char * port_variable = "HWDPORT"; +constexpr const char * host_variable = "HWDHOST"; + +int port(); +const char * host(); + +} // namespace config +} // namespace hwd diff --git a/config/src/config.cpp b/config/src/config.cpp new file mode 100644 index 0000000..8895a24 --- /dev/null +++ b/config/src/config.cpp @@ -0,0 +1,27 @@ +#include "hwd/config.h" + +#include + + +namespace hwd +{ +namespace config +{ + +int port() +{ + if (const char * from_env = std::getenv(port_variable)) + if (int port_number = std::atoi(from_env)) + return port_number; + return default_port; +} + +const char * host() +{ + if (const char * from_env = std::getenv(host_variable)) + return from_env; + return default_host; +} + +} // namespace config +} // namespace hwd -- cgit v1.1