forked from EvergreenCrypto/docker-finance
container: root: macros: add Pluggable support
- Adds requirements to support auto-(un)load'ing, refactors - Adds loader argument to unit tests and benchmarks * Filters can now be passed as a loader argument - Adds loader argument to Hash macro * Factored out from shell caller
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
// docker-finance | modern accounting for the power-user
|
// docker-finance | modern accounting for the power-user
|
||||||
//
|
//
|
||||||
// Copyright (C) 2024-2025 Aaron Fiore (Founder, Evergreen Crypto LLC)
|
// Copyright (C) 2024-2026 Aaron Fiore (Founder, Evergreen Crypto LLC)
|
||||||
//
|
//
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU General Public License as published by
|
||||||
@@ -47,8 +47,8 @@ namespace common = ::dfi::macro::common;
|
|||||||
namespace libsodium = common::crypto::libsodium;
|
namespace libsodium = common::crypto::libsodium;
|
||||||
namespace cryptopp = common::crypto::cryptopp;
|
namespace cryptopp = common::crypto::cryptopp;
|
||||||
namespace botan = common::crypto::botan;
|
namespace botan = common::crypto::botan;
|
||||||
|
|
||||||
//! \brief Hash generator macro
|
//! \brief Hash generator macro
|
||||||
|
//! \since docker-finance 1.0.0
|
||||||
class Hash final
|
class Hash final
|
||||||
{
|
{
|
||||||
//! Text description of Hash impl, encoded digest
|
//! Text description of Hash impl, encoded digest
|
||||||
@@ -248,6 +248,48 @@ class Hash final
|
|||||||
//! \param message Message to encode
|
//! \param message Message to encode
|
||||||
static void run(const std::string& message) { Hash::encode(message); }
|
static void run(const std::string& message) { Hash::encode(message); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//! \brief Pluggable entrypoint
|
||||||
|
//! \ingroup cpp_macro_impl
|
||||||
|
//! \since docker-finance 1.1.0
|
||||||
|
class hash_C final
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
hash_C() = default;
|
||||||
|
~hash_C() = default;
|
||||||
|
|
||||||
|
hash_C(const hash_C&) = default;
|
||||||
|
hash_C& operator=(const hash_C&) = default;
|
||||||
|
|
||||||
|
hash_C(hash_C&&) = default;
|
||||||
|
hash_C& operator=(hash_C&&) = default;
|
||||||
|
|
||||||
|
public:
|
||||||
|
//! \brief Macro auto-loader
|
||||||
|
//! \param arg Message to encode
|
||||||
|
static void load(const std::string& arg = {})
|
||||||
|
{
|
||||||
|
std::string message{arg};
|
||||||
|
|
||||||
|
// If no message is given, default to unique profile/subprofile
|
||||||
|
if (message.empty())
|
||||||
|
{
|
||||||
|
message += ::dfi::common::get_env("global_parent_profile");
|
||||||
|
message += ::dfi::common::get_env("global_arg_delim_1");
|
||||||
|
message += ::dfi::common::get_env("global_child_profile");
|
||||||
|
}
|
||||||
|
|
||||||
|
Hash::run(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \brief Macro auto-unloader
|
||||||
|
//! \param arg Optional code to execute before unloading
|
||||||
|
static void unload(const std::string& arg = {})
|
||||||
|
{
|
||||||
|
if (!arg.empty())
|
||||||
|
::dfi::common::line(arg);
|
||||||
|
}
|
||||||
|
};
|
||||||
} // namespace crypto
|
} // namespace crypto
|
||||||
} // namespace macro
|
} // namespace macro
|
||||||
} // namespace dfi
|
} // namespace dfi
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// docker-finance | modern accounting for the power-user
|
// docker-finance | modern accounting for the power-user
|
||||||
//
|
//
|
||||||
// Copyright (C) 2024-2025 Aaron Fiore (Founder, Evergreen Crypto LLC)
|
// Copyright (C) 2024-2026 Aaron Fiore (Founder, Evergreen Crypto LLC)
|
||||||
//
|
//
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU General Public License as published by
|
||||||
@@ -50,8 +50,8 @@ namespace botan = common::crypto::botan;
|
|||||||
#ifdef __DFI_PLUGIN_BITCOIN__
|
#ifdef __DFI_PLUGIN_BITCOIN__
|
||||||
namespace bitcoin = common::crypto::bitcoin;
|
namespace bitcoin = common::crypto::bitcoin;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//! \brief CSPRNG macro
|
//! \brief CSPRNG macro
|
||||||
|
//! \since docker-finance 1.0.0
|
||||||
class Random final
|
class Random final
|
||||||
{
|
{
|
||||||
//! Text description of number type, random number
|
//! Text description of number type, random number
|
||||||
@@ -155,6 +155,41 @@ class Random final
|
|||||||
//! \brief Wrapper to Random generator
|
//! \brief Wrapper to Random generator
|
||||||
static void run() { Random::generate(); }
|
static void run() { Random::generate(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//! \brief Pluggable entrypoint
|
||||||
|
//! \ingroup cpp_macro_impl
|
||||||
|
//! \since docker-finance 1.1.0
|
||||||
|
class random_C final
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
random_C() = default;
|
||||||
|
~random_C() = default;
|
||||||
|
|
||||||
|
random_C(const random_C&) = default;
|
||||||
|
random_C& operator=(const random_C&) = default;
|
||||||
|
|
||||||
|
random_C(random_C&&) = default;
|
||||||
|
random_C& operator=(random_C&&) = default;
|
||||||
|
|
||||||
|
public:
|
||||||
|
//! \brief Macro auto-loader
|
||||||
|
//! \param arg Optional code to execute after loading
|
||||||
|
static void load(const std::string& arg = {})
|
||||||
|
{
|
||||||
|
if (!arg.empty())
|
||||||
|
::dfi::common::line(arg);
|
||||||
|
|
||||||
|
Random::run();
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \brief Macro auto-unloader
|
||||||
|
//! \param arg Optional code to execute before unloading
|
||||||
|
static void unload(const std::string& arg = {})
|
||||||
|
{
|
||||||
|
if (!arg.empty())
|
||||||
|
::dfi::common::line(arg);
|
||||||
|
}
|
||||||
|
};
|
||||||
} // namespace crypto
|
} // namespace crypto
|
||||||
} // namespace macro
|
} // namespace macro
|
||||||
} // namespace dfi
|
} // namespace dfi
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// docker-finance | modern accounting for the power-user
|
// docker-finance | modern accounting for the power-user
|
||||||
//
|
//
|
||||||
// Copyright (C) 2021-2025 Aaron Fiore (Founder, Evergreen Crypto LLC)
|
// Copyright (C) 2021-2026 Aaron Fiore (Founder, Evergreen Crypto LLC)
|
||||||
//
|
//
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU General Public License as published by
|
||||||
@@ -61,27 +61,61 @@ class Benchmark
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
//! \brief Macro for running all benchmarks
|
//! \brief Macro for running all benchmarks
|
||||||
//! \todo parameter arg that takes list of benchmarks
|
static void run() { ::benchmark::RunSpecifiedBenchmarks(); }
|
||||||
static void run()
|
|
||||||
|
public:
|
||||||
|
static constexpr std::initializer_list<std::string_view> m_paths{
|
||||||
|
{"test/benchmark/hash.hh"},
|
||||||
|
{"test/benchmark/random.hh"},
|
||||||
|
{"test/benchmark/utility.hh"}};
|
||||||
|
};
|
||||||
|
|
||||||
|
//! \brief Pluggable entrypoint
|
||||||
|
//! \ingroup cpp_macro_impl
|
||||||
|
//! \since docker-finance 1.1.0
|
||||||
|
class benchmark_C final
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
benchmark_C() = default;
|
||||||
|
~benchmark_C() = default;
|
||||||
|
|
||||||
|
benchmark_C(const benchmark_C&) = default;
|
||||||
|
benchmark_C& operator=(const benchmark_C&) = default;
|
||||||
|
|
||||||
|
benchmark_C(benchmark_C&&) = default;
|
||||||
|
benchmark_C& operator=(benchmark_C&&) = default;
|
||||||
|
|
||||||
|
public:
|
||||||
|
//! \brief Macro auto-loader
|
||||||
|
//! \param arg Optional code to execute after loading
|
||||||
|
static void load(const std::string& arg = {})
|
||||||
{
|
{
|
||||||
static bool loaded{false};
|
for (auto path : Benchmark::m_paths)
|
||||||
static const std::initializer_list<std::string> paths{
|
::dfi::common::load(std::string{path});
|
||||||
{"test/benchmark/hash.hh"},
|
|
||||||
{"test/benchmark/random.hh"},
|
|
||||||
{"test/benchmark/utility.hh"}};
|
|
||||||
|
|
||||||
if (!loaded)
|
|
||||||
{
|
|
||||||
::dfi::common::Command::load(paths);
|
|
||||||
loaded = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO(unassigned): add argc,argv to macro/function signatures
|
|
||||||
static int argc{1};
|
static int argc{1};
|
||||||
static const char* argv{"docker-finance"};
|
static const char* argv{"docker-finance"};
|
||||||
::benchmark::Initialize(&argc, const_cast<char**>(&argv));
|
::benchmark::Initialize(&argc, const_cast<char**>(&argv));
|
||||||
::benchmark::RunSpecifiedBenchmarks();
|
|
||||||
|
// NOTE: benchmark filters can only be set via environment
|
||||||
|
// (when calling this macro via `dfi` `root`, as an argument)
|
||||||
|
Benchmark::run();
|
||||||
|
|
||||||
|
if (!arg.empty())
|
||||||
|
::dfi::common::line(arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \brief Macro auto-unloader
|
||||||
|
//! \param arg Optional code to execute before unloading
|
||||||
|
static void unload(const std::string& arg = {})
|
||||||
|
{
|
||||||
|
if (!arg.empty())
|
||||||
|
::dfi::common::line(arg);
|
||||||
|
|
||||||
::benchmark::Shutdown();
|
::benchmark::Shutdown();
|
||||||
|
|
||||||
|
for (auto path : Benchmark::m_paths)
|
||||||
|
::dfi::common::unload(std::string{path});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // namespace test
|
} // namespace test
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// docker-finance | modern accounting for the power-user
|
// docker-finance | modern accounting for the power-user
|
||||||
//
|
//
|
||||||
// Copyright (C) 2021-2025 Aaron Fiore (Founder, Evergreen Crypto LLC)
|
// Copyright (C) 2021-2026 Aaron Fiore (Founder, Evergreen Crypto LLC)
|
||||||
//
|
//
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU General Public License as published by
|
||||||
@@ -61,24 +61,57 @@ class Unit
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
//! \brief Macro for running all tests
|
//! \brief Macro for running all tests
|
||||||
//! \todo parameter arg that takes list of tests
|
static int run(const std::string& arg)
|
||||||
static int run()
|
|
||||||
{
|
{
|
||||||
static bool loaded{false};
|
::testing::GTEST_FLAG(filter) = arg.empty() ? "*" : arg;
|
||||||
static const std::initializer_list<std::string> paths{
|
return RUN_ALL_TESTS();
|
||||||
{"test/unit/hash.hh"},
|
}
|
||||||
{"test/unit/random.hh"},
|
|
||||||
{"test/unit/type.hh"},
|
|
||||||
{"test/unit/utility.hh"}};
|
|
||||||
|
|
||||||
if (!loaded)
|
public:
|
||||||
{
|
static constexpr std::initializer_list<std::string_view> m_paths{
|
||||||
::dfi::common::Command::load(paths);
|
{"test/unit/hash.hh"},
|
||||||
loaded = true;
|
{"test/unit/random.hh"},
|
||||||
}
|
{"test/unit/type.hh"},
|
||||||
|
{"test/unit/utility.hh"}};
|
||||||
|
};
|
||||||
|
|
||||||
|
//! \brief Pluggable entrypoint
|
||||||
|
//! \ingroup cpp_macro_impl
|
||||||
|
//! \since docker-finance 1.1.0
|
||||||
|
class unit_C final
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
unit_C() = default;
|
||||||
|
~unit_C() = default;
|
||||||
|
|
||||||
|
unit_C(const unit_C&) = default;
|
||||||
|
unit_C& operator=(const unit_C&) = default;
|
||||||
|
|
||||||
|
unit_C(unit_C&&) = default;
|
||||||
|
unit_C& operator=(unit_C&&) = default;
|
||||||
|
|
||||||
|
public:
|
||||||
|
//! \brief Macro auto-loader
|
||||||
|
//! \param arg GoogleTest regex filter
|
||||||
|
static void load(const std::string& arg = {})
|
||||||
|
{
|
||||||
|
for (auto path : Unit::m_paths)
|
||||||
|
::dfi::common::load(std::string{path});
|
||||||
|
|
||||||
::testing::InitGoogleTest();
|
::testing::InitGoogleTest();
|
||||||
return RUN_ALL_TESTS(); // TODO(unassigned): caller do something about this
|
|
||||||
|
Unit::run(arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \brief Macro auto-unloader
|
||||||
|
//! \param arg Optional code to execute before unloading
|
||||||
|
static void unload(const std::string& arg = {})
|
||||||
|
{
|
||||||
|
if (!arg.empty())
|
||||||
|
::dfi::common::line(arg);
|
||||||
|
|
||||||
|
for (auto path : Unit::m_paths)
|
||||||
|
::dfi::common::unload(std::string{path});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // namespace test
|
} // namespace test
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// docker-finance | modern accounting for the power-user
|
// docker-finance | modern accounting for the power-user
|
||||||
//
|
//
|
||||||
// Copyright (C) 2021-2025 Aaron Fiore (Founder, Evergreen Crypto LLC)
|
// Copyright (C) 2021-2026 Aaron Fiore (Founder, Evergreen Crypto LLC)
|
||||||
//
|
//
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU General Public License as published by
|
||||||
@@ -51,7 +51,8 @@ namespace macro
|
|||||||
namespace web
|
namespace web
|
||||||
{
|
{
|
||||||
//! \namespace dfi::macro::web::internal
|
//! \namespace dfi::macro::web::internal
|
||||||
//! \brief ROOT web-based macros for internal use only
|
//! \brief ROOT web server dfi macros for internal use only
|
||||||
|
//! \details Primarily implementation for public-consuming macros
|
||||||
//! \since docker-finance 1.0.0
|
//! \since docker-finance 1.0.0
|
||||||
namespace internal
|
namespace internal
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// docker-finance | modern accounting for the power-user
|
// docker-finance | modern accounting for the power-user
|
||||||
//
|
//
|
||||||
// Copyright (C) 2021-2025 Aaron Fiore (Founder, Evergreen Crypto LLC)
|
// Copyright (C) 2021-2026 Aaron Fiore (Founder, Evergreen Crypto LLC)
|
||||||
//
|
//
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU General Public License as published by
|
||||||
@@ -49,7 +49,8 @@ namespace macro
|
|||||||
namespace web
|
namespace web
|
||||||
{
|
{
|
||||||
//! \namespace dfi::macro::web::internal
|
//! \namespace dfi::macro::web::internal
|
||||||
//! \brief ROOT web-based macros for internal use only
|
//! \brief ROOT web server dfi macros for internal use only
|
||||||
|
//! \details Primarily implementation for public-consuming macros
|
||||||
//! \since docker-finance 1.0.0
|
//! \since docker-finance 1.0.0
|
||||||
namespace internal
|
namespace internal
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// docker-finance | modern accounting for the power-user
|
// docker-finance | modern accounting for the power-user
|
||||||
//
|
//
|
||||||
// Copyright (C) 2021-2025 Aaron Fiore (Founder, Evergreen Crypto LLC)
|
// Copyright (C) 2021-2026 Aaron Fiore (Founder, Evergreen Crypto LLC)
|
||||||
//
|
//
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU General Public License as published by
|
||||||
@@ -60,16 +60,14 @@ class Server final
|
|||||||
//! \details Registers internal macros
|
//! \details Registers internal macros
|
||||||
static void register_commands()
|
static void register_commands()
|
||||||
{
|
{
|
||||||
namespace macro = ::dfi::macro;
|
::dfi::common::load("macro/web/internal/crypto.C");
|
||||||
|
::dfi::macro::common::g_HTTPServer->RegisterCommand(
|
||||||
macro::load("macro/web/internal/crypto.C");
|
|
||||||
macro::common::g_HTTPServer->RegisterCommand(
|
|
||||||
"/rng_sample",
|
"/rng_sample",
|
||||||
"::dfi::macro::web::internal::Random::rng_sample(\"%arg1%"
|
"::dfi::macro::web::internal::Random::rng_sample(\"%arg1%"
|
||||||
"\")");
|
"\")");
|
||||||
|
|
||||||
macro::load("macro/web/internal/meta.C");
|
::dfi::common::load("macro/web/internal/meta.C");
|
||||||
macro::common::g_HTTPServer->RegisterCommand(
|
::dfi::macro::common::g_HTTPServer->RegisterCommand(
|
||||||
"/meta_sample",
|
"/meta_sample",
|
||||||
"::dfi::macro::web::internal::Meta::meta_sample(\"%arg1%"
|
"::dfi::macro::web::internal::Meta::meta_sample(\"%arg1%"
|
||||||
"\")");
|
"\")");
|
||||||
@@ -79,6 +77,41 @@ class Server final
|
|||||||
//! \brief Start webserver
|
//! \brief Start webserver
|
||||||
static void run() { Server::register_commands(); }
|
static void run() { Server::register_commands(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//! \brief Pluggable entrypoint
|
||||||
|
//! \ingroup cpp_macro_impl
|
||||||
|
//! \since docker-finance 1.1.0
|
||||||
|
class server_C final
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
server_C() = default;
|
||||||
|
~server_C() = default;
|
||||||
|
|
||||||
|
server_C(const server_C&) = default;
|
||||||
|
server_C& operator=(const server_C&) = default;
|
||||||
|
|
||||||
|
server_C(server_C&&) = default;
|
||||||
|
server_C& operator=(server_C&&) = default;
|
||||||
|
|
||||||
|
public:
|
||||||
|
//! \brief Macro auto-loader
|
||||||
|
//! \param arg Optional code to execute after loading
|
||||||
|
static void load(const std::string& arg = {})
|
||||||
|
{
|
||||||
|
if (!arg.empty())
|
||||||
|
::dfi::common::line(arg);
|
||||||
|
|
||||||
|
Server::run();
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \brief Macro auto-unloader
|
||||||
|
//! \param arg Optional code to execute before unloading
|
||||||
|
static void unload(const std::string& arg = {})
|
||||||
|
{
|
||||||
|
if (!arg.empty())
|
||||||
|
::dfi::common::line(arg);
|
||||||
|
}
|
||||||
|
};
|
||||||
} // namespace web
|
} // namespace web
|
||||||
} // namespace macro
|
} // namespace macro
|
||||||
} // namespace dfi
|
} // namespace dfi
|
||||||
|
|||||||
Reference in New Issue
Block a user