From 9bdbfa29697b2e6ed39c58d6af0ae98a248178a7 Mon Sep 17 00:00:00 2001 From: Kacper Doga Date: Sun, 7 Dec 2025 01:56:01 +0100 Subject: [PATCH 01/37] feat(agent): setup CI pipeline, CMake formatting targets & code stubs (#15) * build: add format target to cmake * ci: add github workflow for build & formatting * test(agent): add NVML stub for CI environments Introduced a dummy implementation of NVML functions (Init, Shutdown,DeviceGetHandle, etc.) to allow the agent to compile and link successfully on CI runners (Ubuntu) where NVIDIA drivers are missing. This stub is conditionally linked via CMake when the system NVML library is not found. * style(agent): reformat agent codebase to pass CI Agent check * chore: add reformat commit to ignore-revs, fix cmake to check google format, clean agent ci --- .git-blame-ignore-revs | 2 + .github/workflows/agent_ci.yml | 52 +++++ .gitignore | 3 +- CMakeLists.txt | 30 ++- libs/stubs/nvml_stub.cc | 81 ++++++++ source/agent/CMakeLists.txt | 19 +- source/agent/src/collectors/collector.h | 18 +- source/agent/src/collectors/nvml_collector.cc | 157 +++++++-------- source/agent/src/collectors/nvml_collector.h | 27 +-- .../src/collectors/proc_stat_collector.cc | 80 ++++---- .../src/collectors/proc_stat_collector.h | 20 +- source/agent/src/collectors/ram_collector.cc | 64 +++--- source/agent/src/collectors/ram_collector.h | 18 +- source/agent/src/config/config.h | 81 ++++---- source/agent/src/config/config_loader.cc | 38 ++-- source/agent/src/config/config_loader.h | 18 +- source/agent/src/main.cc | 69 +++---- source/agent/src/metric.h | 14 +- source/agent/src/platform/cpu_info.h | 48 ++--- source/agent/src/platform/gpu_info.h | 32 ++- source/agent/src/platform/hardware_info.h | 22 +- .../agent/src/platform/platform_detector.cc | 190 ++++++++++-------- source/agent/src/platform/platform_detector.h | 18 +- source/agent/src/scheduler.cc | 75 +++---- source/agent/src/scheduler.h | 34 ++-- 25 files changed, 684 insertions(+), 526 deletions(-) create mode 100644 .git-blame-ignore-revs create mode 100644 .github/workflows/agent_ci.yml create mode 100644 libs/stubs/nvml_stub.cc diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs new file mode 100644 index 0000000..68bbb0c --- /dev/null +++ b/.git-blame-ignore-revs @@ -0,0 +1,2 @@ +# Mass reformatting - introducing CI Agent (Issue #14) +433cd2b661a88b143fae6e215a487280a5dedf05 diff --git a/.github/workflows/agent_ci.yml b/.github/workflows/agent_ci.yml new file mode 100644 index 0000000..d7f376d --- /dev/null +++ b/.github/workflows/agent_ci.yml @@ -0,0 +1,52 @@ +name: Agent CI + +on: + push: + branches: [ "main", "devel" ] + paths: + - 'source/agent/**' # If changes are in the agent source code + - 'libs/**' # If changes are in libraries (proto, NVIDIA headers) + - 'CMakeLists.txt' # If changes are in main CMake (affects everything) + - '.github/workflows/agent_ci.yml' + pull_request: + branches: [ "main", "devel" ] + paths: + - 'source/agent/**' + - 'libs/**' + - 'CMakeLists.txt' + - '.github/workflows/agent_ci.yml' + +jobs: + build-and-test: + name: Build & Format Check + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y build-essential cmake \ + libgrpc++-dev libprotobuf-dev protobuf-compiler-grpc \ + libabsl-dev clang-format cppcheck + + - name: Check Code Formatting + run: | + find source/agent -name "*.cc" -o -name "*.h" | xargs clang-format --dry-run --Werror -style=Google + + - name: CMake Configure + run: cmake -B build -S . + + - name: Build + run: cmake --build build --parallel $(nproc) + + - name: Analyze Logic + run: | + cppcheck --enable=warning,performance,portability \ + --error-exitcode=1 \ + --suppress=missingIncludeSystem \ + --inline-suppr \ + --force \ + -i build -i libs \ + source/agent diff --git a/.gitignore b/.gitignore index c90e3cd..7e53678 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .vscode/ + build/ -cmake-build-*/ +bin/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 6800ca1..ff22de7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,15 +2,16 @@ cmake_minimum_required(VERSION 3.16) project(volta LANGUAGES CXX) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -find_package(protobuf CONFIG REQUIRED) +find_package(Protobuf REQUIRED) find_package(gRPC CONFIG REQUIRED) set(PROTO_DIR ${CMAKE_SOURCE_DIR}/libs/proto) set(PROTO_FILE ${PROTO_DIR}/volta.proto) +set(LOCAL_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/libs/include") get_target_property(GRPC_CPP_PLUGIN gRPC::grpc_cpp_plugin LOCATION) @@ -40,5 +41,30 @@ target_include_directories(volta_proto PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) target_link_libraries(volta_proto PRIVATE protobuf::libprotobuf gRPC::grpc++) +include_directories("${LOCAL_INCLUDE_DIR}/nvidia") + add_subdirectory(source/agent) #add_subdirectory(source/server) + +# --- Custom Tools Targets --- +find_program(CLANG_FORMAT_EXE clang-format) + +if(CLANG_FORMAT_EXE) + # clang-format + add_custom_target(format + COMMAND find source/agent -name "*.cc" -o -name "*.h" | xargs ${CLANG_FORMAT_EXE} -i -style=Google + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + COMMENT "Running clang-format on source files..." + VERBATIM + ) + + # optional: check formatting + add_custom_target(check-format + COMMAND find source/agent -name "*.cc" -o -name "*.h" | xargs ${CLANG_FORMAT_EXE} --dry-run --Werror -style=Google + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + COMMENT "Checking code formatting..." + VERBATIM + ) +else() + message(WARNING "clang-format not found! 'make format' will not be available.") +endif() diff --git a/libs/stubs/nvml_stub.cc b/libs/stubs/nvml_stub.cc new file mode 100644 index 0000000..c78c447 --- /dev/null +++ b/libs/stubs/nvml_stub.cc @@ -0,0 +1,81 @@ +/* + * Copyright 2025 Monvit + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +extern "C" { + +nvmlReturn_t nvmlInit_v2() { + return NVML_SUCCESS; +} + +nvmlReturn_t nvmlShutdown() { + return NVML_SUCCESS; +} + +const char* nvmlErrorString(nvmlReturn_t result) { + return "Stub: No Error (Simulation)"; +} + +nvmlReturn_t nvmlDeviceGetHandleByIndex_v2(unsigned int index, nvmlDevice_t* device) { + if (index > 0) { + return NVML_ERROR_INVALID_ARGUMENT; + } + *device = (nvmlDevice_t)0xDEADBEEF; + return NVML_SUCCESS; +} + +nvmlReturn_t nvmlDeviceGetUUID(nvmlDevice_t device, char* uuid, unsigned int length) { + snprintf(uuid, length, "GPU-STUB-0000-0000"); + return NVML_SUCCESS; +} + +nvmlReturn_t nvmlDeviceGetPowerUsage(nvmlDevice_t device, unsigned int* power) { + *power = 0; + return NVML_SUCCESS; +} + +nvmlReturn_t nvmlDeviceGetTemperature(nvmlDevice_t device, nvmlTemperatureSensors_t sensorType, unsigned int* temp) { + *temp = 25; + return NVML_SUCCESS; +} + +nvmlReturn_t nvmlDeviceGetUtilizationRates(nvmlDevice_t device, nvmlUtilization_t* utilization) { + utilization->gpu = 0; + utilization->memory = 0; + return NVML_SUCCESS; +} + +nvmlReturn_t nvmlDeviceGetMemoryInfo(nvmlDevice_t device, nvmlMemory_t* memory) { + memory->total = 8ULL * 1024 * 1024 * 1024; + memory->free = 4ULL * 1024 * 1024 * 1024; + memory->used = 4ULL * 1024 * 1024 * 1024; + return NVML_SUCCESS; +} + +nvmlReturn_t nvmlDeviceGetCount_v2(unsigned int* deviceCount) { + *deviceCount = 1; + return NVML_SUCCESS; +} + +nvmlReturn_t nvmlDeviceGetName(nvmlDevice_t device, char* name, unsigned int length) { + snprintf(name, length, "NVIDIA GeForce RTX 4090 (Stub)"); + return NVML_SUCCESS; +} + +} // extern "C" diff --git a/source/agent/CMakeLists.txt b/source/agent/CMakeLists.txt index 65ea219..46a770a 100644 --- a/source/agent/CMakeLists.txt +++ b/source/agent/CMakeLists.txt @@ -9,7 +9,7 @@ target_include_directories(${AGENT_NAME} PRIVATE src) target_link_libraries(${AGENT_NAME} PRIVATE volta_proto) find_package(Threads REQUIRED) -find_package(protobuf REQUIRED) +find_package(Protobuf REQUIRED) find_package(gRPC REQUIRED) target_link_libraries(${AGENT_NAME} PRIVATE Threads::Threads) @@ -17,26 +17,27 @@ target_link_libraries(${AGENT_NAME} PRIVATE gRPC::grpc++ protobuf::libprotobuf) find_path(NVML_INCLUDE_DIR nvml.h PATHS ${CMAKE_SOURCE_DIR}/libs/include/nvidia - /usr/include - /usr/local/include - /usr/include/nvidia /usr/local/cuda/include - PATH_SUFFIXES nvidia/current gdk ) find_library(NVML_LIBRARY NAMES nvidia-ml nvml - PATHS /usr/lib /usr/lib64 /usr/local/lib /usr/lib/x86_64-linux-gnu - PATH_SUFFIXES nvidia/current + PATHS /usr/lib /usr/lib64 /usr/local/lib ) if(NVML_INCLUDE_DIR AND NVML_LIBRARY) - message(STATUS "Found NVML: ${NVML_LIBRARY}") + message(STATUS "Found Real NVML: ${NVML_LIBRARY}") target_include_directories(${AGENT_NAME} PRIVATE ${NVML_INCLUDE_DIR}) target_link_libraries(${AGENT_NAME} PRIVATE ${NVML_LIBRARY}) target_compile_definitions(${AGENT_NAME} PRIVATE HAVE_NVML) + else() - message(WARNING "NVML not found - the agent will be built without NVIDIA support.") + message(STATUS "NVML library not found. Using STUB for compilation.") + add_library(nvml_stub STATIC ${CMAKE_SOURCE_DIR}/libs/stubs/nvml_stub.cc) + target_include_directories(nvml_stub PRIVATE ${CMAKE_SOURCE_DIR}/libs/include/nvidia) + target_link_libraries(${AGENT_NAME} PRIVATE nvml_stub) + target_compile_definitions(${AGENT_NAME} PRIVATE HAVE_NVML) + target_include_directories(${AGENT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/libs/include/nvidia) endif() # 5. TODO: find rocm_smi and oneapi level_zero diff --git a/source/agent/src/collectors/collector.h b/source/agent/src/collectors/collector.h index 7b692a9..a43c76a 100644 --- a/source/agent/src/collectors/collector.h +++ b/source/agent/src/collectors/collector.h @@ -10,16 +10,16 @@ namespace agent { namespace collectors { class Collector { -public: - virtual ~Collector() = default; - - virtual std::vector Collect() = 0; + public: + virtual ~Collector() = default; - virtual bool Init() { return true; } + virtual std::vector Collect() = 0; + + virtual bool Init() { return true; } }; -} // namespace collectors -} // namespace agent -} // namespace volta +} // namespace collectors +} // namespace agent +} // namespace volta -#endif // VOLTA_AGENT_SRC_COLLECTORS_COLLECTOR_H_ +#endif // VOLTA_AGENT_SRC_COLLECTORS_COLLECTOR_H_ diff --git a/source/agent/src/collectors/nvml_collector.cc b/source/agent/src/collectors/nvml_collector.cc index 15a2912..4d6cddf 100644 --- a/source/agent/src/collectors/nvml_collector.cc +++ b/source/agent/src/collectors/nvml_collector.cc @@ -1,108 +1,89 @@ #include "collectors/nvml_collector.h" -#include #include +#include namespace volta { namespace agent { namespace collectors { NvmlCollector::NvmlCollector() { - // Initialization moved to Init() + // Initialization moved to Init() } NvmlCollector::~NvmlCollector() { - if (initialized_) { - nvmlShutdown(); - } + if (initialized_) { + nvmlShutdown(); + } } bool NvmlCollector::Init() { - nvmlReturn_t result = nvmlInit(); - if (result != NVML_SUCCESS) { - std::cerr << "Failed to initialize NVML: " << nvmlErrorString(result) << std::endl; - return false; - } - - result = nvmlDeviceGetHandleByIndex(0, &device_handle_); - if (result != NVML_SUCCESS) { - std::cerr << "Failed to get device handle: " << nvmlErrorString(result) << std::endl; - return false; - } - - initialized_ = true; - return true; + nvmlReturn_t result = nvmlInit(); + if (result != NVML_SUCCESS) { + std::cerr << "Failed to initialize NVML: " << nvmlErrorString(result) + << std::endl; + return false; + } + + result = nvmlDeviceGetHandleByIndex(0, &device_handle_); + if (result != NVML_SUCCESS) { + std::cerr << "Failed to get device handle: " << nvmlErrorString(result) + << std::endl; + return false; + } + + initialized_ = true; + return true; } std::vector NvmlCollector::Collect() { - if (!initialized_) return {}; - - std::vector metrics; - unsigned int power_mw = 0; - auto now = std::chrono::system_clock::now().time_since_epoch().count(); - - nvmlReturn_t result = nvmlDeviceGetPowerUsage(device_handle_, &power_mw); - - if (result == NVML_SUCCESS) { - metrics.push_back({ - "gpu_0_power_watts", - static_cast(power_mw) / 1000.0, // mW -> W - now - }); - } - - unsigned int temp_c = 0; - result = nvmlDeviceGetTemperature(device_handle_, NVML_TEMPERATURE_GPU, &temp_c); - if (result == NVML_SUCCESS) { - metrics.push_back({ - "gpu_0_temp_celsius", - static_cast(temp_c), - now - }); - } - - nvmlUtilization_t utilization; - result = nvmlDeviceGetUtilizationRates(device_handle_, &utilization); - - if (result == NVML_SUCCESS) { - metrics.push_back({ - "gpu_0_utilization_percent", - static_cast(utilization.gpu), - now - }); - - metrics.push_back({ - "gpu_0_memory_activity_percent", - static_cast(utilization.memory), - now - }); - } - - nvmlMemory_t memory; - result = nvmlDeviceGetMemoryInfo(device_handle_, &memory); - - if (result == NVML_SUCCESS) { - metrics.push_back({ - "gpu_0_memory_total_bytes", - static_cast(memory.total), - now - }); - metrics.push_back({ - "gpu_0_memory_used_bytes", - static_cast(memory.used), - now - }); - double used_percent = (double)memory.used / memory.total * 100.0; - metrics.push_back({ - "gpu_0_memory_used_percent", - used_percent, - now - }); -} - - return metrics; + if (!initialized_) return {}; + + std::vector metrics; + unsigned int power_mw = 0; + auto now = std::chrono::system_clock::now().time_since_epoch().count(); + + nvmlReturn_t result = nvmlDeviceGetPowerUsage(device_handle_, &power_mw); + + if (result == NVML_SUCCESS) { + metrics.push_back({"gpu_0_power_watts", + static_cast(power_mw) / 1000.0, // mW -> W + now}); + } + + unsigned int temp_c = 0; + result = + nvmlDeviceGetTemperature(device_handle_, NVML_TEMPERATURE_GPU, &temp_c); + if (result == NVML_SUCCESS) { + metrics.push_back({"gpu_0_temp_celsius", static_cast(temp_c), now}); + } + + nvmlUtilization_t utilization; + result = nvmlDeviceGetUtilizationRates(device_handle_, &utilization); + + if (result == NVML_SUCCESS) { + metrics.push_back({"gpu_0_utilization_percent", + static_cast(utilization.gpu), now}); + + metrics.push_back({"gpu_0_memory_activity_percent", + static_cast(utilization.memory), now}); + } + + nvmlMemory_t memory; + result = nvmlDeviceGetMemoryInfo(device_handle_, &memory); + + if (result == NVML_SUCCESS) { + metrics.push_back( + {"gpu_0_memory_total_bytes", static_cast(memory.total), now}); + metrics.push_back( + {"gpu_0_memory_used_bytes", static_cast(memory.used), now}); + double used_percent = (double)memory.used / memory.total * 100.0; + metrics.push_back({"gpu_0_memory_used_percent", used_percent, now}); + } + + return metrics; } -} // namespace collectors -} // namespace agent -} // namespace volta +} // namespace collectors +} // namespace agent +} // namespace volta diff --git a/source/agent/src/collectors/nvml_collector.h b/source/agent/src/collectors/nvml_collector.h index a732675..7223e34 100644 --- a/source/agent/src/collectors/nvml_collector.h +++ b/source/agent/src/collectors/nvml_collector.h @@ -1,28 +1,29 @@ #ifndef VOLTA_AGENT_SRC_COLLECTORS_NVML_COLLECTOR_H_ #define VOLTA_AGENT_SRC_COLLECTORS_NVML_COLLECTOR_H_ -#include "collectors/collector.h" #include +#include "collectors/collector.h" + namespace volta { namespace agent { namespace collectors { class NvmlCollector : public Collector { -public: - NvmlCollector(); - ~NvmlCollector() override; + public: + NvmlCollector(); + ~NvmlCollector() override; - bool Init() override; - std::vector Collect() override; + bool Init() override; + std::vector Collect() override; -private: - nvmlDevice_t device_handle_; - bool initialized_ = false; + private: + nvmlDevice_t device_handle_; + bool initialized_ = false; }; -} // namespace collectors -} // namespace agent -} // namespace volta +} // namespace collectors +} // namespace agent +} // namespace volta -#endif // VOLTA_AGENT_SRC_COLLECTORS_NVML_COLLECTOR_H_ +#endif // VOLTA_AGENT_SRC_COLLECTORS_NVML_COLLECTOR_H_ diff --git a/source/agent/src/collectors/proc_stat_collector.cc b/source/agent/src/collectors/proc_stat_collector.cc index daedbbc..e177a8b 100644 --- a/source/agent/src/collectors/proc_stat_collector.cc +++ b/source/agent/src/collectors/proc_stat_collector.cc @@ -1,53 +1,55 @@ #include "collectors/proc_stat_collector.h" -#include #include +#include namespace volta { namespace agent { namespace collectors { std::vector ProcStatCollector::Collect() { - uint64_t current_total = 0; - uint64_t current_idle = 0; - - ReadCpuStats(current_total, current_idle); - - uint64_t diff_total = current_total - prev_total_; - uint64_t diff_idle = current_idle - prev_idle_; - - double usage_percent = 0.0; - if (diff_total > 0) usage_percent = (double)(diff_total - diff_idle) / diff_total * 100.0; - - prev_total_ = current_total; - prev_idle_ = current_idle; - - Metric m; - m.name = "cpu_usage_total_percent"; - m.value = usage_percent; - m.timestamp = std::chrono::duration_cast( - std::chrono::system_clock::now().time_since_epoch()).count(); - - return {m}; + uint64_t current_total = 0; + uint64_t current_idle = 0; + + ReadCpuStats(current_total, current_idle); + + uint64_t diff_total = current_total - prev_total_; + uint64_t diff_idle = current_idle - prev_idle_; + + double usage_percent = 0.0; + if (diff_total > 0) + usage_percent = (double)(diff_total - diff_idle) / diff_total * 100.0; + + prev_total_ = current_total; + prev_idle_ = current_idle; + + Metric m; + m.name = "cpu_usage_total_percent"; + m.value = usage_percent; + m.timestamp = std::chrono::duration_cast( + std::chrono::system_clock::now().time_since_epoch()) + .count(); + + return {m}; } void ProcStatCollector::ReadCpuStats(uint64_t& total, uint64_t& idle) { - std::ifstream file("/proc/stat"); - std::string line; - - if (std::getline(file, line)) { - std::istringstream iss(line); - std::string cpu_label; - uint64_t user, nice, system, cur_idle, iowait, irq, softirq, steal; - - iss >> cpu_label >> user >> nice >> system >> cur_idle >> iowait >> irq >> softirq >> steal; - - idle = cur_idle + iowait; - total = user + nice + system + idle + irq + softirq + steal; - } -} + std::ifstream file("/proc/stat"); + std::string line; + if (std::getline(file, line)) { + std::istringstream iss(line); + std::string cpu_label; + uint64_t user, nice, system, cur_idle, iowait, irq, softirq, steal; + + iss >> cpu_label >> user >> nice >> system >> cur_idle >> iowait >> irq >> + softirq >> steal; + + idle = cur_idle + iowait; + total = user + nice + system + idle + irq + softirq + steal; + } +} -} // namespace collectors -} // namespace agent -} // namespace volta \ No newline at end of file +} // namespace collectors +} // namespace agent +} // namespace volta \ No newline at end of file diff --git a/source/agent/src/collectors/proc_stat_collector.h b/source/agent/src/collectors/proc_stat_collector.h index 9253ab7..258143a 100644 --- a/source/agent/src/collectors/proc_stat_collector.h +++ b/source/agent/src/collectors/proc_stat_collector.h @@ -10,18 +10,18 @@ namespace agent { namespace collectors { class ProcStatCollector : public Collector { -public: - std::vector Collect() override; + public: + std::vector Collect() override; -private: - void ReadCpuStats(uint64_t& idle_time, uint64_t& total_time); + private: + void ReadCpuStats(uint64_t& idle_time, uint64_t& total_time); - uint64_t prev_total_ = 0; - uint64_t prev_idle_ = 0; + uint64_t prev_total_ = 0; + uint64_t prev_idle_ = 0; }; -} // namespace collectors -} // namespace agent -} // namespace volta +} // namespace collectors +} // namespace agent +} // namespace volta -#endif // VOLTA_AGENT_SRC_COLLECTORS_PROC_STAT_COLLECTOR_H_ +#endif // VOLTA_AGENT_SRC_COLLECTORS_PROC_STAT_COLLECTOR_H_ diff --git a/source/agent/src/collectors/ram_collector.cc b/source/agent/src/collectors/ram_collector.cc index 05f0060..b135002 100644 --- a/source/agent/src/collectors/ram_collector.cc +++ b/source/agent/src/collectors/ram_collector.cc @@ -1,48 +1,50 @@ #include "collectors/ram_collector.h" -#include -#include #include +#include +#include namespace volta { namespace agent { namespace collectors { std::vector RamCollector::Collect() { - uint64_t used = 0; - uint64_t total = 0; + uint64_t used = 0; + uint64_t total = 0; - ReadStats(used, total); + ReadStats(used, total); - auto now = std::chrono::system_clock::now().time_since_epoch().count(); + auto now = std::chrono::system_clock::now().time_since_epoch().count(); - return { - {"ram_total_bytes", (double) total, now}, - {"ram_used_bytes", (double) used, now}, - {"ram_used_percent", (double) used / total * 100.0, now} - }; + return {{"ram_total_bytes", (double)total, now}, + {"ram_used_bytes", (double)used, now}, + {"ram_used_percent", (double)used / total * 100.0, now}}; } void RamCollector::ReadStats(uint64_t& used, uint64_t& total) { - std::ifstream file("/proc/meminfo"); - std::string line, key; - uint64_t value; - std::string unit; // "kB" - - uint64_t available = 0; - - while (std::getline(file, line)) { - std::istringstream iss(line); - iss >> key >> value >> unit; - if (key == "MemTotal:") total = value * 1024; // kB to bytes - else if (key == "MemAvailable:") available = value * 1024; - - if (total > 0 && available > 0) break; - } - - used = total - available; + std::ifstream file("/proc/meminfo"); + std::string line, key; + uint64_t value; + // "kB" + std::string unit; + + uint64_t available = 0; + + while (std::getline(file, line)) { + std::istringstream iss(line); + iss >> key >> value >> unit; + // kB to bytes + if (key == "MemTotal:") + total = value * 1024; + else if (key == "MemAvailable:") + available = value * 1024; + + if (total > 0 && available > 0) break; + } + + used = total - available; } -} // namespace collectors -} // namespace agent -} // namespace volta +} // namespace collectors +} // namespace agent +} // namespace volta diff --git a/source/agent/src/collectors/ram_collector.h b/source/agent/src/collectors/ram_collector.h index 49fba22..f634910 100644 --- a/source/agent/src/collectors/ram_collector.h +++ b/source/agent/src/collectors/ram_collector.h @@ -8,17 +8,17 @@ namespace agent { namespace collectors { class RamCollector : public Collector { -public: - std::vector Collect() override; + public: + std::vector Collect() override; -private: - void ReadStats(uint64_t& used, uint64_t& total); + private: + void ReadStats(uint64_t& used, uint64_t& total); - bool initialized_ = false; + bool initialized_ = false; }; -} // namespace collectors -} // namespace agent -} // namespace volta +} // namespace collectors +} // namespace agent +} // namespace volta -#endif // VOLTA_AGENT_SRC_COLLECTORS_RAM_COLLECTOR_H_ +#endif // VOLTA_AGENT_SRC_COLLECTORS_RAM_COLLECTOR_H_ diff --git a/source/agent/src/config/config.h b/source/agent/src/config/config.h index 91fb05f..1a83a7c 100644 --- a/source/agent/src/config/config.h +++ b/source/agent/src/config/config.h @@ -1,60 +1,61 @@ #ifndef VOLTA_AGENT_CONFIG_CONFIG_H_ #define VOLTA_AGENT_CONFIG_CONFIG_H_ -#include -#include #include #include +#include +#include namespace volta { namespace agent { namespace config { namespace CollectorNames { - // CPU - static constexpr char const* kProcStat = "proc_stat"; - static constexpr char const* kCpuFreq = "cpu_freq"; - static constexpr char const* kRapl = "rapl"; - static constexpr char const* kZenPower = "zenpower"; - static constexpr char const* kPmu = "pmu"; - - // GPU - static constexpr char const* kNvml = "nvml"; - static constexpr char const* kDcgm = "dcgm"; - static constexpr char const* kRocm = "rocm"; - static constexpr char const* kLevelZero = "level_zero"; - - // RAM - static constexpr char const* kMemInfo = "mem_info"; - static constexpr char const* kVmStat = "vm_stat"; - - // Disc and Network (I/O) - static constexpr char const* kDiskStats = "disk_stats"; - static constexpr char const* kNetDev = "net_dev"; -} +// CPU +static constexpr char const* kProcStat = "proc_stat"; +static constexpr char const* kCpuFreq = "cpu_freq"; +static constexpr char const* kRapl = "rapl"; +static constexpr char const* kZenPower = "zenpower"; +static constexpr char const* kPmu = "pmu"; + +// GPU +static constexpr char const* kNvml = "nvml"; +static constexpr char const* kDcgm = "dcgm"; +static constexpr char const* kRocm = "rocm"; +static constexpr char const* kLevelZero = "level_zero"; + +// RAM +static constexpr char const* kMemInfo = "mem_info"; +static constexpr char const* kVmStat = "vm_stat"; + +// Disc and Network (I/O) +static constexpr char const* kDiskStats = "disk_stats"; +static constexpr char const* kNetDev = "net_dev"; +} // namespace CollectorNames struct CollectorConfig { - bool enabled = false; - std::map metrics; + bool enabled = false; + std::map metrics; }; struct Config { - static constexpr int32_t kDefaultIntervalMs = 500; - static constexpr int32_t kDefaultAffinity = -1; - static constexpr char const* kDefaultServerAddress = "localhost"; - static constexpr uint16_t kDefaultServerPort = 50051; - - std::chrono::milliseconds collection_interval = std::chrono::milliseconds(kDefaultIntervalMs); - int32_t core_affinity = kDefaultAffinity; - - std::string server_address = kDefaultServerAddress; - uint16_t server_port = kDefaultServerPort; - - std::map collectors; + static constexpr int32_t kDefaultIntervalMs = 500; + static constexpr int32_t kDefaultAffinity = -1; + static constexpr char const* kDefaultServerAddress = "localhost"; + static constexpr uint16_t kDefaultServerPort = 50051; + + std::chrono::milliseconds collection_interval = + std::chrono::milliseconds(kDefaultIntervalMs); + int32_t core_affinity = kDefaultAffinity; + + std::string server_address = kDefaultServerAddress; + uint16_t server_port = kDefaultServerPort; + + std::map collectors; }; -} // namespace config -} // namespace agent -} // namespace volta +} // namespace config +} // namespace agent +} // namespace volta #endif // VOLTA_AGENT_CONFIG_CONFIG_H_ diff --git a/source/agent/src/config/config_loader.cc b/source/agent/src/config/config_loader.cc index 37a44ff..d409213 100644 --- a/source/agent/src/config/config_loader.cc +++ b/source/agent/src/config/config_loader.cc @@ -5,30 +5,30 @@ namespace agent { namespace config { Config ConfigLoader::LoadConfig() { - Config config; + Config config; - CollectorConfig nvml_collector; - nvml_collector.enabled = true; - nvml_collector.metrics = { - {"gpu_utilization", true}, - {"memory_utilization", true}, - {"temperature", true}, - }; - config.collectors[CollectorNames::kNvml] = nvml_collector; + CollectorConfig nvml_collector; + nvml_collector.enabled = true; + nvml_collector.metrics = { + {"gpu_utilization", true}, + {"memory_utilization", true}, + {"temperature", true}, + }; + config.collectors[CollectorNames::kNvml] = nvml_collector; - CollectorConfig proc_stat_config; - proc_stat_config.enabled = true; - proc_stat_config.metrics["cpu_usage_percent"] = true; - config.collectors[CollectorNames::kProcStat] = proc_stat_config; + CollectorConfig proc_stat_config; + proc_stat_config.enabled = true; + proc_stat_config.metrics["cpu_usage_percent"] = true; + config.collectors[CollectorNames::kProcStat] = proc_stat_config; - return config; + return config; } Config ConfigLoader::LoadConfig(const std::filesystem::path& filepath) { - // ignore for POC - return LoadConfig(); + // ignore for POC + return LoadConfig(); } -} // namespace config -} // namespace agent -} // namespace volta +} // namespace config +} // namespace agent +} // namespace volta diff --git a/source/agent/src/config/config_loader.h b/source/agent/src/config/config_loader.h index d447dca..c683c35 100644 --- a/source/agent/src/config/config_loader.h +++ b/source/agent/src/config/config_loader.h @@ -1,25 +1,25 @@ #ifndef VOLTA_AGENT_CONFIG_CONFIG_LOADER_H_ #define VOLTA_AGENT_CONFIG_CONFIG_LOADER_H_ -#include #include +#include #include "config/config.h" namespace volta { namespace agent { namespace config { - + class ConfigLoader { -public: - static Config LoadConfig(); - static Config LoadConfig(const std::filesystem::path& filepath); + public: + static Config LoadConfig(); + static Config LoadConfig(const std::filesystem::path& filepath); -private: + private: }; -} // namespace config -} // namespace agent -} // namespace volta +} // namespace config +} // namespace agent +} // namespace volta #endif // VOLTA_AGENT_CONFIG_CONFIG_LOADER_H_ diff --git a/source/agent/src/main.cc b/source/agent/src/main.cc index e916d79..e44c31e 100644 --- a/source/agent/src/main.cc +++ b/source/agent/src/main.cc @@ -1,50 +1,51 @@ +#include #include -#include #include #include #include -#include +#include -#include "scheduler.h" -#include "config/config_loader.h" -#include "config/config.h" -#include "platform/platform_detector.h" #include "collectors/collector.h" -#include "collectors/ram_collector.h" #include "collectors/nvml_collector.h" #include "collectors/proc_stat_collector.h" +#include "collectors/ram_collector.h" +#include "config/config.h" +#include "config/config_loader.h" +#include "platform/platform_detector.h" +#include "scheduler.h" using namespace volta::agent; int main() { - try { - auto config = config::ConfigLoader::LoadConfig(); - - platform::PlatformDetector detector; - auto hw = detector.Detect(); - detector.PrintDetectedInfo(hw); - - std::vector> active_collectors; - - active_collectors.push_back(std::make_unique()); - - active_collectors.push_back(std::make_unique()); - - for (const auto& gpu : hw.gpus) { - if (gpu.vendor == platform::GpuVendor::NVIDIA) { - auto nvml = std::make_unique(); - if (nvml->Init()) { - active_collectors.push_back(std::move(nvml)); - } - } - } + try { + auto config = config::ConfigLoader::LoadConfig(); + + platform::PlatformDetector detector; + auto hw = detector.Detect(); + detector.PrintDetectedInfo(hw); - Scheduler scheduler(config, std::move(active_collectors)); - scheduler.Run(); + std::vector> active_collectors; - } catch (const std::exception& e) { - std::cerr << "CRITICAL ERROR: " << e.what() << std::endl; - return 1; + active_collectors.push_back( + std::make_unique()); + + active_collectors.push_back(std::make_unique()); + + for (const auto& gpu : hw.gpus) { + if (gpu.vendor == platform::GpuVendor::NVIDIA) { + auto nvml = std::make_unique(); + if (nvml->Init()) { + active_collectors.push_back(std::move(nvml)); + } + } } - return 0; + + Scheduler scheduler(config, std::move(active_collectors)); + scheduler.Run(); + + } catch (const std::exception& e) { + std::cerr << "CRITICAL ERROR: " << e.what() << std::endl; + return 1; + } + return 0; } diff --git a/source/agent/src/metric.h b/source/agent/src/metric.h index f1847ff..04a4c2f 100644 --- a/source/agent/src/metric.h +++ b/source/agent/src/metric.h @@ -1,19 +1,19 @@ #ifndef VOLTA_AGENT_SRC_METRIC_H #define VOLTA_AGENT_SRC_METRIC_H -#include #include +#include namespace volta { namespace agent { struct Metric { - std::string name; - double value; - int64_t timestamp; + std::string name; + double value; + int64_t timestamp; }; -} // namespace agent -} // namespace volta +} // namespace agent +} // namespace volta -#endif // VOLTA_AGENT_SRC_METRIC_H +#endif // VOLTA_AGENT_SRC_METRIC_H diff --git a/source/agent/src/platform/cpu_info.h b/source/agent/src/platform/cpu_info.h index fe97391..a99c04a 100644 --- a/source/agent/src/platform/cpu_info.h +++ b/source/agent/src/platform/cpu_info.h @@ -1,46 +1,42 @@ #ifndef VOLTA_AGENT_PLATFORM_CPU_INFO_H_ #define VOLTA_AGENT_PLATFORM_CPU_INFO_H_ -#include #include +#include namespace volta { namespace agent { namespace platform { -enum class CpuVendor { - UNKNOWN, - AMD, - INTEL -}; +enum class CpuVendor { UNKNOWN, AMD, INTEL }; struct CpuInfo { - CpuVendor vendor = CpuVendor::UNKNOWN; - - std::string model_name; - std::string architecture; + CpuVendor vendor = CpuVendor::UNKNOWN; + + std::string model_name; + std::string architecture; - // Topology information - uint8_t physical_cores = 0; - uint8_t logical_threads = 0; - uint8_t socket_count = 1; + // Topology information + uint8_t physical_cores = 0; + uint8_t logical_threads = 0; + uint8_t socket_count = 1; - float base_frequency_mhz = 0.0; - float max_frequency_mhz = 0.0; + float base_frequency_mhz = 0.0; + float max_frequency_mhz = 0.0; - uint64_t l1_cache_size_bytes = 0; - uint64_t l2_cache_size_bytes = 0; - uint64_t l3_cache_size_bytes = 0; + uint64_t l1_cache_size_bytes = 0; + uint64_t l2_cache_size_bytes = 0; + uint64_t l3_cache_size_bytes = 0; - float power_limit_watts = 0.0; + float power_limit_watts = 0.0; - bool has_rapl = false; // Support Intel RAPL - bool has_zenpower = false; // Support AMD zenpower/k10temp - bool has_pmu = false; // Access to Performance Monitoring Unit + bool has_rapl = false; // Support Intel RAPL + bool has_zenpower = false; // Support AMD zenpower/k10temp + bool has_pmu = false; // Access to Performance Monitoring Unit }; -} // namespace platform -} // namespace agent -} // namespace volta +} // namespace platform +} // namespace agent +} // namespace volta #endif // VOLTA_AGENT_PLATFORM_CPU_INFO_H_ diff --git a/source/agent/src/platform/gpu_info.h b/source/agent/src/platform/gpu_info.h index 9fb28c1..e1e24c7 100644 --- a/source/agent/src/platform/gpu_info.h +++ b/source/agent/src/platform/gpu_info.h @@ -1,35 +1,31 @@ #ifndef VOLTA_AGENT_PLATFORM_GPU_INFO_H_ #define VOLTA_AGENT_PLATFORM_GPU_INFO_H_ -#include #include +#include namespace volta { namespace agent { namespace platform { -enum class GpuVendor { - UNKNOWN, - NVIDIA, - AMD, - INTEL -}; +enum class GpuVendor { UNKNOWN, NVIDIA, AMD, INTEL }; struct GpuInfo { - GpuVendor vendor = GpuVendor::UNKNOWN; + GpuVendor vendor = GpuVendor::UNKNOWN; + + std::string model_name; - std::string model_name; - - // Unique identifier (Domain:Bus:Device.Function) to differentiate multiple GPUs in one system - std::string pci_address; - std::string driver_version; + // Unique identifier (Domain:Bus:Device.Function) to differentiate multiple + // GPUs in one system + std::string pci_address; + std::string driver_version; - uint64_t vram_total_bytes = 0; - float power_limit_watts = 0.0; + uint64_t vram_total_bytes = 0; + float power_limit_watts = 0.0; }; -} // namespace platform -} // namespace agent -} // namespace volta +} // namespace platform +} // namespace agent +} // namespace volta #endif // VOLTA_AGENT_PLATFORM_GPU_INFO_H_ diff --git a/source/agent/src/platform/hardware_info.h b/source/agent/src/platform/hardware_info.h index d15f7e3..944dc4b 100644 --- a/source/agent/src/platform/hardware_info.h +++ b/source/agent/src/platform/hardware_info.h @@ -1,30 +1,30 @@ #ifndef VOLTA_AGENT_PLATFORM_HARDWARE_INFO_H_ #define VOLTA_AGENT_PLATFORM_HARDWARE_INFO_H_ +#include #include #include -#include -#include "platform/gpu_info.h" #include "platform/cpu_info.h" +#include "platform/gpu_info.h" namespace volta { namespace agent { namespace platform { struct HardwareInfo { - std::string hostname; - std::string os_version; - std::string kernel_version; + std::string hostname; + std::string os_version; + std::string kernel_version; - uint64_t total_ram_bytes = 0; + uint64_t total_ram_bytes = 0; - CpuInfo cpu; - std::vector gpus; + CpuInfo cpu; + std::vector gpus; }; -} // namespace platform -} // namespace agent -} // namespace volta +} // namespace platform +} // namespace agent +} // namespace volta #endif // VOLTA_AGENT_PLATFORM_HARDWARE_INFO_H_ diff --git a/source/agent/src/platform/platform_detector.cc b/source/agent/src/platform/platform_detector.cc index 44b5908..243f11d 100644 --- a/source/agent/src/platform/platform_detector.cc +++ b/source/agent/src/platform/platform_detector.cc @@ -1,10 +1,13 @@ #include "platform/platform_detector.h" #include + #include #include -#include #include +#include +#include +#include #ifdef HAVE_NVML #include @@ -15,114 +18,125 @@ namespace agent { namespace platform { static std::string CpuVendorToString(CpuVendor v) { - switch(v) { - case CpuVendor::INTEL: return "Intel"; - case CpuVendor::AMD: return "AMD"; - default: return "Unknown"; - } + switch (v) { + case CpuVendor::INTEL: + return "Intel"; + case CpuVendor::AMD: + return "AMD"; + default: + return "Unknown"; + } } static std::string GpuVendorToString(GpuVendor v) { - switch(v) { - case GpuVendor::NVIDIA: return "NVIDIA"; - case GpuVendor::AMD: return "AMD"; - case GpuVendor::INTEL: return "Intel"; - default: return "Unknown"; - } + switch (v) { + case GpuVendor::NVIDIA: + return "NVIDIA"; + case GpuVendor::AMD: + return "AMD"; + case GpuVendor::INTEL: + return "Intel"; + default: + return "Unknown"; + } } HardwareInfo PlatformDetector::Detect() { - HardwareInfo info; - - char hostname_buffer[256]; - if (gethostname(hostname_buffer, sizeof(hostname_buffer)) == 0) info.hostname = std::string(hostname_buffer); - else info.hostname = "unknown-host"; - - info.os_version = DetectOS(); - - std::ifstream cpuinfo("/proc/cpuinfo"); - std::string line; - while (std::getline(cpuinfo, line)) { - if (line.find("vendor_id") != std::string::npos) { - if (line.find("AuthenticAMD") != std::string::npos) info.cpu.vendor = CpuVendor::AMD; - else if (line.find("GenuineIntel") != std::string::npos) info.cpu.vendor = CpuVendor::INTEL; - } - if (line.find("model name") != std::string::npos) { - size_t pos = line.find(":"); - if (pos != std::string::npos) { - info.cpu.model_name = line.substr(pos + 2); - } - break; - } + HardwareInfo info; + + char hostname_buffer[256]; + if (gethostname(hostname_buffer, sizeof(hostname_buffer)) == 0) + info.hostname = std::string(hostname_buffer); + else + info.hostname = "unknown-host"; + + info.os_version = DetectOS(); + + std::ifstream cpuinfo("/proc/cpuinfo"); + std::string line; + while (std::getline(cpuinfo, line)) { + if (line.find("vendor_id") != std::string::npos) { + if (line.find("AuthenticAMD") != std::string::npos) + info.cpu.vendor = CpuVendor::AMD; + else if (line.find("GenuineIntel") != std::string::npos) + info.cpu.vendor = CpuVendor::INTEL; } + if (line.find("model name") != std::string::npos) { + size_t pos = line.find(":"); + if (pos != std::string::npos) { + info.cpu.model_name = line.substr(pos + 2); + } + break; + } + } #ifdef HAVE_NVML - if (nvmlInit() == NVML_SUCCESS) { - unsigned int device_count = 0; - nvmlDeviceGetCount(&device_count); - - for (unsigned int i = 0; i < device_count; ++i) { - nvmlDevice_t device; - nvmlDeviceGetHandleByIndex(i, &device); - - char name[64]; - if (nvmlDeviceGetName(device, name, sizeof(name)) == NVML_SUCCESS) { - GpuInfo gpu; - gpu.vendor = GpuVendor::NVIDIA; - gpu.model_name = std::string(name); - info.gpus.push_back(gpu); - } - } - nvmlShutdown(); + if (nvmlInit() == NVML_SUCCESS) { + unsigned int device_count = 0; + nvmlDeviceGetCount(&device_count); + + for (unsigned int i = 0; i < device_count; ++i) { + nvmlDevice_t device; + nvmlDeviceGetHandleByIndex(i, &device); + + char name[64]; + if (nvmlDeviceGetName(device, name, sizeof(name)) == NVML_SUCCESS) { + GpuInfo gpu; + gpu.vendor = GpuVendor::NVIDIA; + gpu.model_name = std::string(name); + info.gpus.push_back(gpu); + } } + nvmlShutdown(); + } #endif - return info; + return info; } void PlatformDetector::PrintDetectedInfo(const HardwareInfo& info) { - std::cout << "[" << typeid(*this).name() << "] Hardware Detection Result:\n"; - std::cout << " > Host: " << info.hostname << "\n"; - std::cout << " > OS: " << info.os_version << "\n"; - std::cout << " > CPU: " << CpuVendorToString(info.cpu.vendor) << "\n" - << " | Model: " << info.cpu.model_name << "\n"; - - if (info.gpus.empty()) { - std::cout << " > GPU: None detected (or NVML disabled)\n"; - } else { - for (const auto& gpu : info.gpus) { - std::cout << " > GPU: " << GpuVendorToString(gpu.vendor) << "\n" - << " | Model: " << gpu.model_name << "\n"; - } + std::cout << "[" << typeid(*this).name() << "] Hardware Detection Result:\n"; + std::cout << " > Host: " << info.hostname << "\n"; + std::cout << " > OS: " << info.os_version << "\n"; + std::cout << " > CPU: " << CpuVendorToString(info.cpu.vendor) << "\n" + << " | Model: " << info.cpu.model_name << "\n"; + + if (info.gpus.empty()) { + std::cout << " > GPU: None detected (or NVML disabled)\n"; + } else { + for (const auto& gpu : info.gpus) { + std::cout << " > GPU: " << GpuVendorToString(gpu.vendor) << "\n" + << " | Model: " << gpu.model_name << "\n"; } - std::cout << "--------------------------------------------------\n"; - std::cout.flush(); - std::cin.get(); + } + std::cout << "--------------------------------------------------\n"; + std::cout.flush(); + std::cin.get(); } std::string PlatformDetector::DetectOS() { - std::ifstream file("/etc/os-release"); - - if (!file.is_open()) { - return "Linux (Unknown - Cannot open /etc/os-release)"; - } + std::ifstream file("/etc/os-release"); + + if (!file.is_open()) { + return "Linux (Unknown - Cannot open /etc/os-release)"; + } + + std::string line; + while (std::getline(file, line)) { + if (line.starts_with("PRETTY_NAME=") == 0) { + std::string value = line.substr(12); + + if (value.size() >= 2 && value.front() == '"' && value.back() == '"') { + value = value.substr(1, value.size() - 2); + } - std::string line; - while (std::getline(file, line)) { - if (line.find("PRETTY_NAME=") == 0) { - std::string value = line.substr(12); - - if (value.size() >= 2 && value.front() == '"' && value.back() == '"') { - value = value.substr(1, value.size() - 2); - } - - return value; - } + return value; } + } - return "Linux (Unknown - Tag not found)"; + return "Linux (Unknown - Tag not found)"; } -} // namespace platform -} // namespace agent -} // namespace volta +} // namespace platform +} // namespace agent +} // namespace volta diff --git a/source/agent/src/platform/platform_detector.h b/source/agent/src/platform/platform_detector.h index e1af149..458f27c 100644 --- a/source/agent/src/platform/platform_detector.h +++ b/source/agent/src/platform/platform_detector.h @@ -1,9 +1,9 @@ #ifndef VOLTA_AGENT_PLATFORM_PLATFORM_DETECTOR_H_ #define VOLTA_AGENT_PLATFORM_PLATFORM_DETECTOR_H_ +#include #include #include -#include #include "platform/hardware_info.h" @@ -12,16 +12,16 @@ namespace agent { namespace platform { class PlatformDetector { -public: - HardwareInfo Detect(); - void PrintDetectedInfo(const HardwareInfo& info); + public: + HardwareInfo Detect(); + void PrintDetectedInfo(const HardwareInfo& info); -private: - std::string DetectOS(); + private: + std::string DetectOS(); }; -} // namespace platform -} // namespace agent -} // namespace volta +} // namespace platform +} // namespace agent +} // namespace volta #endif // VOLTA_AGENT_PLATFORM_PLATFORM_DETECTOR_H_ diff --git a/source/agent/src/scheduler.cc b/source/agent/src/scheduler.cc index 6bb88bd..74927c7 100644 --- a/source/agent/src/scheduler.cc +++ b/source/agent/src/scheduler.cc @@ -1,57 +1,58 @@ #include "scheduler.h" +#include #include #include -#include namespace volta { namespace agent { Scheduler::Scheduler( - const config::Config& config, - std::vector>&& collectors) - : config_(config) - , collectors_(std::move(collectors)) {} + const config::Config& config, + std::vector>&& collectors) + : config_(config), collectors_(std::move(collectors)) {} void Scheduler::Run() { - std::cout << "[" << typeid(*this).name() << "] Starting collection loop (Interval: " - << config_.collection_interval.count() << "ms)..." << std::endl; - - std::this_thread::sleep_for(config_.collection_interval); - - while (true) { - std::vector batch; - for (const auto& collector : collectors_) { - auto metrics = collector->Collect(); - batch.insert(batch.end(), metrics.begin(), metrics.end()); - } + std::cout << "[" << typeid(*this).name() + << "] Starting collection loop (Interval: " + << config_.collection_interval.count() << "ms)..." << std::endl; - PrintDashboard(batch); + std::this_thread::sleep_for(config_.collection_interval); - std::this_thread::sleep_for(config_.collection_interval); + while (true) { + std::vector batch; + for (const auto& collector : collectors_) { + auto metrics = collector->Collect(); + batch.insert(batch.end(), metrics.begin(), metrics.end()); } + + PrintDashboard(batch); + + std::this_thread::sleep_for(config_.collection_interval); + } } void Scheduler::PrintDashboard(const std::vector& metrics) { - std::cout << "\033[2J\033[1;1H"; // ansi clean screen, move cursor to top-left - - std::cout << "===============================================\n"; - std::cout << " VOLTA AGENT v0.1 (POC) - ACTIVE MONITOR \n"; - std::cout << "===============================================\n"; - - std::cout << std::left << std::setw(30) << "METRIC NAME" << "VALUE\n"; - std::cout << "-----------------------------------------------\n"; - - for (const auto& m : metrics) { - std::cout << std::left << std::setw(30) << m.name - << std::fixed << std::setprecision(2) << m.value << "\n"; - } + // ansi clean screen, move cursor to top-left + std::cout << "\033[2J\033[1;1H"; + + std::cout << "===============================================\n"; + std::cout << " VOLTA AGENT v0.1 (POC) - ACTIVE MONITOR \n"; + std::cout << "===============================================\n"; + + std::cout << std::left << std::setw(30) << "METRIC NAME" << "VALUE\n"; + std::cout << "-----------------------------------------------\n"; + + for (const auto& m : metrics) { + std::cout << std::left << std::setw(30) << m.name << std::fixed + << std::setprecision(2) << m.value << "\n"; + } - std::cout << "-----------------------------------------------\n"; - std::cout << "Data points collected: " << metrics.size() << "\n"; - std::cout << "Press Ctrl+C to exit." << "\n"; - std::cout.flush(); + std::cout << "-----------------------------------------------\n"; + std::cout << "Data points collected: " << metrics.size() << "\n"; + std::cout << "Press Ctrl+C to exit." << "\n"; + std::cout.flush(); } -} // namespace agent -} // namespace volta +} // namespace agent +} // namespace volta diff --git a/source/agent/src/scheduler.h b/source/agent/src/scheduler.h index d68a3af..9caafee 100644 --- a/source/agent/src/scheduler.h +++ b/source/agent/src/scheduler.h @@ -1,32 +1,32 @@ #ifndef VOLTA_AGENT_SRC_SCHEDULER_H_ #define VOLTA_AGENT_SRC_SCHEDULER_H_ -#include #include +#include -#include "metric.h" #include "collectors/collector.h" #include "config/config.h" +#include "metric.h" namespace volta { namespace agent { class Scheduler { -public: - explicit Scheduler( - const config::Config& config, - std::vector>&& collectors); - - void Run(); - -private: - void PrintDashboard(const std::vector& metrics); - - std::vector> collectors_; - const config::Config& config_; + public: + explicit Scheduler( + const config::Config& config, + std::vector>&& collectors); + + void Run(); + + private: + void PrintDashboard(const std::vector& metrics); + + std::vector> collectors_; + const config::Config& config_; }; -} // namespace agent -} // namespace volta +} // namespace agent +} // namespace volta -#endif // VOLTA_AGENT_SRC_SCHEDULER_H_ +#endif // VOLTA_AGENT_SRC_SCHEDULER_H_ From 69feb0b6601c8708061b7c97ed3c4a33c7ea0dd4 Mon Sep 17 00:00:00 2001 From: Dawid Woloszyn Date: Sat, 24 Jan 2026 19:02:11 +0100 Subject: [PATCH 02/37] updated gitignore --- .gitignore | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.gitignore b/.gitignore index 7e53678..086cdb0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,9 @@ .vscode/ build/ +out/ bin/ + +.cache/ +compile_commands.json + From a59b39269c0c40e0785841472713c917a13ef8cb Mon Sep 17 00:00:00 2001 From: Dawid Woloszyn Date: Sat, 24 Jan 2026 19:04:46 +0100 Subject: [PATCH 03/37] agent config file with toml syntax --- agent.conf | 1 + 1 file changed, 1 insertion(+) create mode 100644 agent.conf diff --git a/agent.conf b/agent.conf new file mode 100644 index 0000000..a80c3bc --- /dev/null +++ b/agent.conf @@ -0,0 +1 @@ +core_affinity = [2, "3-10"] From e595fa61401aa8b0e10876b0755ad8e2263579ad Mon Sep 17 00:00:00 2001 From: Dawid Woloszyn Date: Sat, 24 Jan 2026 19:05:00 +0100 Subject: [PATCH 04/37] toml++ library for parsing toml syntax --- libs/include/toml++/toml.hpp | 17888 +++++++++++++++++++++++++++++++++ 1 file changed, 17888 insertions(+) create mode 100644 libs/include/toml++/toml.hpp diff --git a/libs/include/toml++/toml.hpp b/libs/include/toml++/toml.hpp new file mode 100644 index 0000000..c01a208 --- /dev/null +++ b/libs/include/toml++/toml.hpp @@ -0,0 +1,17888 @@ +//---------------------------------------------------------------------------------------------------------------------- +// +// toml++ v3.4.0 +// https://github.com/marzer/tomlplusplus +// SPDX-License-Identifier: MIT +// +//---------------------------------------------------------------------------------------------------------------------- +// +// - THIS FILE WAS ASSEMBLED FROM MULTIPLE HEADER FILES BY A SCRIPT - PLEASE DON'T EDIT IT DIRECTLY - +// +// If you wish to submit a contribution to toml++, hooray and thanks! Before you crack on, please be aware that this +// file was assembled from a number of smaller files by a python script, and code contributions should not be made +// against it directly. You should instead make your changes in the relevant source file(s). The file names of the files +// that contributed to this header can be found at the beginnings and ends of the corresponding sections of this file. +// +//---------------------------------------------------------------------------------------------------------------------- +// +// TOML Language Specifications: +// latest: https://github.com/toml-lang/toml/blob/master/README.md +// v1.0.0: https://toml.io/en/v1.0.0 +// v0.5.0: https://toml.io/en/v0.5.0 +// changelog: https://github.com/toml-lang/toml/blob/master/CHANGELOG.md +// +//---------------------------------------------------------------------------------------------------------------------- +// +// MIT License +// +// Copyright (c) Mark Gillard +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +// documentation files (the "Software"), to deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the +// Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +//---------------------------------------------------------------------------------------------------------------------- +#ifndef TOMLPLUSPLUS_HPP +#define TOMLPLUSPLUS_HPP + +#define INCLUDE_TOMLPLUSPLUS_H // old guard name used pre-v3 +#define TOMLPLUSPLUS_H // guard name used in the legacy toml.h + +//******** impl/preprocessor.hpp ************************************************************************************* + +#ifndef __cplusplus +#error toml++ is a C++ library. +#endif + +#ifndef TOML_CPP +#ifdef _MSVC_LANG +#if _MSVC_LANG > __cplusplus +#define TOML_CPP _MSVC_LANG +#endif +#endif +#ifndef TOML_CPP +#define TOML_CPP __cplusplus +#endif +#if TOML_CPP >= 202900L +#undef TOML_CPP +#define TOML_CPP 29 +#elif TOML_CPP >= 202600L +#undef TOML_CPP +#define TOML_CPP 26 +#elif TOML_CPP >= 202302L +#undef TOML_CPP +#define TOML_CPP 23 +#elif TOML_CPP >= 202002L +#undef TOML_CPP +#define TOML_CPP 20 +#elif TOML_CPP >= 201703L +#undef TOML_CPP +#define TOML_CPP 17 +#elif TOML_CPP >= 201402L +#undef TOML_CPP +#define TOML_CPP 14 +#elif TOML_CPP >= 201103L +#undef TOML_CPP +#define TOML_CPP 11 +#else +#undef TOML_CPP +#define TOML_CPP 0 +#endif +#endif + +#if !TOML_CPP +#error toml++ requires C++17 or higher. For a pre-C++11 TOML library see https://github.com/ToruNiina/Boost.toml +#elif TOML_CPP < 17 +#error toml++ requires C++17 or higher. For a C++11 TOML library see https://github.com/ToruNiina/toml11 +#endif + +#ifndef TOML_MAKE_VERSION +#define TOML_MAKE_VERSION(major, minor, patch) (((major)*10000) + ((minor)*100) + ((patch))) +#endif + +#ifndef TOML_INTELLISENSE +#ifdef __INTELLISENSE__ +#define TOML_INTELLISENSE 1 +#else +#define TOML_INTELLISENSE 0 +#endif +#endif + +#ifndef TOML_DOXYGEN +#if defined(DOXYGEN) || defined(__DOXYGEN) || defined(__DOXYGEN__) || defined(__doxygen__) || defined(__POXY__) \ + || defined(__poxy__) +#define TOML_DOXYGEN 1 +#else +#define TOML_DOXYGEN 0 +#endif +#endif + +#ifndef TOML_CLANG +#ifdef __clang__ +#define TOML_CLANG __clang_major__ +#else +#define TOML_CLANG 0 +#endif + +// special handling for apple clang; see: +// - https://github.com/marzer/tomlplusplus/issues/189 +// - https://en.wikipedia.org/wiki/Xcode +// - +// https://stackoverflow.com/questions/19387043/how-can-i-reliably-detect-the-version-of-clang-at-preprocessing-time +#if TOML_CLANG && defined(__apple_build_version__) +#undef TOML_CLANG +#define TOML_CLANG_VERSION TOML_MAKE_VERSION(__clang_major__, __clang_minor__, __clang_patchlevel__) +#if TOML_CLANG_VERSION >= TOML_MAKE_VERSION(15, 0, 0) +#define TOML_CLANG 16 +#elif TOML_CLANG_VERSION >= TOML_MAKE_VERSION(14, 3, 0) +#define TOML_CLANG 15 +#elif TOML_CLANG_VERSION >= TOML_MAKE_VERSION(14, 0, 0) +#define TOML_CLANG 14 +#elif TOML_CLANG_VERSION >= TOML_MAKE_VERSION(13, 1, 6) +#define TOML_CLANG 13 +#elif TOML_CLANG_VERSION >= TOML_MAKE_VERSION(13, 0, 0) +#define TOML_CLANG 12 +#elif TOML_CLANG_VERSION >= TOML_MAKE_VERSION(12, 0, 5) +#define TOML_CLANG 11 +#elif TOML_CLANG_VERSION >= TOML_MAKE_VERSION(12, 0, 0) +#define TOML_CLANG 10 +#elif TOML_CLANG_VERSION >= TOML_MAKE_VERSION(11, 0, 3) +#define TOML_CLANG 9 +#elif TOML_CLANG_VERSION >= TOML_MAKE_VERSION(11, 0, 0) +#define TOML_CLANG 8 +#elif TOML_CLANG_VERSION >= TOML_MAKE_VERSION(10, 0, 1) +#define TOML_CLANG 7 +#else +#define TOML_CLANG 6 // not strictly correct but doesn't matter below this +#endif +#undef TOML_CLANG_VERSION +#endif +#endif + +#ifndef TOML_ICC +#ifdef __INTEL_COMPILER +#define TOML_ICC __INTEL_COMPILER +#ifdef __ICL +#define TOML_ICC_CL TOML_ICC +#else +#define TOML_ICC_CL 0 +#endif +#else +#define TOML_ICC 0 +#define TOML_ICC_CL 0 +#endif +#endif + +#ifndef TOML_MSVC_LIKE +#ifdef _MSC_VER +#define TOML_MSVC_LIKE _MSC_VER +#else +#define TOML_MSVC_LIKE 0 +#endif +#endif + +#ifndef TOML_MSVC +#if TOML_MSVC_LIKE && !TOML_CLANG && !TOML_ICC +#define TOML_MSVC TOML_MSVC_LIKE +#else +#define TOML_MSVC 0 +#endif +#endif + +#ifndef TOML_GCC_LIKE +#ifdef __GNUC__ +#define TOML_GCC_LIKE __GNUC__ +#else +#define TOML_GCC_LIKE 0 +#endif +#endif + +#ifndef TOML_GCC +#if TOML_GCC_LIKE && !TOML_CLANG && !TOML_ICC +#define TOML_GCC TOML_GCC_LIKE +#else +#define TOML_GCC 0 +#endif +#endif + +#ifndef TOML_CUDA +#if defined(__CUDACC__) || defined(__CUDA_ARCH__) || defined(__CUDA_LIBDEVICE__) +#define TOML_CUDA 1 +#else +#define TOML_CUDA 0 +#endif +#endif + +#ifndef TOML_NVCC +#ifdef __NVCOMPILER_MAJOR__ +#define TOML_NVCC __NVCOMPILER_MAJOR__ +#else +#define TOML_NVCC 0 +#endif +#endif + +#ifndef TOML_ARCH_ITANIUM +#if defined(__ia64__) || defined(__ia64) || defined(_IA64) || defined(__IA64__) || defined(_M_IA64) +#define TOML_ARCH_ITANIUM 1 +#define TOML_ARCH_BITNESS 64 +#else +#define TOML_ARCH_ITANIUM 0 +#endif +#endif + +#ifndef TOML_ARCH_AMD64 +#if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_AMD64) +#define TOML_ARCH_AMD64 1 +#define TOML_ARCH_BITNESS 64 +#else +#define TOML_ARCH_AMD64 0 +#endif +#endif + +#ifndef TOML_ARCH_X86 +#if defined(__i386__) || defined(_M_IX86) +#define TOML_ARCH_X86 1 +#define TOML_ARCH_BITNESS 32 +#else +#define TOML_ARCH_X86 0 +#endif +#endif + +#ifndef TOML_ARCH_ARM +#if defined(__aarch64__) || defined(__ARM_ARCH_ISA_A64) || defined(_M_ARM64) || defined(__ARM_64BIT_STATE) \ + || defined(_M_ARM64EC) +#define TOML_ARCH_ARM32 0 +#define TOML_ARCH_ARM64 1 +#define TOML_ARCH_ARM 1 +#define TOML_ARCH_BITNESS 64 +#elif defined(__arm__) || defined(_M_ARM) || defined(__ARM_32BIT_STATE) +#define TOML_ARCH_ARM32 1 +#define TOML_ARCH_ARM64 0 +#define TOML_ARCH_ARM 1 +#define TOML_ARCH_BITNESS 32 +#else +#define TOML_ARCH_ARM32 0 +#define TOML_ARCH_ARM64 0 +#define TOML_ARCH_ARM 0 +#endif +#endif + +#ifndef TOML_ARCH_BITNESS +#define TOML_ARCH_BITNESS 0 +#endif + +#ifndef TOML_ARCH_X64 +#if TOML_ARCH_BITNESS == 64 +#define TOML_ARCH_X64 1 +#else +#define TOML_ARCH_X64 0 +#endif +#endif + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || defined(__CYGWIN__) +#define TOML_WINDOWS 1 +#else +#define TOML_WINDOWS 0 +#endif + +#ifdef __unix__ +#define TOML_UNIX 1 +#else +#define TOML_UNIX 0 +#endif + +#ifdef __linux__ +#define TOML_LINUX 1 +#else +#define TOML_LINUX 0 +#endif + +// TOML_HAS_INCLUDE +#ifndef TOML_HAS_INCLUDE +#ifdef __has_include +#define TOML_HAS_INCLUDE(header) __has_include(header) +#else +#define TOML_HAS_INCLUDE(header) 0 +#endif +#endif + +// TOML_HAS_BUILTIN +#ifndef TOML_HAS_BUILTIN +#ifdef __has_builtin +#define TOML_HAS_BUILTIN(name) __has_builtin(name) +#else +#define TOML_HAS_BUILTIN(name) 0 +#endif +#endif + +// TOML_HAS_FEATURE +#ifndef TOML_HAS_FEATURE +#ifdef __has_feature +#define TOML_HAS_FEATURE(name) __has_feature(name) +#else +#define TOML_HAS_FEATURE(name) 0 +#endif +#endif + +// TOML_HAS_ATTR +#ifndef TOML_HAS_ATTR +#ifdef __has_attribute +#define TOML_HAS_ATTR(attr) __has_attribute(attr) +#else +#define TOML_HAS_ATTR(attr) 0 +#endif +#endif + +// TOML_HAS_CPP_ATTR +#ifndef TOML_HAS_CPP_ATTR +#ifdef __has_cpp_attribute +#define TOML_HAS_CPP_ATTR(attr) __has_cpp_attribute(attr) +#else +#define TOML_HAS_CPP_ATTR(attr) 0 +#endif +#endif + +// TOML_ATTR (gnu attributes) +#ifndef TOML_ATTR +#if TOML_CLANG || TOML_GCC_LIKE +#define TOML_ATTR(...) __attribute__((__VA_ARGS__)) +#else +#define TOML_ATTR(...) +#endif +#endif + +// TOML_DECLSPEC (msvc attributes) +#ifndef TOML_DECLSPEC +#if TOML_MSVC_LIKE +#define TOML_DECLSPEC(...) __declspec(__VA_ARGS__) +#else +#define TOML_DECLSPEC(...) +#endif +#endif + +// TOML_COMPILER_HAS_EXCEPTIONS +#ifndef TOML_COMPILER_HAS_EXCEPTIONS +#if defined(__EXCEPTIONS) || defined(_CPPUNWIND) || defined(__cpp_exceptions) +#define TOML_COMPILER_HAS_EXCEPTIONS 1 +#else +#define TOML_COMPILER_HAS_EXCEPTIONS 0 +#endif +#endif + +// TOML_COMPILER_HAS_RTTI +#ifndef TOML_COMPILER_HAS_RTTI +#if defined(_CPPRTTI) || defined(__GXX_RTTI) || TOML_HAS_FEATURE(cxx_rtti) +#define TOML_COMPILER_HAS_RTTI 1 +#else +#define TOML_COMPILER_HAS_RTTI 0 +#endif +#endif + +// TOML_CONCAT +#define TOML_CONCAT_1(x, y) x##y +#define TOML_CONCAT(x, y) TOML_CONCAT_1(x, y) + +// TOML_MAKE_STRING +#define TOML_MAKE_STRING_1(s) #s +#define TOML_MAKE_STRING(s) TOML_MAKE_STRING_1(s) + +// TOML_PRAGMA_XXXX (compiler-specific pragmas) +#if TOML_CLANG +#define TOML_PRAGMA_CLANG(decl) _Pragma(TOML_MAKE_STRING(clang decl)) +#else +#define TOML_PRAGMA_CLANG(decl) +#endif +#if TOML_CLANG >= 8 +#define TOML_PRAGMA_CLANG_GE_8(decl) TOML_PRAGMA_CLANG(decl) +#else +#define TOML_PRAGMA_CLANG_GE_8(decl) +#endif +#if TOML_CLANG >= 9 +#define TOML_PRAGMA_CLANG_GE_9(decl) TOML_PRAGMA_CLANG(decl) +#else +#define TOML_PRAGMA_CLANG_GE_9(decl) +#endif +#if TOML_CLANG >= 10 +#define TOML_PRAGMA_CLANG_GE_10(decl) TOML_PRAGMA_CLANG(decl) +#else +#define TOML_PRAGMA_CLANG_GE_10(decl) +#endif +#if TOML_CLANG >= 11 +#define TOML_PRAGMA_CLANG_GE_11(decl) TOML_PRAGMA_CLANG(decl) +#else +#define TOML_PRAGMA_CLANG_GE_11(decl) +#endif +#if TOML_GCC +#define TOML_PRAGMA_GCC(decl) _Pragma(TOML_MAKE_STRING(GCC decl)) +#else +#define TOML_PRAGMA_GCC(decl) +#endif +#if TOML_MSVC +#define TOML_PRAGMA_MSVC(...) __pragma(__VA_ARGS__) +#else +#define TOML_PRAGMA_MSVC(...) +#endif +#if TOML_ICC +#define TOML_PRAGMA_ICC(...) __pragma(__VA_ARGS__) +#else +#define TOML_PRAGMA_ICC(...) +#endif + +// TOML_ALWAYS_INLINE +#ifndef TOML_ALWAYS_INLINE +#ifdef _MSC_VER +#define TOML_ALWAYS_INLINE __forceinline +#elif TOML_GCC || TOML_CLANG || TOML_HAS_ATTR(__always_inline__) +#define TOML_ALWAYS_INLINE \ + TOML_ATTR(__always_inline__) \ + inline +#else +#define TOML_ALWAYS_INLINE inline +#endif +#endif + +// TOML_NEVER_INLINE +#ifndef TOML_NEVER_INLINE +#ifdef _MSC_VER +#define TOML_NEVER_INLINE TOML_DECLSPEC(noinline) +#elif TOML_CUDA // https://gitlab.gnome.org/GNOME/glib/-/issues/2555 +#define TOML_NEVER_INLINE TOML_ATTR(noinline) +#else +#if TOML_GCC || TOML_CLANG || TOML_HAS_ATTR(__noinline__) +#define TOML_NEVER_INLINE TOML_ATTR(__noinline__) +#endif +#endif +#ifndef TOML_NEVER_INLINE +#define TOML_NEVER_INLINE +#endif +#endif + +// MSVC attributes +#ifndef TOML_ABSTRACT_INTERFACE +#define TOML_ABSTRACT_INTERFACE TOML_DECLSPEC(novtable) +#endif +#ifndef TOML_EMPTY_BASES +#define TOML_EMPTY_BASES TOML_DECLSPEC(empty_bases) +#endif + +// TOML_TRIVIAL_ABI +#ifndef TOML_TRIVIAL_ABI +#if TOML_CLANG || TOML_HAS_ATTR(__trivial_abi__) +#define TOML_TRIVIAL_ABI TOML_ATTR(__trivial_abi__) +#else +#define TOML_TRIVIAL_ABI +#endif +#endif + +// TOML_NODISCARD +#ifndef TOML_NODISCARD +#if TOML_CPP >= 17 && TOML_HAS_CPP_ATTR(nodiscard) >= 201603 +#define TOML_NODISCARD [[nodiscard]] +#elif TOML_CLANG || TOML_GCC || TOML_HAS_ATTR(__warn_unused_result__) +#define TOML_NODISCARD TOML_ATTR(__warn_unused_result__) +#else +#define TOML_NODISCARD +#endif +#endif + +// TOML_NODISCARD_CTOR +#ifndef TOML_NODISCARD_CTOR +#if TOML_CPP >= 17 && TOML_HAS_CPP_ATTR(nodiscard) >= 201907 +#define TOML_NODISCARD_CTOR [[nodiscard]] +#else +#define TOML_NODISCARD_CTOR +#endif +#endif + +// pure + const +#ifndef TOML_PURE +#ifdef NDEBUG +#define TOML_PURE \ + TOML_DECLSPEC(noalias) \ + TOML_ATTR(pure) +#else +#define TOML_PURE +#endif +#endif +#ifndef TOML_CONST +#ifdef NDEBUG +#define TOML_CONST \ + TOML_DECLSPEC(noalias) \ + TOML_ATTR(const) +#else +#define TOML_CONST +#endif +#endif +#ifndef TOML_INLINE_GETTER +#define TOML_INLINE_GETTER \ + TOML_NODISCARD \ + TOML_ALWAYS_INLINE +#endif +#ifndef TOML_PURE_GETTER +#define TOML_PURE_GETTER \ + TOML_NODISCARD \ + TOML_PURE +#endif +#ifndef TOML_PURE_INLINE_GETTER +#define TOML_PURE_INLINE_GETTER \ + TOML_NODISCARD \ + TOML_ALWAYS_INLINE \ + TOML_PURE +#endif +#ifndef TOML_CONST_GETTER +#define TOML_CONST_GETTER \ + TOML_NODISCARD \ + TOML_CONST +#endif +#ifndef TOML_CONST_INLINE_GETTER +#define TOML_CONST_INLINE_GETTER \ + TOML_NODISCARD \ + TOML_ALWAYS_INLINE \ + TOML_CONST +#endif + +// TOML_ASSUME +#ifndef TOML_ASSUME +#ifdef _MSC_VER +#define TOML_ASSUME(expr) __assume(expr) +#elif TOML_ICC || TOML_CLANG || TOML_HAS_BUILTIN(__builtin_assume) +#define TOML_ASSUME(expr) __builtin_assume(expr) +#elif TOML_HAS_CPP_ATTR(assume) >= 202207 +#define TOML_ASSUME(expr) [[assume(expr)]] +#elif TOML_HAS_ATTR(__assume__) +#define TOML_ASSUME(expr) __attribute__((__assume__(expr))) +#else +#define TOML_ASSUME(expr) static_cast(0) +#endif +#endif + +// TOML_UNREACHABLE +#ifndef TOML_UNREACHABLE +#ifdef _MSC_VER +#define TOML_UNREACHABLE __assume(0) +#elif TOML_ICC || TOML_CLANG || TOML_GCC || TOML_HAS_BUILTIN(__builtin_unreachable) +#define TOML_UNREACHABLE __builtin_unreachable() +#else +#define TOML_UNREACHABLE static_cast(0) +#endif +#endif + +// TOML_LIKELY +#if TOML_CPP >= 20 && TOML_HAS_CPP_ATTR(likely) >= 201803 +#define TOML_LIKELY(...) (__VA_ARGS__) [[likely]] +#define TOML_LIKELY_CASE [[likely]] +#elif TOML_GCC || TOML_CLANG || TOML_HAS_BUILTIN(__builtin_expect) +#define TOML_LIKELY(...) (__builtin_expect(!!(__VA_ARGS__), 1)) +#else +#define TOML_LIKELY(...) (__VA_ARGS__) +#endif +#ifndef TOML_LIKELY_CASE +#define TOML_LIKELY_CASE +#endif + +// TOML_UNLIKELY +#if TOML_CPP >= 20 && TOML_HAS_CPP_ATTR(unlikely) >= 201803 +#define TOML_UNLIKELY(...) (__VA_ARGS__) [[unlikely]] +#define TOML_UNLIKELY_CASE [[unlikely]] +#elif TOML_GCC || TOML_CLANG || TOML_HAS_BUILTIN(__builtin_expect) +#define TOML_UNLIKELY(...) (__builtin_expect(!!(__VA_ARGS__), 0)) +#else +#define TOML_UNLIKELY(...) (__VA_ARGS__) +#endif +#ifndef TOML_UNLIKELY_CASE +#define TOML_UNLIKELY_CASE +#endif + +// TOML_FLAGS_ENUM +#if TOML_CLANG || TOML_HAS_ATTR(flag_enum) +#define TOML_FLAGS_ENUM __attribute__((flag_enum)) +#else +#define TOML_FLAGS_ENUM +#endif + +// TOML_OPEN_ENUM + TOML_CLOSED_ENUM +#if TOML_CLANG || TOML_HAS_ATTR(enum_extensibility) +#define TOML_OPEN_ENUM __attribute__((enum_extensibility(open))) +#define TOML_CLOSED_ENUM __attribute__((enum_extensibility(closed))) +#else +#define TOML_OPEN_ENUM +#define TOML_CLOSED_ENUM +#endif + +// TOML_OPEN_FLAGS_ENUM + TOML_CLOSED_FLAGS_ENUM +#define TOML_OPEN_FLAGS_ENUM TOML_OPEN_ENUM TOML_FLAGS_ENUM +#define TOML_CLOSED_FLAGS_ENUM TOML_CLOSED_ENUM TOML_FLAGS_ENUM + +// TOML_MAKE_FLAGS +#define TOML_MAKE_FLAGS_2(T, op, linkage) \ + TOML_CONST_INLINE_GETTER \ + linkage constexpr T operator op(T lhs, T rhs) noexcept \ + { \ + using under = std::underlying_type_t; \ + return static_cast(static_cast(lhs) op static_cast(rhs)); \ + } \ + \ + linkage constexpr T& operator TOML_CONCAT(op, =)(T & lhs, T rhs) noexcept \ + { \ + return lhs = (lhs op rhs); \ + } \ + \ + static_assert(true) +#define TOML_MAKE_FLAGS_1(T, linkage) \ + static_assert(std::is_enum_v); \ + \ + TOML_MAKE_FLAGS_2(T, &, linkage); \ + TOML_MAKE_FLAGS_2(T, |, linkage); \ + TOML_MAKE_FLAGS_2(T, ^, linkage); \ + \ + TOML_CONST_INLINE_GETTER \ + linkage constexpr T operator~(T val) noexcept \ + { \ + using under = std::underlying_type_t; \ + return static_cast(~static_cast(val)); \ + } \ + \ + TOML_CONST_INLINE_GETTER \ + linkage constexpr bool operator!(T val) noexcept \ + { \ + using under = std::underlying_type_t; \ + return !static_cast(val); \ + } \ + \ + static_assert(true) +#define TOML_MAKE_FLAGS(T) TOML_MAKE_FLAGS_1(T, ) + +#define TOML_UNUSED(...) static_cast(__VA_ARGS__) + +#define TOML_DELETE_DEFAULTS(T) \ + T(const T&) = delete; \ + T(T&&) = delete; \ + T& operator=(const T&) = delete; \ + T& operator=(T&&) = delete + +#define TOML_ASYMMETRICAL_EQUALITY_OPS(LHS, RHS, ...) \ + __VA_ARGS__ TOML_NODISCARD \ + friend bool operator==(RHS rhs, LHS lhs) noexcept \ + { \ + return lhs == rhs; \ + } \ + __VA_ARGS__ TOML_NODISCARD \ + friend bool operator!=(LHS lhs, RHS rhs) noexcept \ + { \ + return !(lhs == rhs); \ + } \ + __VA_ARGS__ TOML_NODISCARD \ + friend bool operator!=(RHS rhs, LHS lhs) noexcept \ + { \ + return !(lhs == rhs); \ + } \ + static_assert(true) + +#define TOML_EVAL_BOOL_1(T, F) T +#define TOML_EVAL_BOOL_0(T, F) F + +#if !defined(__POXY__) && !defined(POXY_IMPLEMENTATION_DETAIL) +#define POXY_IMPLEMENTATION_DETAIL(...) __VA_ARGS__ +#endif + +// COMPILER-SPECIFIC WARNING MANAGEMENT + +#if TOML_CLANG + +#define TOML_PUSH_WARNINGS \ + TOML_PRAGMA_CLANG(diagnostic push) \ + TOML_PRAGMA_CLANG(diagnostic ignored "-Wunknown-warning-option") \ + static_assert(true) + +#define TOML_DISABLE_SWITCH_WARNINGS \ + TOML_PRAGMA_CLANG(diagnostic ignored "-Wswitch") \ + static_assert(true) + +#define TOML_DISABLE_ARITHMETIC_WARNINGS \ + TOML_PRAGMA_CLANG_GE_10(diagnostic ignored "-Wimplicit-int-float-conversion") \ + TOML_PRAGMA_CLANG(diagnostic ignored "-Wfloat-equal") \ + TOML_PRAGMA_CLANG(diagnostic ignored "-Wdouble-promotion") \ + TOML_PRAGMA_CLANG(diagnostic ignored "-Wchar-subscripts") \ + TOML_PRAGMA_CLANG(diagnostic ignored "-Wshift-sign-overflow") \ + static_assert(true) + +#define TOML_DISABLE_SPAM_WARNINGS \ + TOML_PRAGMA_CLANG_GE_8(diagnostic ignored "-Wdefaulted-function-deleted") \ + TOML_PRAGMA_CLANG_GE_9(diagnostic ignored "-Wctad-maybe-unsupported") \ + TOML_PRAGMA_CLANG_GE_10(diagnostic ignored "-Wzero-as-null-pointer-constant") \ + TOML_PRAGMA_CLANG_GE_11(diagnostic ignored "-Wsuggest-destructor-override") \ + TOML_PRAGMA_CLANG(diagnostic ignored "-Wweak-vtables") \ + TOML_PRAGMA_CLANG(diagnostic ignored "-Wweak-template-vtables") \ + TOML_PRAGMA_CLANG(diagnostic ignored "-Wdouble-promotion") \ + TOML_PRAGMA_CLANG(diagnostic ignored "-Wchar-subscripts") \ + TOML_PRAGMA_CLANG(diagnostic ignored "-Wmissing-field-initializers") \ + TOML_PRAGMA_CLANG(diagnostic ignored "-Wpadded") \ + static_assert(true) + +#define TOML_POP_WARNINGS \ + TOML_PRAGMA_CLANG(diagnostic pop) \ + static_assert(true) + +#define TOML_DISABLE_WARNINGS \ + TOML_PRAGMA_CLANG(diagnostic push) \ + TOML_PRAGMA_CLANG(diagnostic ignored "-Weverything") \ + static_assert(true, "") + +#define TOML_ENABLE_WARNINGS \ + TOML_PRAGMA_CLANG(diagnostic pop) \ + static_assert(true) + +#define TOML_SIMPLE_STATIC_ASSERT_MESSAGES 1 + +#elif TOML_MSVC + +#define TOML_PUSH_WARNINGS \ + __pragma(warning(push)) \ + static_assert(true) + +#if TOML_HAS_INCLUDE() +#pragma warning(push, 0) +#include +#pragma warning(pop) +#define TOML_DISABLE_CODE_ANALYSIS_WARNINGS \ + __pragma(warning(disable : ALL_CODE_ANALYSIS_WARNINGS)) \ + static_assert(true) +#else +#define TOML_DISABLE_CODE_ANALYSIS_WARNINGS static_assert(true) +#endif + +#define TOML_DISABLE_SWITCH_WARNINGS \ + __pragma(warning(disable : 4061)) \ + __pragma(warning(disable : 4062)) \ + __pragma(warning(disable : 4063)) \ + __pragma(warning(disable : 5262)) /* switch-case implicit fallthrough (false-positive) */ \ + __pragma(warning(disable : 26819)) /* cg: unannotated fallthrough */ \ + static_assert(true) + +#define TOML_DISABLE_SPAM_WARNINGS \ + __pragma(warning(disable : 4127)) /* conditional expr is constant */ \ + __pragma(warning(disable : 4324)) /* structure was padded due to alignment specifier */ \ + __pragma(warning(disable : 4348)) \ + __pragma(warning(disable : 4464)) /* relative include path contains '..' */ \ + __pragma(warning(disable : 4505)) /* unreferenced local function removed */ \ + __pragma(warning(disable : 4514)) /* unreferenced inline function has been removed */ \ + __pragma(warning(disable : 4582)) /* constructor is not implicitly called */ \ + __pragma(warning(disable : 4619)) /* there is no warning number 'XXXX' */ \ + __pragma(warning(disable : 4623)) /* default constructor was implicitly defined as deleted */ \ + __pragma(warning(disable : 4625)) /* copy constructor was implicitly defined as deleted */ \ + __pragma(warning(disable : 4626)) /* assignment operator was implicitly defined as deleted */ \ + __pragma(warning(disable : 4710)) /* function not inlined */ \ + __pragma(warning(disable : 4711)) /* function selected for automatic expansion */ \ + __pragma(warning(disable : 4820)) /* N bytes padding added */ \ + __pragma(warning(disable : 4946)) /* reinterpret_cast used between related classes */ \ + __pragma(warning(disable : 5026)) /* move constructor was implicitly defined as deleted */ \ + __pragma(warning(disable : 5027)) /* move assignment operator was implicitly defined as deleted */ \ + __pragma(warning(disable : 5039)) /* potentially throwing function passed to 'extern "C"' function */ \ + __pragma(warning(disable : 5045)) /* Compiler will insert Spectre mitigation */ \ + __pragma(warning(disable : 5264)) /* const variable is not used (false-positive) */ \ + __pragma(warning(disable : 26451)) \ + __pragma(warning(disable : 26490)) \ + __pragma(warning(disable : 26495)) \ + __pragma(warning(disable : 26812)) \ + __pragma(warning(disable : 26819)) \ + static_assert(true) + +#define TOML_DISABLE_ARITHMETIC_WARNINGS \ + __pragma(warning(disable : 4365)) /* argument signed/unsigned mismatch */ \ + __pragma(warning(disable : 4738)) /* storing 32-bit float result in memory */ \ + __pragma(warning(disable : 5219)) /* implicit conversion from integral to float */ \ + static_assert(true) + +#define TOML_POP_WARNINGS \ + __pragma(warning(pop)) \ + static_assert(true) + +#define TOML_DISABLE_WARNINGS \ + __pragma(warning(push, 0)) \ + __pragma(warning(disable : 4348)) \ + __pragma(warning(disable : 4668)) \ + __pragma(warning(disable : 5105)) \ + __pragma(warning(disable : 5264)) \ + TOML_DISABLE_CODE_ANALYSIS_WARNINGS; \ + TOML_DISABLE_SWITCH_WARNINGS; \ + TOML_DISABLE_SPAM_WARNINGS; \ + TOML_DISABLE_ARITHMETIC_WARNINGS; \ + static_assert(true) + +#define TOML_ENABLE_WARNINGS TOML_POP_WARNINGS + +#elif TOML_ICC + +#define TOML_PUSH_WARNINGS \ + __pragma(warning(push)) \ + static_assert(true) + +#define TOML_DISABLE_SPAM_WARNINGS \ + __pragma(warning(disable : 82)) /* storage class is not first */ \ + __pragma(warning(disable : 111)) /* statement unreachable (false-positive) */ \ + __pragma(warning(disable : 869)) /* unreferenced parameter */ \ + __pragma(warning(disable : 1011)) /* missing return (false-positive) */ \ + __pragma(warning(disable : 2261)) /* assume expr side-effects discarded */ \ + static_assert(true) + +#define TOML_POP_WARNINGS \ + __pragma(warning(pop)) \ + static_assert(true) + +#define TOML_DISABLE_WARNINGS \ + __pragma(warning(push, 0)) \ + TOML_DISABLE_SPAM_WARNINGS + +#define TOML_ENABLE_WARNINGS \ + __pragma(warning(pop)) \ + static_assert(true) + +#elif TOML_GCC + +#define TOML_PUSH_WARNINGS \ + TOML_PRAGMA_GCC(diagnostic push) \ + static_assert(true) + +#define TOML_DISABLE_SWITCH_WARNINGS \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wswitch") \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wswitch-enum") \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wswitch-default") \ + static_assert(true) + +#define TOML_DISABLE_ARITHMETIC_WARNINGS \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wfloat-equal") \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wsign-conversion") \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wchar-subscripts") \ + static_assert(true) + +#define TOML_DISABLE_SUGGEST_ATTR_WARNINGS \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wsuggest-attribute=const") \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wsuggest-attribute=pure") \ + static_assert(true) + +#define TOML_DISABLE_SPAM_WARNINGS \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wpadded") \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wcast-align") \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wcomment") \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wtype-limits") \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wuseless-cast") \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wchar-subscripts") \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wsubobject-linkage") \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wmissing-field-initializers") \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wmaybe-uninitialized") \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wnoexcept") \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wnull-dereference") \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wduplicated-branches") \ + static_assert(true) + +#define TOML_POP_WARNINGS \ + TOML_PRAGMA_GCC(diagnostic pop) \ + static_assert(true) + +#define TOML_DISABLE_WARNINGS \ + TOML_PRAGMA_GCC(diagnostic push) \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wall") \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wextra") \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wpedantic") \ + TOML_DISABLE_SWITCH_WARNINGS; \ + TOML_DISABLE_ARITHMETIC_WARNINGS; \ + TOML_DISABLE_SUGGEST_ATTR_WARNINGS; \ + TOML_DISABLE_SPAM_WARNINGS; \ + static_assert(true) + +#define TOML_ENABLE_WARNINGS \ + TOML_PRAGMA_GCC(diagnostic pop) \ + static_assert(true) + +#endif + +#ifndef TOML_PUSH_WARNINGS +#define TOML_PUSH_WARNINGS static_assert(true) +#endif +#ifndef TOML_DISABLE_CODE_ANALYSIS_WARNINGS +#define TOML_DISABLE_CODE_ANALYSIS_WARNINGS static_assert(true) +#endif +#ifndef TOML_DISABLE_SWITCH_WARNINGS +#define TOML_DISABLE_SWITCH_WARNINGS static_assert(true) +#endif +#ifndef TOML_DISABLE_SUGGEST_ATTR_WARNINGS +#define TOML_DISABLE_SUGGEST_ATTR_WARNINGS static_assert(true) +#endif +#ifndef TOML_DISABLE_SPAM_WARNINGS +#define TOML_DISABLE_SPAM_WARNINGS static_assert(true) +#endif +#ifndef TOML_DISABLE_ARITHMETIC_WARNINGS +#define TOML_DISABLE_ARITHMETIC_WARNINGS static_assert(true) +#endif +#ifndef TOML_POP_WARNINGS +#define TOML_POP_WARNINGS static_assert(true) +#endif +#ifndef TOML_DISABLE_WARNINGS +#define TOML_DISABLE_WARNINGS static_assert(true) +#endif +#ifndef TOML_ENABLE_WARNINGS +#define TOML_ENABLE_WARNINGS static_assert(true) +#endif +#ifndef TOML_SIMPLE_STATIC_ASSERT_MESSAGES +#define TOML_SIMPLE_STATIC_ASSERT_MESSAGES 0 +#endif + +#ifdef TOML_CONFIG_HEADER +#include TOML_CONFIG_HEADER +#endif + +// is the library being built as a shared lib/dll using meson and friends? +#ifndef TOML_SHARED_LIB +#define TOML_SHARED_LIB 0 +#endif + +// header-only mode +#if !defined(TOML_HEADER_ONLY) && defined(TOML_ALL_INLINE) // was TOML_ALL_INLINE pre-2.0 +#define TOML_HEADER_ONLY TOML_ALL_INLINE +#endif +#if !defined(TOML_HEADER_ONLY) || (defined(TOML_HEADER_ONLY) && TOML_HEADER_ONLY) || TOML_INTELLISENSE +#undef TOML_HEADER_ONLY +#define TOML_HEADER_ONLY 1 +#endif +#if TOML_DOXYGEN || TOML_SHARED_LIB +#undef TOML_HEADER_ONLY +#define TOML_HEADER_ONLY 0 +#endif + +// internal implementation switch +#if defined(TOML_IMPLEMENTATION) || TOML_HEADER_ONLY +#undef TOML_IMPLEMENTATION +#define TOML_IMPLEMENTATION 1 +#else +#define TOML_IMPLEMENTATION 0 +#endif + +// dll/shared lib function exports (legacy - TOML_API was the old name for this setting) +#if !defined(TOML_EXPORTED_MEMBER_FUNCTION) && !defined(TOML_EXPORTED_STATIC_FUNCTION) \ + && !defined(TOML_EXPORTED_FREE_FUNCTION) && !defined(TOML_EXPORTED_CLASS) && defined(TOML_API) +#define TOML_EXPORTED_MEMBER_FUNCTION TOML_API +#define TOML_EXPORTED_STATIC_FUNCTION TOML_API +#define TOML_EXPORTED_FREE_FUNCTION TOML_API +#endif + +// dll/shared lib exports +#if TOML_SHARED_LIB +#undef TOML_API +#undef TOML_EXPORTED_CLASS +#undef TOML_EXPORTED_MEMBER_FUNCTION +#undef TOML_EXPORTED_STATIC_FUNCTION +#undef TOML_EXPORTED_FREE_FUNCTION +#if TOML_WINDOWS +#if TOML_IMPLEMENTATION +#define TOML_EXPORTED_CLASS __declspec(dllexport) +#define TOML_EXPORTED_FREE_FUNCTION __declspec(dllexport) +#else +#define TOML_EXPORTED_CLASS __declspec(dllimport) +#define TOML_EXPORTED_FREE_FUNCTION __declspec(dllimport) +#endif +#ifndef TOML_CALLCONV +#define TOML_CALLCONV __cdecl +#endif +#elif defined(__GNUC__) && __GNUC__ >= 4 +#define TOML_EXPORTED_CLASS __attribute__((visibility("default"))) +#define TOML_EXPORTED_MEMBER_FUNCTION __attribute__((visibility("default"))) +#define TOML_EXPORTED_STATIC_FUNCTION __attribute__((visibility("default"))) +#define TOML_EXPORTED_FREE_FUNCTION __attribute__((visibility("default"))) +#endif +#endif +#ifndef TOML_EXPORTED_CLASS +#define TOML_EXPORTED_CLASS +#endif +#ifndef TOML_EXPORTED_MEMBER_FUNCTION +#define TOML_EXPORTED_MEMBER_FUNCTION +#endif +#ifndef TOML_EXPORTED_STATIC_FUNCTION +#define TOML_EXPORTED_STATIC_FUNCTION +#endif +#ifndef TOML_EXPORTED_FREE_FUNCTION +#define TOML_EXPORTED_FREE_FUNCTION +#endif + +// experimental language features +#if !defined(TOML_ENABLE_UNRELEASED_FEATURES) && defined(TOML_UNRELEASED_FEATURES) // was TOML_UNRELEASED_FEATURES + // pre-3.0 +#define TOML_ENABLE_UNRELEASED_FEATURES TOML_UNRELEASED_FEATURES +#endif +#if (defined(TOML_ENABLE_UNRELEASED_FEATURES) && TOML_ENABLE_UNRELEASED_FEATURES) || TOML_INTELLISENSE +#undef TOML_ENABLE_UNRELEASED_FEATURES +#define TOML_ENABLE_UNRELEASED_FEATURES 1 +#endif +#ifndef TOML_ENABLE_UNRELEASED_FEATURES +#define TOML_ENABLE_UNRELEASED_FEATURES 0 +#endif + +// parser +#if !defined(TOML_ENABLE_PARSER) && defined(TOML_PARSER) // was TOML_PARSER pre-3.0 +#define TOML_ENABLE_PARSER TOML_PARSER +#endif +#if !defined(TOML_ENABLE_PARSER) || (defined(TOML_ENABLE_PARSER) && TOML_ENABLE_PARSER) || TOML_INTELLISENSE +#undef TOML_ENABLE_PARSER +#define TOML_ENABLE_PARSER 1 +#endif + +// formatters +#if !defined(TOML_ENABLE_FORMATTERS) || (defined(TOML_ENABLE_FORMATTERS) && TOML_ENABLE_FORMATTERS) || TOML_INTELLISENSE +#undef TOML_ENABLE_FORMATTERS +#define TOML_ENABLE_FORMATTERS 1 +#endif + +// SIMD +#if !defined(TOML_ENABLE_SIMD) || (defined(TOML_ENABLE_SIMD) && TOML_ENABLE_SIMD) || TOML_INTELLISENSE +#undef TOML_ENABLE_SIMD +#define TOML_ENABLE_SIMD 1 +#endif + +// windows compat +#if !defined(TOML_ENABLE_WINDOWS_COMPAT) && defined(TOML_WINDOWS_COMPAT) // was TOML_WINDOWS_COMPAT pre-3.0 +#define TOML_ENABLE_WINDOWS_COMPAT TOML_WINDOWS_COMPAT +#endif +#if !defined(TOML_ENABLE_WINDOWS_COMPAT) || (defined(TOML_ENABLE_WINDOWS_COMPAT) && TOML_ENABLE_WINDOWS_COMPAT) \ + || TOML_INTELLISENSE +#undef TOML_ENABLE_WINDOWS_COMPAT +#define TOML_ENABLE_WINDOWS_COMPAT 1 +#endif + +#if !TOML_WINDOWS +#undef TOML_ENABLE_WINDOWS_COMPAT +#define TOML_ENABLE_WINDOWS_COMPAT 0 +#endif + +#ifndef TOML_INCLUDE_WINDOWS_H +#define TOML_INCLUDE_WINDOWS_H 0 +#endif + +// custom optional +#ifdef TOML_OPTIONAL_TYPE +#define TOML_HAS_CUSTOM_OPTIONAL_TYPE 1 +#else +#define TOML_HAS_CUSTOM_OPTIONAL_TYPE 0 +#endif + +// exceptions (library use) +#if TOML_COMPILER_HAS_EXCEPTIONS +#if !defined(TOML_EXCEPTIONS) || (defined(TOML_EXCEPTIONS) && TOML_EXCEPTIONS) +#undef TOML_EXCEPTIONS +#define TOML_EXCEPTIONS 1 +#endif +#else +#if defined(TOML_EXCEPTIONS) && TOML_EXCEPTIONS +#error TOML_EXCEPTIONS was explicitly enabled but exceptions are disabled/unsupported by the compiler. +#endif +#undef TOML_EXCEPTIONS +#define TOML_EXCEPTIONS 0 +#endif + +// calling convention for static/free/friend functions +#ifndef TOML_CALLCONV +#define TOML_CALLCONV +#endif + +#ifndef TOML_UNDEF_MACROS +#define TOML_UNDEF_MACROS 1 +#endif + +#ifndef TOML_MAX_NESTED_VALUES +#define TOML_MAX_NESTED_VALUES 256 +// this refers to the depth of nested values, e.g. inline tables and arrays. +// 256 is crazy high! if you're hitting this limit with real input, TOML is probably the wrong tool for the job... +#endif + +#ifndef TOML_MAX_DOTTED_KEYS_DEPTH +#define TOML_MAX_DOTTED_KEYS_DEPTH 1024 +#endif + +#ifdef TOML_CHAR_8_STRINGS +#if TOML_CHAR_8_STRINGS +#error TOML_CHAR_8_STRINGS was removed in toml++ 2.0.0; all value setters and getters now work with char8_t strings implicitly. +#endif +#endif + +#ifdef TOML_LARGE_FILES +#if !TOML_LARGE_FILES +#error Support for !TOML_LARGE_FILES (i.e. 'small files') was removed in toml++ 3.0.0. +#endif +#endif + +#ifndef TOML_LIFETIME_HOOKS +#define TOML_LIFETIME_HOOKS 0 +#endif + +#ifdef NDEBUG +#undef TOML_ASSERT +#define TOML_ASSERT(expr) static_assert(true) +#endif +#ifndef TOML_ASSERT +#ifndef assert +TOML_DISABLE_WARNINGS; +#include +TOML_ENABLE_WARNINGS; +#endif +#define TOML_ASSERT(expr) assert(expr) +#endif +#ifdef NDEBUG +#define TOML_ASSERT_ASSUME(expr) TOML_ASSUME(expr) +#else +#define TOML_ASSERT_ASSUME(expr) TOML_ASSERT(expr) +#endif + +#ifndef TOML_ENABLE_FLOAT16 +#define TOML_ENABLE_FLOAT16 0 +#endif + +#ifndef TOML_DISABLE_CONDITIONAL_NOEXCEPT_LAMBDA +#define TOML_DISABLE_CONDITIONAL_NOEXCEPT_LAMBDA 0 +#endif + +#ifndef TOML_DISABLE_NOEXCEPT_NOEXCEPT +#define TOML_DISABLE_NOEXCEPT_NOEXCEPT 0 + #ifdef _MSC_VER + #if _MSC_VER <= 1943 // Up to Visual Studio 2022 Version 17.13.6 + #undef TOML_DISABLE_NOEXCEPT_NOEXCEPT + #define TOML_DISABLE_NOEXCEPT_NOEXCEPT 1 + #endif + #endif +#endif + +#if !defined(TOML_FLOAT_CHARCONV) && (TOML_GCC || TOML_CLANG || (TOML_ICC && !TOML_ICC_CL)) +// not supported by any version of GCC or Clang as of 26/11/2020 +// not supported by any version of ICC on Linux as of 11/01/2021 +#define TOML_FLOAT_CHARCONV 0 +#endif +#if !defined(TOML_INT_CHARCONV) && (defined(__EMSCRIPTEN__) || defined(__APPLE__)) +// causes link errors on emscripten +// causes Mac OS SDK version errors on some versions of Apple Clang +#define TOML_INT_CHARCONV 0 +#endif +#ifndef TOML_INT_CHARCONV +#define TOML_INT_CHARCONV 1 +#endif +#ifndef TOML_FLOAT_CHARCONV +#define TOML_FLOAT_CHARCONV 1 +#endif +#if (TOML_INT_CHARCONV || TOML_FLOAT_CHARCONV) && !TOML_HAS_INCLUDE() +#undef TOML_INT_CHARCONV +#undef TOML_FLOAT_CHARCONV +#define TOML_INT_CHARCONV 0 +#define TOML_FLOAT_CHARCONV 0 +#endif + +#if defined(__cpp_concepts) && __cpp_concepts >= 201907 +#define TOML_REQUIRES(...) requires(__VA_ARGS__) +#else +#define TOML_REQUIRES(...) +#endif +#define TOML_ENABLE_IF(...) , typename std::enable_if<(__VA_ARGS__), int>::type = 0 +#define TOML_CONSTRAINED_TEMPLATE(condition, ...) \ + template <__VA_ARGS__ TOML_ENABLE_IF(condition)> \ + TOML_REQUIRES(condition) +#define TOML_HIDDEN_CONSTRAINT(condition, ...) TOML_CONSTRAINED_TEMPLATE(condition, __VA_ARGS__) + +#if defined(__SIZEOF_FLOAT128__) && defined(__FLT128_MANT_DIG__) && defined(__LDBL_MANT_DIG__) \ + && __FLT128_MANT_DIG__ > __LDBL_MANT_DIG__ +#define TOML_FLOAT128 __float128 +#endif + +#ifdef __SIZEOF_INT128__ +#define TOML_INT128 __int128_t +#define TOML_UINT128 __uint128_t +#endif + +// clang-format off + +//******** impl/version.hpp ****************************************************************************************** + +#define TOML_LIB_MAJOR 3 +#define TOML_LIB_MINOR 4 +#define TOML_LIB_PATCH 0 + +#define TOML_LANG_MAJOR 1 +#define TOML_LANG_MINOR 0 +#define TOML_LANG_PATCH 0 + +//******** impl/preprocessor.hpp ************************************************************************************* + +#define TOML_LIB_SINGLE_HEADER 1 + +#if TOML_ENABLE_UNRELEASED_FEATURES + #define TOML_LANG_EFFECTIVE_VERSION \ + TOML_MAKE_VERSION(TOML_LANG_MAJOR, TOML_LANG_MINOR, TOML_LANG_PATCH+1) +#else + #define TOML_LANG_EFFECTIVE_VERSION \ + TOML_MAKE_VERSION(TOML_LANG_MAJOR, TOML_LANG_MINOR, TOML_LANG_PATCH) +#endif + +#define TOML_LANG_HIGHER_THAN(major, minor, patch) \ + (TOML_LANG_EFFECTIVE_VERSION > TOML_MAKE_VERSION(major, minor, patch)) + +#define TOML_LANG_AT_LEAST(major, minor, patch) \ + (TOML_LANG_EFFECTIVE_VERSION >= TOML_MAKE_VERSION(major, minor, patch)) + +#define TOML_LANG_UNRELEASED \ + TOML_LANG_HIGHER_THAN(TOML_LANG_MAJOR, TOML_LANG_MINOR, TOML_LANG_PATCH) + +#ifndef TOML_ABI_NAMESPACES + #if TOML_DOXYGEN + #define TOML_ABI_NAMESPACES 0 + #else + #define TOML_ABI_NAMESPACES 1 + #endif +#endif +#if TOML_ABI_NAMESPACES + #define TOML_NAMESPACE_START namespace toml { inline namespace TOML_CONCAT(v, TOML_LIB_MAJOR) + #define TOML_NAMESPACE_END } static_assert(true) + #define TOML_NAMESPACE ::toml::TOML_CONCAT(v, TOML_LIB_MAJOR) + #define TOML_ABI_NAMESPACE_START(name) inline namespace name { static_assert(true) + #define TOML_ABI_NAMESPACE_BOOL(cond, T, F) TOML_ABI_NAMESPACE_START(TOML_CONCAT(TOML_EVAL_BOOL_, cond)(T, F)) + #define TOML_ABI_NAMESPACE_END } static_assert(true) +#else + #define TOML_NAMESPACE_START namespace toml + #define TOML_NAMESPACE_END static_assert(true) + #define TOML_NAMESPACE toml + #define TOML_ABI_NAMESPACE_START(...) static_assert(true) + #define TOML_ABI_NAMESPACE_BOOL(...) static_assert(true) + #define TOML_ABI_NAMESPACE_END static_assert(true) +#endif +#define TOML_IMPL_NAMESPACE_START TOML_NAMESPACE_START { namespace impl +#define TOML_IMPL_NAMESPACE_END } TOML_NAMESPACE_END +#if TOML_HEADER_ONLY + #define TOML_ANON_NAMESPACE_START static_assert(TOML_IMPLEMENTATION); TOML_IMPL_NAMESPACE_START + #define TOML_ANON_NAMESPACE_END TOML_IMPL_NAMESPACE_END + #define TOML_ANON_NAMESPACE TOML_NAMESPACE::impl + #define TOML_EXTERNAL_LINKAGE inline + #define TOML_INTERNAL_LINKAGE inline +#else + #define TOML_ANON_NAMESPACE_START static_assert(TOML_IMPLEMENTATION); \ + using namespace toml; \ + namespace + #define TOML_ANON_NAMESPACE_END static_assert(true) + #define TOML_ANON_NAMESPACE + #define TOML_EXTERNAL_LINKAGE + #define TOML_INTERNAL_LINKAGE static +#endif + +// clang-format on + +// clang-format off + +#if TOML_SIMPLE_STATIC_ASSERT_MESSAGES + + #define TOML_SA_NEWLINE " " + #define TOML_SA_LIST_SEP ", " + #define TOML_SA_LIST_BEG " (" + #define TOML_SA_LIST_END ")" + #define TOML_SA_LIST_NEW " " + #define TOML_SA_LIST_NXT ", " + +#else + + #define TOML_SA_NEWLINE "\n| " + #define TOML_SA_LIST_SEP TOML_SA_NEWLINE " - " + #define TOML_SA_LIST_BEG TOML_SA_LIST_SEP + #define TOML_SA_LIST_END + #define TOML_SA_LIST_NEW TOML_SA_NEWLINE TOML_SA_NEWLINE + #define TOML_SA_LIST_NXT TOML_SA_LIST_NEW + +#endif + +#define TOML_SA_NATIVE_VALUE_TYPE_LIST \ + TOML_SA_LIST_BEG "std::string" \ + TOML_SA_LIST_SEP "int64_t" \ + TOML_SA_LIST_SEP "double" \ + TOML_SA_LIST_SEP "bool" \ + TOML_SA_LIST_SEP "toml::date" \ + TOML_SA_LIST_SEP "toml::time" \ + TOML_SA_LIST_SEP "toml::date_time" \ + TOML_SA_LIST_END + +#define TOML_SA_NODE_TYPE_LIST \ + TOML_SA_LIST_BEG "toml::table" \ + TOML_SA_LIST_SEP "toml::array" \ + TOML_SA_LIST_SEP "toml::value" \ + TOML_SA_LIST_SEP "toml::value" \ + TOML_SA_LIST_SEP "toml::value" \ + TOML_SA_LIST_SEP "toml::value" \ + TOML_SA_LIST_SEP "toml::value" \ + TOML_SA_LIST_SEP "toml::value" \ + TOML_SA_LIST_SEP "toml::value" \ + TOML_SA_LIST_END + +#define TOML_SA_UNWRAPPED_NODE_TYPE_LIST \ + TOML_SA_LIST_NEW "A native TOML value type" \ + TOML_SA_NATIVE_VALUE_TYPE_LIST \ + \ + TOML_SA_LIST_NXT "A TOML node type" \ + TOML_SA_NODE_TYPE_LIST + +// clang-format on + +TOML_PUSH_WARNINGS; +TOML_DISABLE_SPAM_WARNINGS; +TOML_DISABLE_SWITCH_WARNINGS; +TOML_DISABLE_SUGGEST_ATTR_WARNINGS; + +// misc warning false-positives +#if TOML_MSVC +#pragma warning(disable : 5031) // #pragma warning(pop): likely mismatch +#if TOML_SHARED_LIB +#pragma warning(disable : 4251) // dll exports for std lib types +#endif +#elif TOML_CLANG +TOML_PRAGMA_CLANG(diagnostic ignored "-Wheader-hygiene") +#if TOML_CLANG >= 12 +TOML_PRAGMA_CLANG(diagnostic ignored "-Wc++20-extensions") +#endif +#if TOML_CLANG == 13 +TOML_PRAGMA_CLANG(diagnostic ignored "-Wreserved-identifier") +#endif +#endif + +//******** impl/std_new.hpp ****************************************************************************************** + +TOML_DISABLE_WARNINGS; +#include +TOML_ENABLE_WARNINGS; + +#if (!defined(__apple_build_version__) && TOML_CLANG >= 8) || TOML_GCC >= 7 || TOML_ICC >= 1910 || TOML_MSVC >= 1914 +#define TOML_LAUNDER(x) __builtin_launder(x) +#elif defined(__cpp_lib_launder) && __cpp_lib_launder >= 201606 +#define TOML_LAUNDER(x) std::launder(x) +#else +#define TOML_LAUNDER(x) x +#endif + +//******** impl/std_string.hpp *************************************************************************************** + +TOML_DISABLE_WARNINGS; +#include +#include +TOML_ENABLE_WARNINGS; + +#if TOML_DOXYGEN \ + || (defined(__cpp_char8_t) && __cpp_char8_t >= 201811 && defined(__cpp_lib_char8_t) \ + && __cpp_lib_char8_t >= 201907) +#define TOML_HAS_CHAR8 1 +#else +#define TOML_HAS_CHAR8 0 +#endif + +namespace toml // non-abi namespace; this is not an error +{ + using namespace std::string_literals; + using namespace std::string_view_literals; +} + +#if TOML_ENABLE_WINDOWS_COMPAT + +TOML_IMPL_NAMESPACE_START +{ + TOML_NODISCARD + TOML_EXPORTED_FREE_FUNCTION + std::string narrow(std::wstring_view); + + TOML_NODISCARD + TOML_EXPORTED_FREE_FUNCTION + std::wstring widen(std::string_view); + +#if TOML_HAS_CHAR8 + + TOML_NODISCARD + TOML_EXPORTED_FREE_FUNCTION + std::wstring widen(std::u8string_view); + +#endif +} +TOML_IMPL_NAMESPACE_END; + +#endif // TOML_ENABLE_WINDOWS_COMPAT + +//******** impl/std_optional.hpp ************************************************************************************* + +TOML_DISABLE_WARNINGS; +#if !TOML_HAS_CUSTOM_OPTIONAL_TYPE +#include +#endif +TOML_ENABLE_WARNINGS; + +TOML_NAMESPACE_START +{ +#if TOML_HAS_CUSTOM_OPTIONAL_TYPE + + template + using optional = TOML_OPTIONAL_TYPE; + +#else + + template + using optional = std::optional; + +#endif +} +TOML_NAMESPACE_END; + +//******** impl/forward_declarations.hpp ***************************************************************************** + +TOML_DISABLE_WARNINGS; +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +TOML_ENABLE_WARNINGS; +TOML_PUSH_WARNINGS; +#ifdef _MSC_VER +#ifndef __clang__ +#pragma inline_recursion(on) +#endif +#pragma push_macro("min") +#pragma push_macro("max") +#undef min +#undef max +#endif + +#ifndef TOML_DISABLE_ENVIRONMENT_CHECKS +#define TOML_ENV_MESSAGE \ + "If you're seeing this error it's because you're building toml++ for an environment that doesn't conform to " \ + "one of the 'ground truths' assumed by the library. Essentially this just means that I don't have the " \ + "resources to test on more platforms, but I wish I did! You can try disabling the checks by defining " \ + "TOML_DISABLE_ENVIRONMENT_CHECKS, but your mileage may vary. Please consider filing an issue at " \ + "https://github.com/marzer/tomlplusplus/issues to help me improve support for your target environment. " \ + "Thanks!" + +static_assert(CHAR_BIT == 8, TOML_ENV_MESSAGE); +#ifdef FLT_RADIX +static_assert(FLT_RADIX == 2, TOML_ENV_MESSAGE); +#endif +static_assert('A' == 65, TOML_ENV_MESSAGE); +static_assert(sizeof(double) == 8, TOML_ENV_MESSAGE); +static_assert(std::numeric_limits::is_iec559, TOML_ENV_MESSAGE); +static_assert(std::numeric_limits::digits == 53, TOML_ENV_MESSAGE); +static_assert(std::numeric_limits::digits10 == 15, TOML_ENV_MESSAGE); +static_assert(std::numeric_limits::radix == 2, TOML_ENV_MESSAGE); + +#undef TOML_ENV_MESSAGE +#endif // !TOML_DISABLE_ENVIRONMENT_CHECKS + +// undocumented forward declarations are hidden from doxygen because they fuck it up =/ + +namespace toml // non-abi namespace; this is not an error +{ + using ::std::size_t; + using ::std::intptr_t; + using ::std::uintptr_t; + using ::std::ptrdiff_t; + using ::std::nullptr_t; + using ::std::int8_t; + using ::std::int16_t; + using ::std::int32_t; + using ::std::int64_t; + using ::std::uint8_t; + using ::std::uint16_t; + using ::std::uint32_t; + using ::std::uint64_t; + using ::std::uint_least32_t; + using ::std::uint_least64_t; +} + +TOML_NAMESPACE_START +{ + struct date; + struct time; + struct time_offset; + + TOML_ABI_NAMESPACE_BOOL(TOML_HAS_CUSTOM_OPTIONAL_TYPE, custopt, stdopt); + struct date_time; + TOML_ABI_NAMESPACE_END; + + struct source_position; + struct source_region; + + class node; + template + class node_view; + + class key; + class array; + class table; + template + class value; + + class path; + + class toml_formatter; + class json_formatter; + class yaml_formatter; + + TOML_ABI_NAMESPACE_BOOL(TOML_EXCEPTIONS, ex, noex); +#if TOML_EXCEPTIONS + using parse_result = table; +#else + class parse_result; +#endif + TOML_ABI_NAMESPACE_END; // TOML_EXCEPTIONS +} +TOML_NAMESPACE_END; + +TOML_IMPL_NAMESPACE_START +{ + using node_ptr = std::unique_ptr; + + TOML_ABI_NAMESPACE_BOOL(TOML_EXCEPTIONS, impl_ex, impl_noex); + class parser; + TOML_ABI_NAMESPACE_END; // TOML_EXCEPTIONS + + // clang-format off + + inline constexpr std::string_view control_char_escapes[] = + { + "\\u0000"sv, + "\\u0001"sv, + "\\u0002"sv, + "\\u0003"sv, + "\\u0004"sv, + "\\u0005"sv, + "\\u0006"sv, + "\\u0007"sv, + "\\b"sv, + "\\t"sv, + "\\n"sv, + "\\u000B"sv, + "\\f"sv, + "\\r"sv, + "\\u000E"sv, + "\\u000F"sv, + "\\u0010"sv, + "\\u0011"sv, + "\\u0012"sv, + "\\u0013"sv, + "\\u0014"sv, + "\\u0015"sv, + "\\u0016"sv, + "\\u0017"sv, + "\\u0018"sv, + "\\u0019"sv, + "\\u001A"sv, + "\\u001B"sv, + "\\u001C"sv, + "\\u001D"sv, + "\\u001E"sv, + "\\u001F"sv, + }; + + inline constexpr std::string_view node_type_friendly_names[] = + { + "none"sv, + "table"sv, + "array"sv, + "string"sv, + "integer"sv, + "floating-point"sv, + "boolean"sv, + "date"sv, + "time"sv, + "date-time"sv + }; + + // clang-format on +} +TOML_IMPL_NAMESPACE_END; + +#if TOML_ABI_NAMESPACES +#if TOML_EXCEPTIONS +#define TOML_PARSER_TYPENAME TOML_NAMESPACE::impl::impl_ex::parser +#else +#define TOML_PARSER_TYPENAME TOML_NAMESPACE::impl::impl_noex::parser +#endif +#else +#define TOML_PARSER_TYPENAME TOML_NAMESPACE::impl::parser +#endif + +namespace toml +{ +} + +TOML_NAMESPACE_START // abi namespace +{ + inline namespace literals + { + } + + enum class TOML_CLOSED_ENUM node_type : uint8_t + { + none, + table, + array, + string, + integer, + floating_point, + boolean, + date, + time, + date_time + }; + + template + inline std::basic_ostream& operator<<(std::basic_ostream& lhs, node_type rhs) + { + const auto str = impl::node_type_friendly_names[static_cast>(rhs)]; + using str_char_t = decltype(str)::value_type; + if constexpr (std::is_same_v) + return lhs << str; + else + { + if constexpr (sizeof(Char) == sizeof(str_char_t)) + return lhs << std::basic_string_view{ reinterpret_cast(str.data()), str.length() }; + else + return lhs << str.data(); + } + } + + enum class TOML_OPEN_FLAGS_ENUM value_flags : uint16_t // being an "OPEN" flags enum is not an error + { + none, + format_as_binary = 1, + format_as_octal = 2, + format_as_hexadecimal = 3, + }; + TOML_MAKE_FLAGS(value_flags); + + inline constexpr value_flags preserve_source_value_flags = + POXY_IMPLEMENTATION_DETAIL(value_flags{ static_cast>(-1) }); + + enum class TOML_CLOSED_FLAGS_ENUM format_flags : uint64_t + { + none, + quote_dates_and_times = (1ull << 0), + quote_infinities_and_nans = (1ull << 1), + allow_literal_strings = (1ull << 2), + allow_multi_line_strings = (1ull << 3), + allow_real_tabs_in_strings = (1ull << 4), + allow_unicode_strings = (1ull << 5), + allow_binary_integers = (1ull << 6), + allow_octal_integers = (1ull << 7), + allow_hexadecimal_integers = (1ull << 8), + indent_sub_tables = (1ull << 9), + indent_array_elements = (1ull << 10), + indentation = indent_sub_tables | indent_array_elements, + relaxed_float_precision = (1ull << 11), + terse_key_value_pairs = (1ull << 12), + force_multiline_arrays = (1ull << 13), + }; + TOML_MAKE_FLAGS(format_flags); + + template + struct TOML_TRIVIAL_ABI inserter + { + static_assert(std::is_reference_v); + + T value; + }; + template + inserter(T&&) -> inserter; + template + inserter(T&) -> inserter; + + using default_formatter = toml_formatter; +} +TOML_NAMESPACE_END; + +TOML_IMPL_NAMESPACE_START +{ + template + using remove_cvref = std::remove_cv_t>; + + template + using common_signed_type = std::common_type_t...>; + + template + inline constexpr bool is_one_of = (false || ... || std::is_same_v); + + template + inline constexpr bool all_integral = (std::is_integral_v && ...); + + template + inline constexpr bool is_cvref = std::is_reference_v || std::is_const_v || std::is_volatile_v; + + template + inline constexpr bool is_wide_string = + is_one_of, const wchar_t*, wchar_t*, std::wstring_view, std::wstring>; + + template + inline constexpr bool value_retrieval_is_nothrow = !std::is_same_v, std::string> +#if TOML_HAS_CHAR8 + && !std::is_same_v, std::u8string> +#endif + + && !is_wide_string; + + template + struct copy_ref_; + template + using copy_ref = typename copy_ref_::type; + + template + struct copy_ref_ + { + using type = Dest; + }; + + template + struct copy_ref_ + { + using type = std::add_lvalue_reference_t; + }; + + template + struct copy_ref_ + { + using type = std::add_rvalue_reference_t; + }; + + template + struct copy_cv_; + template + using copy_cv = typename copy_cv_::type; + + template + struct copy_cv_ + { + using type = Dest; + }; + + template + struct copy_cv_ + { + using type = std::add_const_t; + }; + + template + struct copy_cv_ + { + using type = std::add_volatile_t; + }; + + template + struct copy_cv_ + { + using type = std::add_cv_t; + }; + + template + using copy_cvref = + copy_ref, std::remove_reference_t>, Dest>, Src>; + + template + inline constexpr bool always_false = false; + + template + inline constexpr bool first_is_same = false; + template + inline constexpr bool first_is_same = true; + + template > + struct underlying_type_ + { + using type = std::underlying_type_t; + }; + template + struct underlying_type_ + { + using type = T; + }; + template + using underlying_type = typename underlying_type_::type; + + // general value traits + // (as they relate to their equivalent native TOML type) + struct default_value_traits + { + using native_type = void; + static constexpr bool is_native = false; + static constexpr bool is_losslessly_convertible_to_native = false; + static constexpr bool can_represent_native = false; + static constexpr bool can_partially_represent_native = false; + static constexpr auto type = node_type::none; + }; + + template + struct value_traits; + + template > + struct value_traits_base_selector + { + static_assert(!is_cvref); + + using type = default_value_traits; + }; + template + struct value_traits_base_selector + { + static_assert(!is_cvref); + + using type = value_traits>; + }; + + template + struct value_traits : value_traits_base_selector::type + {}; + template + struct value_traits : value_traits + {}; + template + struct value_traits : value_traits + {}; + template + struct value_traits : value_traits + {}; + template + struct value_traits : value_traits + {}; + template + struct value_traits : value_traits + {}; + + // integer value_traits specializations - standard types + template + struct integer_limits + { + static constexpr T min = T{ (std::numeric_limits>::min)() }; + static constexpr T max = T{ (std::numeric_limits>::max)() }; + }; + template + struct integer_traits_base : integer_limits + { + using native_type = int64_t; + static constexpr bool is_native = std::is_same_v, native_type>; + static constexpr bool is_signed = static_cast>(-1) < underlying_type{}; + static constexpr auto type = node_type::integer; + static constexpr bool can_partially_represent_native = true; + }; + template + struct unsigned_integer_traits : integer_traits_base + { + static constexpr bool is_losslessly_convertible_to_native = + integer_limits>::max <= 9223372036854775807ULL; + static constexpr bool can_represent_native = false; + }; + template + struct signed_integer_traits : integer_traits_base + { + using native_type = int64_t; + static constexpr bool is_losslessly_convertible_to_native = + integer_limits>::min >= (-9223372036854775807LL - 1LL) + && integer_limits>::max <= 9223372036854775807LL; + static constexpr bool can_represent_native = + integer_limits>::min <= (-9223372036854775807LL - 1LL) + && integer_limits>::max >= 9223372036854775807LL; + }; + template ::is_signed> + struct integer_traits : signed_integer_traits + {}; + template + struct integer_traits : unsigned_integer_traits + {}; + template <> + struct value_traits : integer_traits + {}; + template <> + struct value_traits : integer_traits + {}; + template <> + struct value_traits : integer_traits + {}; + template <> + struct value_traits : integer_traits + {}; + template <> + struct value_traits : integer_traits + {}; + template <> + struct value_traits : integer_traits + {}; + template <> + struct value_traits : integer_traits + {}; + template <> + struct value_traits : integer_traits + {}; + template <> + struct value_traits : integer_traits + {}; + template <> + struct value_traits : integer_traits + {}; + static_assert(value_traits::is_native); + static_assert(value_traits::is_signed); + static_assert(value_traits::is_losslessly_convertible_to_native); + static_assert(value_traits::can_represent_native); + static_assert(value_traits::can_partially_represent_native); + + // integer value_traits specializations - non-standard types +#ifdef TOML_INT128 + template <> + struct integer_limits + { + static constexpr TOML_INT128 max = + static_cast((TOML_UINT128{ 1u } << ((__SIZEOF_INT128__ * CHAR_BIT) - 1)) - 1); + static constexpr TOML_INT128 min = -max - TOML_INT128{ 1 }; + }; + template <> + struct integer_limits + { + static constexpr TOML_UINT128 min = TOML_UINT128{}; + static constexpr TOML_UINT128 max = (2u * static_cast(integer_limits::max)) + 1u; + }; + template <> + struct value_traits : integer_traits + {}; + template <> + struct value_traits : integer_traits + {}; +#endif +#ifdef TOML_SMALL_INT_TYPE + template <> + struct value_traits : signed_integer_traits + {}; +#endif + + // floating-point traits base + template + struct float_traits_base + { + static constexpr auto type = node_type::floating_point; + using native_type = double; + static constexpr bool is_native = std::is_same_v; + static constexpr bool is_signed = true; + + static constexpr int bits = static_cast(sizeof(T) * CHAR_BIT); + static constexpr int digits = MantissaDigits; + static constexpr int digits10 = DecimalDigits; + + static constexpr bool is_losslessly_convertible_to_native = bits <= 64 // + && digits <= 53 // DBL_MANT_DIG + && digits10 <= 15; // DBL_DIG + + static constexpr bool can_represent_native = digits >= 53 // DBL_MANT_DIG + && digits10 >= 15; // DBL_DIG + + static constexpr bool can_partially_represent_native = digits > 0 && digits10 > 0; + }; + template + struct float_traits : float_traits_base::digits, std::numeric_limits::digits10> + {}; +#if TOML_ENABLE_FLOAT16 + template <> + struct float_traits<_Float16> : float_traits_base<_Float16, __FLT16_MANT_DIG__, __FLT16_DIG__> + {}; +#endif +#ifdef TOML_FLOAT128 + template <> + struct float_traits : float_traits_base + {}; +#endif + + // floating-point traits + template <> + struct value_traits : float_traits + {}; + template <> + struct value_traits : float_traits + {}; + template <> + struct value_traits : float_traits + {}; +#if TOML_ENABLE_FLOAT16 + template <> + struct value_traits<_Float16> : float_traits<_Float16> + {}; +#endif +#ifdef TOML_FLOAT128 + template <> + struct value_traits : float_traits + {}; +#endif +#ifdef TOML_SMALL_FLOAT_TYPE + template <> + struct value_traits : float_traits + {}; +#endif + static_assert(value_traits::is_native); + static_assert(value_traits::is_losslessly_convertible_to_native); + static_assert(value_traits::can_represent_native); + static_assert(value_traits::can_partially_represent_native); + + // string value_traits specializations - char-based strings + template + struct string_traits + { + using native_type = std::string; + static constexpr bool is_native = std::is_same_v; + static constexpr bool is_losslessly_convertible_to_native = true; + static constexpr bool can_represent_native = + !std::is_array_v && (!std::is_pointer_v || std::is_const_v>); + static constexpr bool can_partially_represent_native = can_represent_native; + static constexpr auto type = node_type::string; + }; + template <> + struct value_traits : string_traits + {}; + template <> + struct value_traits : string_traits + {}; + template <> + struct value_traits : string_traits + {}; + template + struct value_traits : string_traits + {}; + template <> + struct value_traits : string_traits + {}; + template + struct value_traits : string_traits + {}; + + // string value_traits specializations - char8_t-based strings +#if TOML_HAS_CHAR8 + template <> + struct value_traits : string_traits + {}; + template <> + struct value_traits : string_traits + {}; + template <> + struct value_traits : string_traits + {}; + template + struct value_traits : string_traits + {}; + template <> + struct value_traits : string_traits + {}; + template + struct value_traits : string_traits + {}; +#endif + + // string value_traits specializations - wchar_t-based strings on Windows +#if TOML_ENABLE_WINDOWS_COMPAT + template + struct wstring_traits + { + using native_type = std::string; + static constexpr bool is_native = false; + static constexpr bool is_losslessly_convertible_to_native = true; // narrow + static constexpr bool can_represent_native = std::is_same_v; // widen + static constexpr bool can_partially_represent_native = can_represent_native; + static constexpr auto type = node_type::string; + }; + template <> + struct value_traits : wstring_traits + {}; + template <> + struct value_traits : wstring_traits + {}; + template <> + struct value_traits : wstring_traits + {}; + template + struct value_traits : wstring_traits + {}; + template <> + struct value_traits : wstring_traits + {}; + template + struct value_traits : wstring_traits + {}; +#endif + + // other 'native' value_traits specializations + template + struct native_value_traits + { + using native_type = T; + static constexpr bool is_native = true; + static constexpr bool is_losslessly_convertible_to_native = true; + static constexpr bool can_represent_native = true; + static constexpr bool can_partially_represent_native = true; + static constexpr auto type = NodeType; + }; + template <> + struct value_traits : native_value_traits + {}; + template <> + struct value_traits : native_value_traits + {}; + template <> + struct value_traits