diff --git a/scm/mu-scm-store.cc b/scm/mu-scm-store.cc index 37df6b6c..47408245 100644 --- a/scm/mu-scm-store.cc +++ b/scm/mu-scm-store.cc @@ -1,5 +1,5 @@ /* -** Copyright (C) 2025 Dirk-Jan C. Binnema +** Copyright (C) 2025-2026 Dirk-Jan C. Binnema ** ** This program is free software; you can redistribute it and/or modify it ** under the terms of the GNU General Public License as published by the @@ -50,16 +50,11 @@ subr_cc_store_alist(SCM store_scm) try { for (const auto& prop: Mu::Config::properties) { - // don't expose internal values & values that may change during - // runtime - if (any_of(prop.flags & - (MuConfig::Flags::Internal | MuConfig::Flags::Runtime))) + // don't expose internal/system values + if (any_of(prop.flags & (MuConfig::Flags::Internal|MuConfig::Flags::System))) continue; const auto str{conf.as_display_string(prop)}; - if (str.empty()) - continue; - const auto name{make_symbol(prop.name)}; const auto val = std::invoke([&]() { switch (prop.type) { diff --git a/scm/mu-scm.hh b/scm/mu-scm.hh index 62afaa32..83d6f4e3 100644 --- a/scm/mu-scm.hh +++ b/scm/mu-scm.hh @@ -96,9 +96,19 @@ namespace Mu::Scm { // https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2593r0.html template struct always_false : std::false_type {}; - template constexpr bool is_char_array_v = - std::is_array_v && - std::is_same_v, char>; + template + concept IsCharArray = + std::is_array_v && std::is_same_v, char>; + /**< Is this is a char-array? */ + + template + concept IsSignedIntegral = std::is_integral_v && std::is_signed_v; + /**< Is this a signed integral type? */ + + template + concept IsUnsignedIntegral = + std::is_integral_v && std::is_unsigned_v; + /**< Is this an unsigned integral type? */ /** @@ -158,11 +168,11 @@ namespace Mu::Scm { */ template SCM make_symbol(const T& val){ - using Type = std::remove_const_t; // *not* std::remove_const + using Type = std::remove_cvref_t; if constexpr (std::is_same_v || std::is_same_v) return scm_from_utf8_symboln(val.data(), val.size()); - else if constexpr (is_char_array_v|| std::is_same_v) + else if constexpr (IsCharArray || std::is_same_v) return scm_from_utf8_symbol(val); else { static_assert(always_false::value, "source type not supported"); @@ -184,15 +194,17 @@ namespace Mu::Scm { */ template T from_scm(SCM ARG, const char *func, int pos) { - const auto ensure=[&](bool pred, SCM ARG, const char *expected) { + const auto ensure = [&](bool pred, SCM ARG, const char *expected) { if (!pred) throw ScmError{ScmError::Id::WrongType, func, pos, ARG, expected}; }; // note: use the C predicates (scm_is_string etc.); the Scheme // predicates (scm_string_p etc.) return an SCM boolean, which // is truthy as a C++ bool even when it is #f. - using Type = std::remove_const_t; // *not* std::remove_const - if constexpr (std::is_same_v) { + using Type = std::remove_cvref_t; + if constexpr (std::is_same_v) { + return ARG; + } else if constexpr (std::is_same_v) { ensure(scm_is_string(ARG), ARG, "string"); size_t len{}; auto str{scm_to_utf8_stringn(ARG, &len)}; @@ -205,23 +217,23 @@ namespace Mu::Scm { } else if constexpr (std::is_same_v) { ensure(scm_is_bool(ARG), ARG, "bool"); return scm_to_bool(ARG); - } else if constexpr (std::is_same_v) { - ensure(scm_is_signed_integer(ARG, std::numeric_limits::min(), - std::numeric_limits::max()), - ARG, "integer"); + } else if constexpr (IsSignedIntegral) { + ensure(scm_is_signed_integer(ARG, std::numeric_limits::min(), + std::numeric_limits::max()), + ARG, "integer"); return scm_to_int(ARG); - } else if constexpr (std::is_same_v) { - ensure(scm_is_unsigned_integer(ARG, std::numeric_limits::min(), - std::numeric_limits::max()), - ARG, "unsigned"); + } else if constexpr (IsUnsignedIntegral) { + ensure(scm_is_unsigned_integer(ARG, std::numeric_limits::min(), + std::numeric_limits::max()), + ARG, "unsigned"); return scm_to_uint(ARG); - } else if constexpr (std::is_same_v) { - return ARG; - } else { + } else { static_assert(always_false::value, "target type not supported"); return {}; } } + + /** * Like from_SCM, but if ARG is boolean false, return default value. * @@ -245,11 +257,11 @@ namespace Mu::Scm { */ template SCM to_scm(const T& val) { - using Type = std::remove_const_t; + using Type = std::remove_cvref_t; if constexpr (std::is_same_v || std::is_same_v) return scm_from_utf8_stringn(val.data(), val.size()); - else if constexpr (is_char_array_v|| std::is_same_v) + else if constexpr (IsCharArray|| std::is_same_v) return scm_from_utf8_string(val); else if constexpr (std::is_same_v>) { SCM lst{SCM_EOL}; diff --git a/scm/mu-scm.texi b/scm/mu-scm.texi index c85e8972..560bc665 100644 --- a/scm/mu-scm.texi +++ b/scm/mu-scm.texi @@ -478,6 +478,11 @@ Example: (root-maildir . "/home/user/Maildir") (schema-version . 500)) @end lisp +Some of the fields are constant for the lifetime of the store, while others such +as the @code{last-change} may change between calls. + +All date fields are encoded as Unix seconds-since-epoch. + More fields may be added. @deffn {Scheme Procedure} root-maildir