forked from EvergreenCrypto/docker-finance
client/container: root: refactor common namespace
- Factor out respective common from macro and apply to all scopes * `dfi::common` * `dfi::macro::common` * `dfi::plugin::common` - Add deprecation warnings in `dfi::macro::common` * Common functionality (not macro specific) is now in `dfi::common` - Add convenience wrappers to inner common impl, where appropriate * Allows for backwards compatibility - Add/update/clarify code docs and Doxygen definitions - Related refactoring NOTE: all changes are backward compatible (no need to bump major).
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) 2021-2024 Aaron Fiore (Founder, Evergreen Crypto LLC)
|
// Copyright (C) 2021-2025 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
|
||||||
@@ -100,6 +100,10 @@
|
|||||||
//! \brief Group for testing framework (benchmarks, unit testing)
|
//! \brief Group for testing framework (benchmarks, unit testing)
|
||||||
//! \since docker-finance 1.0.0
|
//! \since docker-finance 1.0.0
|
||||||
|
|
||||||
|
//! \defgroup cpp_common_impl docker-finance C++ shared common code
|
||||||
|
//! \brief Group for common functionality (internal and external)
|
||||||
|
//! \since docker-finance 1.1.0
|
||||||
|
|
||||||
//
|
//
|
||||||
// PHP
|
// PHP
|
||||||
//
|
//
|
||||||
|
|||||||
134
container/src/root/common/utility.hh
Normal file
134
container/src/root/common/utility.hh
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
// docker-finance | modern accounting for the power-user
|
||||||
|
//
|
||||||
|
// Copyright (C) 2021-2025 Aaron Fiore (Founder, Evergreen Crypto LLC)
|
||||||
|
//
|
||||||
|
// 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 Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
//! \file
|
||||||
|
//! \author Aaron Fiore (Founder, Evergreen Crypto LLC)
|
||||||
|
//! \note File intended to be loaded into ROOT.cern framework / Cling interpreter
|
||||||
|
//! \since docker-finance 1.1.0
|
||||||
|
|
||||||
|
#ifndef CONTAINER_SRC_ROOT_COMMON_UTILITY_HH_
|
||||||
|
#define CONTAINER_SRC_ROOT_COMMON_UTILITY_HH_
|
||||||
|
|
||||||
|
#include <ctime>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <initializer_list>
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
//! \namespace dfi
|
||||||
|
//! \since docker-finance 1.0.0
|
||||||
|
namespace dfi
|
||||||
|
{
|
||||||
|
//! \namespace dfi::common
|
||||||
|
//! \brief Shared common functionality
|
||||||
|
//! \since docker-finance 1.1.0
|
||||||
|
namespace common
|
||||||
|
{
|
||||||
|
//! \brief Wrapper to ROOT Cling commands
|
||||||
|
//! \ingroup cpp_common_impl
|
||||||
|
//! \since docker-finance 1.0.0
|
||||||
|
class Command
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Command() = default;
|
||||||
|
~Command() = default;
|
||||||
|
|
||||||
|
Command(const Command&) = default;
|
||||||
|
Command& operator=(const Command&) = default;
|
||||||
|
|
||||||
|
Command(Command&&) = default;
|
||||||
|
Command& operator=(Command&&) = default;
|
||||||
|
|
||||||
|
private:
|
||||||
|
static void cmd_handler(const std::initializer_list<std::string>& command)
|
||||||
|
{
|
||||||
|
for (const auto& cmd : command)
|
||||||
|
{
|
||||||
|
std::cout << "Interpreting: '" << cmd << "'" << std::endl;
|
||||||
|
gInterpreter->ProcessLine(cmd.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
//! \brief Load given file path
|
||||||
|
static void load(const std::string& path)
|
||||||
|
{
|
||||||
|
std::filesystem::path p(path);
|
||||||
|
if (!std::filesystem::exists(p))
|
||||||
|
{
|
||||||
|
throw std::runtime_error(
|
||||||
|
std::string{"'" + path + "' does not exist!"}.c_str());
|
||||||
|
}
|
||||||
|
if (!std::filesystem::is_regular_file(p))
|
||||||
|
{
|
||||||
|
throw std::runtime_error(
|
||||||
|
std::string{"'" + path + "' is not a regular file!"}.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string cmd{".L " + path};
|
||||||
|
Command::cmd_handler({cmd});
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \brief Load given file paths
|
||||||
|
static void load(const std::initializer_list<std::string>& commands)
|
||||||
|
{
|
||||||
|
for (const auto& cmd : commands)
|
||||||
|
Command::load(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(afiore): unload
|
||||||
|
};
|
||||||
|
|
||||||
|
//! \brief Get ROOT environment variable
|
||||||
|
//! \param var ROOT variable
|
||||||
|
//! \note ROOT environment variables include shell (and shell caller) environment
|
||||||
|
//! \since docker-finance 1.0.0
|
||||||
|
std::string get_env(const std::string& var)
|
||||||
|
{
|
||||||
|
const auto* env = gSystem->Getenv(var.c_str());
|
||||||
|
if (!env)
|
||||||
|
throw std::runtime_error(
|
||||||
|
std::string{var + " is not set or is unavailable"}.c_str());
|
||||||
|
return std::string{env};
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \brief Execute command in shell
|
||||||
|
//! \param cmd Shell command [args]
|
||||||
|
//! \returns Return value of command
|
||||||
|
//! \since docker-finance 1.0.0
|
||||||
|
int exec(const std::string& cmd)
|
||||||
|
{
|
||||||
|
return gSystem->Exec(cmd.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \brief Make current timestamp
|
||||||
|
//! \return timestamp in "yyyy-mm-ddThh:mm:ssZ" format
|
||||||
|
//! \since docker-finance 1.0.0
|
||||||
|
std::string make_timestamp()
|
||||||
|
{
|
||||||
|
const std::time_t t{std::time({})};
|
||||||
|
std::vector<char> time(std::size("yyyy-mm-ddThh:mm:ssZ"));
|
||||||
|
std::strftime(time.data(), time.size(), "%FT%TZ", std::gmtime(&t));
|
||||||
|
return std::string{time.data()};
|
||||||
|
}
|
||||||
|
} // namespace common
|
||||||
|
} // namespace dfi
|
||||||
|
|
||||||
|
#endif // CONTAINER_SRC_ROOT_COMMON_UTILITY_HH_
|
||||||
|
|
||||||
|
// # vim: sw=2 sts=2 si ai et
|
||||||
@@ -23,12 +23,10 @@
|
|||||||
#ifndef CONTAINER_SRC_ROOT_MACRO_COMMON_UTILITY_HH_
|
#ifndef CONTAINER_SRC_ROOT_MACRO_COMMON_UTILITY_HH_
|
||||||
#define CONTAINER_SRC_ROOT_MACRO_COMMON_UTILITY_HH_
|
#define CONTAINER_SRC_ROOT_MACRO_COMMON_UTILITY_HH_
|
||||||
|
|
||||||
#include <ctime>
|
|
||||||
#include <filesystem>
|
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
|
||||||
|
#include "../../common/utility.hh"
|
||||||
|
|
||||||
//! \namespace dfi
|
//! \namespace dfi
|
||||||
//! \since docker-finance 1.0.0
|
//! \since docker-finance 1.0.0
|
||||||
@@ -44,95 +42,8 @@ namespace macro
|
|||||||
//! \since docker-finance 1.0.0
|
//! \since docker-finance 1.0.0
|
||||||
namespace common
|
namespace common
|
||||||
{
|
{
|
||||||
//! \brief Wrapper to ROOT Cling commands
|
|
||||||
//! \ingroup cpp_macro_impl
|
|
||||||
//! \since docker-finance 1.0.0
|
|
||||||
class Command final
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Command() = default;
|
|
||||||
~Command() = default;
|
|
||||||
|
|
||||||
Command(const Command&) = default;
|
|
||||||
Command& operator=(const Command&) = default;
|
|
||||||
|
|
||||||
Command(Command&&) = default;
|
|
||||||
Command& operator=(Command&&) = default;
|
|
||||||
|
|
||||||
private:
|
|
||||||
static void cmd_handler(const std::initializer_list<std::string>& command)
|
|
||||||
{
|
|
||||||
for (const auto& cmd : command)
|
|
||||||
{
|
|
||||||
std::cout << "Interpreting: '" << cmd << "'" << std::endl;
|
|
||||||
gInterpreter->ProcessLine(cmd.c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
//! \brief Load given file path
|
|
||||||
static void load(const std::string& path)
|
|
||||||
{
|
|
||||||
std::filesystem::path p(path);
|
|
||||||
if (!std::filesystem::exists(p))
|
|
||||||
{
|
|
||||||
throw std::runtime_error(
|
|
||||||
std::string{"'" + path + "' does not exist!"}.c_str());
|
|
||||||
}
|
|
||||||
if (!std::filesystem::is_regular_file(p))
|
|
||||||
{
|
|
||||||
throw std::runtime_error(
|
|
||||||
std::string{"'" + path + "' is not a regular file!"}.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string cmd{".L " + path};
|
|
||||||
Command::cmd_handler({cmd});
|
|
||||||
}
|
|
||||||
|
|
||||||
//! \brief Load given file paths
|
|
||||||
static void load(const std::initializer_list<std::string>& commands)
|
|
||||||
{
|
|
||||||
for (const auto& cmd : commands)
|
|
||||||
Command::load(cmd);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
//! \brief Get ROOT environment variable
|
|
||||||
//! \param var ROOT variable
|
|
||||||
//! \note ROOT environment variables include shell (and shell caller) environment
|
|
||||||
//! \since docker-finance 1.0.0
|
|
||||||
std::string get_env(const std::string& var)
|
|
||||||
{
|
|
||||||
const auto* env = gSystem->Getenv(var.c_str());
|
|
||||||
if (!env)
|
|
||||||
throw std::runtime_error(
|
|
||||||
std::string{var + " is not set or is unavailable"}.c_str());
|
|
||||||
return std::string{env};
|
|
||||||
}
|
|
||||||
|
|
||||||
//! \brief Execute command in shell
|
|
||||||
//! \param cmd Shell command [args]
|
|
||||||
//! \returns Return value of command
|
|
||||||
//! \since docker-finance 1.0.0
|
|
||||||
int exec(const std::string& cmd)
|
|
||||||
{
|
|
||||||
return gSystem->Exec(cmd.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
//! \brief Make current timestamp
|
|
||||||
//! \return timestamp in "yyyy-mm-ddThh:mm:ssZ" format
|
|
||||||
//! \since docker-finance 1.0.0
|
|
||||||
std::string make_timestamp()
|
|
||||||
{
|
|
||||||
const std::time_t t{std::time({})};
|
|
||||||
std::vector<char> time(std::size("yyyy-mm-ddThh:mm:ssZ"));
|
|
||||||
std::strftime(time.data(), time.size(), "%FT%TZ", std::gmtime(&t));
|
|
||||||
return std::string{time.data()};
|
|
||||||
}
|
|
||||||
} // namespace common
|
|
||||||
|
|
||||||
//! \brief Load file by path
|
//! \brief Load file by path
|
||||||
//! \ingroup cpp_macro
|
//! \ingroup cpp_macro_impl
|
||||||
//! \details
|
//! \details
|
||||||
//! Example:
|
//! Example:
|
||||||
//! <br>  root [0] dfi::macro::load("test/unit.C")<br>
|
//! <br>  root [0] dfi::macro::load("test/unit.C")<br>
|
||||||
@@ -141,105 +52,81 @@ std::string make_timestamp()
|
|||||||
//! <br>  root/macro/test/unit.C<br>
|
//! <br>  root/macro/test/unit.C<br>
|
||||||
//!
|
//!
|
||||||
//! \note Parent directory is `root/macro`
|
//! \note Parent directory is `root/macro`
|
||||||
|
//! \todo Isolate for macros only (similar to plugins)
|
||||||
void load(const std::string& path)
|
void load(const std::string& path)
|
||||||
{
|
{
|
||||||
common::Command::load(path);
|
::dfi::common::Command::load(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \brief Wrapper to load files by list of paths
|
//! \brief Wrapper to load files by list of paths
|
||||||
//! \ingroup cpp_macro
|
//! \ingroup cpp_macro_impl
|
||||||
//! \details
|
//! \details
|
||||||
//! Example:
|
//! Example:
|
||||||
//! <br>  root [0] dfi::macro::load({"test/unit.C", "../src/hash.hh"})<br>
|
//! <br>  root [0] dfi::macro::load({"test/unit.C", "test/benchmark.C"})<br>
|
||||||
//!
|
//!
|
||||||
//! Will load:
|
//! Will load:
|
||||||
//! <br>  root/macro/test/unit.C and root/src/hash.hh<br>
|
//! <br>  root/macro/test/unit.C and root/test/benchmark.C<br>
|
||||||
//!
|
//!
|
||||||
//! \note Parent directory is `root/macro`
|
//! \note Parent directory is `root/macro`
|
||||||
|
//! \todo Isolate for macros only (similar to plugins)
|
||||||
void load(const std::initializer_list<std::string>& paths)
|
void load(const std::initializer_list<std::string>& paths)
|
||||||
{
|
{
|
||||||
for (const auto& path : paths)
|
for (const auto& path : paths)
|
||||||
common::Command::load(path);
|
::dfi::common::Command::load(path);
|
||||||
}
|
}
|
||||||
} // namespace macro
|
|
||||||
|
|
||||||
//! \namespace dfi::plugin
|
//! \deprecated This will be removed in the v2 API; use `dfi::common` namespace instead
|
||||||
//! \brief docker-finance plugins
|
//! \todo Remove in 2.0.0
|
||||||
//! \warning All plugins (repo/custom) must exist within this namespace
|
|
||||||
//! and work within their own inner namespace
|
|
||||||
//! \since docker-finance 1.0.0
|
//! \since docker-finance 1.0.0
|
||||||
namespace plugin
|
class Command : public ::dfi::common::Command
|
||||||
{
|
{
|
||||||
//! \brief Load plugin by pseudo-paths
|
};
|
||||||
//! \details Wrapper to load from directory outside of default tree
|
|
||||||
//! \param path Must be of string "repo/file" or "custom/file" where file is
|
//! \deprecated This will be removed in the v2 API; use `dfi::common` namespace instead
|
||||||
//! a plugin filename that exists in repository plugin path or
|
//! \todo Remove in 2.0.0
|
||||||
//! a client-side end-user's custom plugin path.
|
//! \since docker-finance 1.0.0
|
||||||
//! \ingroup cpp_plugin
|
std::string get_env(const std::string& var)
|
||||||
//! \details
|
{
|
||||||
//! Example:
|
return ::dfi::common::get_env(var);
|
||||||
//! <br>  root [0] dfi::plugin::load("repo/example.cc")<br>
|
}
|
||||||
//!
|
|
||||||
//! Will load:
|
//! \deprecated This will be removed in the v2 API; use `dfi::common` namespace instead
|
||||||
//! <br>  ${DOCKER_FINANCE_CONTAINER_REPO}/plugins/root/example.cc<br>
|
//! \todo Remove in 2.0.0
|
||||||
//!
|
//! \since docker-finance 1.0.0
|
||||||
//! Example:
|
int exec(const std::string& cmd)
|
||||||
//! <br>  root [0] dfi::plugin::load("custom/example.cc")<br>
|
{
|
||||||
//!
|
return ::dfi::common::exec(cmd);
|
||||||
//! Will load:
|
}
|
||||||
//! <br>  ${DOCKER_FINANCE_CLIENT_PLUGINS}/root/example.cc<br>
|
|
||||||
//!
|
//! \deprecated This will be removed in the v2 API; use `dfi::common` namespace instead
|
||||||
//! \note Parent directory for all plugins are outside of repository's `root` directory
|
//! \todo Remove in 2.0.0
|
||||||
|
//! \since docker-finance 1.0.0
|
||||||
|
std::string make_timestamp()
|
||||||
|
{
|
||||||
|
return ::dfi::common::make_timestamp();
|
||||||
|
}
|
||||||
|
} // namespace common
|
||||||
|
|
||||||
|
//! \brief Convenience wrapper to inner common loader
|
||||||
|
//! \ref dfi::macro::common::load(const std::string& path)
|
||||||
|
//! \ingroup cpp_macro
|
||||||
|
//! \since docker-finance 1.1.0
|
||||||
void load(const std::string& path)
|
void load(const std::string& path)
|
||||||
{
|
{
|
||||||
const std::string type{path.substr(0, path.find("/"))};
|
common::load(path);
|
||||||
|
|
||||||
std::string file{path};
|
|
||||||
file.erase(0, file.find("/") + 1);
|
|
||||||
|
|
||||||
if (type == "repo")
|
|
||||||
{
|
|
||||||
file.insert(
|
|
||||||
0,
|
|
||||||
macro::common::get_env("DOCKER_FINANCE_CONTAINER_REPO")
|
|
||||||
+ "/plugins/root/");
|
|
||||||
}
|
|
||||||
else if (type == "custom")
|
|
||||||
{
|
|
||||||
file.insert(
|
|
||||||
0,
|
|
||||||
macro::common::get_env("DOCKER_FINANCE_CONTAINER_PLUGINS")
|
|
||||||
+ "/root/");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::runtime_error(
|
|
||||||
"must be of type 'repo/<file>' or 'custom/<file>'");
|
|
||||||
}
|
|
||||||
|
|
||||||
macro::common::Command::load(file);
|
|
||||||
}
|
}
|
||||||
|
//! \brief Convenience wrapper to inner common loader
|
||||||
//! \brief Wrapper to load plugins by list of pseudo-paths
|
//! \ref dfi::macro::common::load(const std::initializer_list<std::string>& paths)
|
||||||
//! \ingroup cpp_plugin
|
//! \ingroup cpp_macro
|
||||||
//! \param paths List must consist of string "repo/file" or "custom/file" where file is
|
//! \since docker-finance 1.1.0
|
||||||
//! a plugin filename that exists in repository plugin path or
|
|
||||||
//! a client-side end-user's custom plugin path.
|
|
||||||
//! \details
|
|
||||||
//! Example:
|
|
||||||
//! <br>  root [0] dfi::plugin::load({"repo/example.cc", "custom/example.cc"})<br>
|
|
||||||
//!
|
|
||||||
//! Will load:
|
|
||||||
//! <br>  ${DOCKER_FINANCE_CONTAINER_REPO}/plugins/root/example.cc
|
|
||||||
//! and ${DOCKER_FINANCE_CLIENT_PLUGINS}/root/example.cc<br>
|
|
||||||
//!
|
|
||||||
//! \note Parent directory for all plugins are outside of repository's `root` directory
|
|
||||||
void load(const std::initializer_list<std::string>& paths)
|
void load(const std::initializer_list<std::string>& paths)
|
||||||
{
|
{
|
||||||
for (const auto& path : paths)
|
common::load(paths);
|
||||||
macro::common::Command::load(path);
|
|
||||||
}
|
}
|
||||||
} // namespace plugin
|
|
||||||
|
// TODO(afiore): unload
|
||||||
|
|
||||||
|
} // namespace macro
|
||||||
} // namespace dfi
|
} // namespace dfi
|
||||||
|
|
||||||
#endif // CONTAINER_SRC_ROOT_MACRO_COMMON_UTILITY_HH_
|
#endif // CONTAINER_SRC_ROOT_MACRO_COMMON_UTILITY_HH_
|
||||||
|
|||||||
@@ -25,9 +25,6 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
// NOTE: the one-and-only header at startup that's not manually loaded
|
|
||||||
#include "./common/utility.hh"
|
|
||||||
|
|
||||||
//! \namespace dfi
|
//! \namespace dfi
|
||||||
//! \since docker-finance 1.0.0
|
//! \since docker-finance 1.0.0
|
||||||
namespace dfi
|
namespace dfi
|
||||||
@@ -182,7 +179,7 @@ void rootlogon()
|
|||||||
// Add nested directory headers
|
// Add nested directory headers
|
||||||
gInterpreter->AddIncludePath("/usr/include/botan-3");
|
gInterpreter->AddIncludePath("/usr/include/botan-3");
|
||||||
|
|
||||||
// Link libraries
|
// Link default packaged libraries
|
||||||
gSystem->AddLinkedLibs("-lgtest"); // gtest/gmock
|
gSystem->AddLinkedLibs("-lgtest"); // gtest/gmock
|
||||||
gSystem->AddLinkedLibs("-lbenchmark"); // gbenchmark
|
gSystem->AddLinkedLibs("-lbenchmark"); // gbenchmark
|
||||||
gSystem->AddLinkedLibs("-pthread"); // gtest/gmock/gbenchmark
|
gSystem->AddLinkedLibs("-pthread"); // gtest/gmock/gbenchmark
|
||||||
@@ -191,7 +188,9 @@ void rootlogon()
|
|||||||
gSystem->AddLinkedLibs("-lcryptopp"); // Crypto++
|
gSystem->AddLinkedLibs("-lcryptopp"); // Crypto++
|
||||||
gSystem->AddLinkedLibs("-lsodium"); // libsodium
|
gSystem->AddLinkedLibs("-lsodium"); // libsodium
|
||||||
|
|
||||||
// Load docker-finance public API source
|
// Load default `dfi` public consumables
|
||||||
|
gInterpreter->ProcessLine(".L ../plugin/common/utility.hh");
|
||||||
|
gInterpreter->ProcessLine(".L ../macro/common/utility.hh");
|
||||||
gInterpreter->ProcessLine(".L ../src/hash.hh");
|
gInterpreter->ProcessLine(".L ../src/hash.hh");
|
||||||
gInterpreter->ProcessLine(".L ../src/random.hh");
|
gInterpreter->ProcessLine(".L ../src/random.hh");
|
||||||
gInterpreter->ProcessLine(".L ../src/utility.hh");
|
gInterpreter->ProcessLine(".L ../src/utility.hh");
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "../common/utility.hh"
|
#include "../../common/utility.hh"
|
||||||
|
|
||||||
//! \namespace dfi
|
//! \namespace dfi
|
||||||
//! \since docker-finance 1.0.0
|
//! \since docker-finance 1.0.0
|
||||||
@@ -70,10 +70,9 @@ class Benchmark
|
|||||||
{"../test/benchmark/random.hh"},
|
{"../test/benchmark/random.hh"},
|
||||||
{"../test/benchmark/utility.hh"}};
|
{"../test/benchmark/utility.hh"}};
|
||||||
|
|
||||||
namespace common = ::dfi::macro::common;
|
|
||||||
if (!loaded)
|
if (!loaded)
|
||||||
{
|
{
|
||||||
common::Command::load(paths);
|
::dfi::common::Command::load(paths);
|
||||||
loaded = true;
|
loaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "../common/utility.hh"
|
#include "../../common/utility.hh"
|
||||||
|
|
||||||
//! \namespace dfi
|
//! \namespace dfi
|
||||||
//! \since docker-finance 1.0.0
|
//! \since docker-finance 1.0.0
|
||||||
@@ -71,10 +71,9 @@ class Unit
|
|||||||
{"../test/unit/type.hh"},
|
{"../test/unit/type.hh"},
|
||||||
{"../test/unit/utility.hh"}};
|
{"../test/unit/utility.hh"}};
|
||||||
|
|
||||||
namespace common = ::dfi::macro::common;
|
|
||||||
if (!loaded)
|
if (!loaded)
|
||||||
{
|
{
|
||||||
common::Command::load(paths);
|
::dfi::common::Command::load(paths);
|
||||||
loaded = true;
|
loaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
140
container/src/root/plugin/common/utility.hh
Normal file
140
container/src/root/plugin/common/utility.hh
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
// docker-finance | modern accounting for the power-user
|
||||||
|
//
|
||||||
|
// Copyright (C) 2021-2025 Aaron Fiore (Founder, Evergreen Crypto LLC)
|
||||||
|
//
|
||||||
|
// 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 Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
//! \file
|
||||||
|
//! \author Aaron Fiore (Founder, Evergreen Crypto LLC)
|
||||||
|
//! \note File intended to be loaded into ROOT.cern framework / Cling interpreter
|
||||||
|
//! \since docker-finance 1.1.0
|
||||||
|
|
||||||
|
#ifndef CONTAINER_SRC_ROOT_PLUGIN_COMMON_UTILITY_HH_
|
||||||
|
#define CONTAINER_SRC_ROOT_PLUGIN_COMMON_UTILITY_HH_
|
||||||
|
|
||||||
|
#include <initializer_list>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "../../common/utility.hh"
|
||||||
|
|
||||||
|
//! \namespace dfi
|
||||||
|
//! \since docker-finance 1.0.0
|
||||||
|
namespace dfi
|
||||||
|
{
|
||||||
|
//! \namespace dfi::plugin
|
||||||
|
//! \brief docker-finance plugins
|
||||||
|
//! \warning All plugins (repo/custom) must exist within this namespace
|
||||||
|
//! and work within their own inner namespace
|
||||||
|
//! \since docker-finance 1.0.0
|
||||||
|
namespace plugin
|
||||||
|
{
|
||||||
|
//! \namespace dfi::plugin::common
|
||||||
|
//! \brief Shared ROOT plugin-related functionality
|
||||||
|
//! \since docker-finance 1.1.0
|
||||||
|
namespace common
|
||||||
|
{
|
||||||
|
//! \brief Load plugin by pseudo-paths
|
||||||
|
//! \details Wrapper to load from directory outside of default tree
|
||||||
|
//! \param path Must be of string "repo/file" or "custom/file" where file is
|
||||||
|
//! a plugin filename that exists in repository plugin path or
|
||||||
|
//! a client-side end-user's custom plugin path.
|
||||||
|
//! \ingroup cpp_plugin_impl
|
||||||
|
//! \details
|
||||||
|
//! Example:
|
||||||
|
//! <br>  root [0] dfi::plugin::load("repo/example.cc")<br>
|
||||||
|
//!
|
||||||
|
//! Will load:
|
||||||
|
//! <br>  ${DOCKER_FINANCE_CONTAINER_REPO}/plugins/root/example.cc<br>
|
||||||
|
//!
|
||||||
|
//! Example:
|
||||||
|
//! <br>  root [0] dfi::plugin::load("custom/example.cc")<br>
|
||||||
|
//!
|
||||||
|
//! Will load:
|
||||||
|
//! <br>  ${DOCKER_FINANCE_CLIENT_PLUGINS}/root/example.cc<br>
|
||||||
|
//!
|
||||||
|
//! \note Parent directory for all plugins are outside of repository's `root` directory
|
||||||
|
void load(const std::string& path)
|
||||||
|
{
|
||||||
|
const std::string type{path.substr(0, path.find("/"))};
|
||||||
|
|
||||||
|
std::string file{path};
|
||||||
|
file.erase(0, file.find("/") + 1);
|
||||||
|
|
||||||
|
if (type == "repo")
|
||||||
|
{
|
||||||
|
file.insert(
|
||||||
|
0,
|
||||||
|
::dfi::common::get_env("DOCKER_FINANCE_CONTAINER_REPO")
|
||||||
|
+ "/plugins/root/");
|
||||||
|
}
|
||||||
|
else if (type == "custom")
|
||||||
|
{
|
||||||
|
file.insert(
|
||||||
|
0,
|
||||||
|
::dfi::common::get_env("DOCKER_FINANCE_CONTAINER_PLUGINS")
|
||||||
|
+ "/root/");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw std::runtime_error(
|
||||||
|
"must be of type 'repo/<file>' or 'custom/<file>'");
|
||||||
|
}
|
||||||
|
|
||||||
|
::dfi::common::Command::load(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \brief Wrapper to load plugins by list of pseudo-paths
|
||||||
|
//! \ingroup cpp_plugin_impl
|
||||||
|
//! \param paths List must consist of string "repo/file" or "custom/file" where file is
|
||||||
|
//! a plugin filename that exists in repository plugin path or
|
||||||
|
//! a client-side end-user's custom plugin path.
|
||||||
|
//! \details
|
||||||
|
//! Example:
|
||||||
|
//! <br>  root [0] dfi::plugin::load({"repo/example.cc", "custom/example.cc"})<br>
|
||||||
|
//!
|
||||||
|
//! Will load:
|
||||||
|
//! <br>  ${DOCKER_FINANCE_CONTAINER_REPO}/plugins/root/example.cc
|
||||||
|
//! and ${DOCKER_FINANCE_CLIENT_PLUGINS}/root/example.cc<br>
|
||||||
|
//!
|
||||||
|
//! \note Parent directory for all plugins are outside of repository's `root` directory
|
||||||
|
void load(const std::initializer_list<std::string>& paths)
|
||||||
|
{
|
||||||
|
for (const auto& path : paths)
|
||||||
|
::dfi::plugin::common::load(path);
|
||||||
|
}
|
||||||
|
} // namespace common
|
||||||
|
|
||||||
|
//! \brief Convenience wrapper to inner common loader
|
||||||
|
//! \ingroup cpp_plugin
|
||||||
|
//! \since docker-finance 1.1.0
|
||||||
|
void load(const std::string& path)
|
||||||
|
{
|
||||||
|
common::load(path);
|
||||||
|
}
|
||||||
|
//! \brief Convenience wrapper to inner common loader
|
||||||
|
//! \ingroup cpp_plugin
|
||||||
|
//! \since docker-finance 1.1.0
|
||||||
|
void load(const std::initializer_list<std::string>& paths)
|
||||||
|
{
|
||||||
|
common::load(paths);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(afiore): unload
|
||||||
|
|
||||||
|
} // namespace plugin
|
||||||
|
} // namespace dfi
|
||||||
|
|
||||||
|
#endif // CONTAINER_SRC_ROOT_PLUGIN_COMMON_UTILITY_HH_
|
||||||
|
|
||||||
|
// # vim: sw=2 sts=2 si ai et
|
||||||
Reference in New Issue
Block a user