<commit_before>#pragma once

#include "acmacs-base/fmt.hh"

// ----------------------------------------------------------------------

namespace acmacs
{
    enum class debug { no, yes };
    enum class verbose { no, yes };

    template <typename Int> constexpr auto number_of_decimal_digits(Int max_value) { return static_cast<int>(std::log10(max_value)) + 1; }

    // constexpr inline debug debug_from(bool verb) { return verb ? debug::yes : debug::no; }
    constexpr inline verbose verbose_from(bool verb) { return verb ? verbose::yes : verbose::no; }

    // ----------------------------------------------------------------------

    namespace log::inline v1
    {
        struct log_key_t
        {
            explicit constexpr log_key_t(std::string_view kk) : key{kk} {}
            constexpr bool operator==(const log_key_t& rhs) const { return key == rhs.key; }
            std::string_view key;
        };

        constexpr log_key_t all{"all"};
        constexpr log_key_t timer{"timer"};
        constexpr log_key_t settings{"settings"};
        constexpr log_key_t vaccines{"vaccines"};

        namespace detail
        {
            using enabled_t = std::vector<log_key_t>;
            extern enabled_t enabled;
            extern size_t indent;
            constexpr size_t indent_size{4};
            extern bool print_debug_messages; // to disable by acmacs.r

        } // namespace detail

        inline bool is_enabled(log_key_t section)
        {
            return !detail::enabled.empty() &&
                   (detail::enabled.front() == all || std::find(std::begin(detail::enabled), std::end(detail::enabled), section) != std::end(detail::enabled));
        }

        template <typename MesssageGetter> void message(log_key_t section, MesssageGetter get_message)
        {
            if (is_enabled(section))
                fmt::print(stderr, ">>>> [{}]: {:{}s}{}\n", section.key, "", detail::indent, get_message());
        }

        void enable(std::string_view names);
        void enable(const std::vector<std::string_view>& names);

        struct indent
        {
            indent() { detail::indent += detail::indent_size; }
            ~indent() { detail::indent -= detail::indent_size; }
        };

        // ----------------------------------------------------------------------

        inline void debug_print(std::string_view prefix, std::string_view message, const char* filename, int line_no, const char* function)
        {
            if (detail::print_debug_messages)
                fmt::print(stderr, "{} {} @@ {}:{} {}\n", prefix, message, filename, line_no, function);
        }

        inline void debug_print(bool do_print, std::string_view prefix, std::string_view message, const char* filename, int line_no)
        {
            if (do_print && detail::print_debug_messages)
                fmt::print(stderr, "{} {} @@ {}:{}\n", prefix, message, filename, line_no);
        }

        inline void ad_assert(bool condition, std::string_view message, const char* filename, int line_no, const char* function)
        {
            if (!(condition)) {
                debug_print("> ASSERTION FAILED", message, filename, line_no, function);<commit_msg>getting rid of macros AD_DEBUG etc.<commit_after>#pragma once

#include "acmacs-base/fmt.hh"

// ----------------------------------------------------------------------

namespace acmacs
{
    enum class debug { no, yes };
    enum class verbose { no, yes };

    template <typename Int> constexpr auto number_of_decimal_digits(Int max_value) { return static_cast<int>(std::log10(max_value)) + 1; }

    // constexpr inline debug debug_from(bool verb) { return verb ? debug::yes : debug::no; }
    constexpr inline verbose verbose_from(bool verb) { return verb ? verbose::yes : verbose::no; }

    // ----------------------------------------------------------------------

    namespace log::inline v1
    {
        struct log_key_t
        {
            explicit constexpr log_key_t(std::string_view kk) : key{kk} {}
            constexpr bool operator==(const log_key_t& rhs) const { return key == rhs.key; }
            std::string_view key;
        };

        constexpr log_key_t all{"all"};
        constexpr log_key_t timer{"timer"};
        constexpr log_key_t settings{"settings"};
        constexpr log_key_t vaccines{"vaccines"};

        namespace detail
        {
            using enabled_t = std::vector<log_key_t>;
            extern enabled_t enabled;
            extern size_t indent;
            constexpr size_t indent_size{4};
            extern bool print_debug_messages; // to disable by acmacs.r

        } // namespace detail

        inline bool is_enabled(log_key_t section)
        {
            return !detail::enabled.empty() &&
                   (detail::enabled.front() == all || std::find(std::begin(detail::enabled), std::end(detail::enabled), section) != std::end(detail::enabled));
        }

        template <typename MesssageGetter> void message(log_key_t section, MesssageGetter get_message)
        {
            if (is_enabled(section))
                fmt::print(stderr, ">>>> [{}]: {:{}s}{}\n", section.key, "", detail::indent, get_message());
        }

        void enable(std::string_view names);
        inline void enable(log_key_t name) { return enable(name.key); }
        void enable(const std::vector<std::string_view>& names);

        struct indent
        {
            indent() { detail::indent += detail::indent_size; }
            ~indent() { detail::indent -= detail::indent_size; }
        };

        // ----------------------------------------------------------------------

        inline void debug_print(std::string_view prefix, std::string_view message, const char* filename, int line_no, const char* function)
        {
            if (detail::print_debug_messages)
                fmt::print(stderr, "{} {} @@ {}:{} {}\n", prefix, message, filename, line_no, function);
        }

        inline void debug_print(bool do_print, std::string_view prefix, std::string_view message, const char* filename, int line_no)
        {
            if (do_print && detail::print_debug_messages)
                fmt::print(stderr, "{} {} @@ {}:{}\n", prefix, message, filename, line_no);
        }

        inline void ad_assert(bool condition, std::string_view message, const char* filename, int line_no, const char* function)
        {
            if (!(condition)) {
                debug_print("> ASSERTION FAILED", message, filename, line_no, function);
{'fraction_non_alphanumeric': 0.18386405388854868, 'fraction_numerical': 0.0015309246785058174, 'mean_word_length': 2.032961931290622, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1106550', 'n_tokens_mistral': 1794, 'n_tokens_neox': 1717, 'n_words': 430}