#pragma once #if !defined(__cplusplus) || __cplusplus < 202002L #error "This code requires C++20 or later" #endif #include "tomlc17.h" #include #include #include #include #include namespace toml { class Datum : public toml_datum_t { public: using datetime = std::chrono::sys_time; using time = std::chrono::hh_mm_ss; using date = std::chrono::year_month_day; Datum(toml_datum_t dat = toml_datum_t{}) : toml_datum_t(dat) {} bool is_table() const { return type == TOML_TABLE; } bool is_array() const { return type == TOML_ARRAY; } // Retrieve a string. std::optional as_str() const { if (type != TOML_STRING) return std::nullopt; else return std::string_view{u.str.ptr, (size_t)u.str.len}; } // Retrieve an int. std::optional as_int() const { if (type != TOML_INT64) return std::nullopt; else return u.int64; } // Retrieve a float. std::optional as_real() const { if (type != TOML_FP64) return std::nullopt; else return u.fp64; } // Retrieve a boolean. std::optional as_bool() const { if (type != TOML_BOOLEAN) return std::nullopt; else return !!u.boolean; } // Retrieve a date. std::optional as_date() const { using namespace std::chrono; if (type != TOML_DATE) return std::nullopt; else return date{year(u.ts.year), month(u.ts.month), day(u.ts.day)}; } // Retrieve a time. std::optional