From fbf8b7ffaee6ff4f2962ab17e17d4ae2f4b47ef2 Mon Sep 17 00:00:00 2001 From: Aaron Fiore Date: Sat, 20 Jul 2024 19:10:27 -0700 Subject: [PATCH] root: macro: factor out common code into utility --- container/src/root/macro/common/common.hh | 90 ---------------------- container/src/root/macro/common/utility.hh | 74 ++++++++++++++++++ container/src/root/macro/rootlogon.C | 35 +-------- container/src/root/macro/test/test.C | 2 +- container/src/root/macro/web/server.C | 2 +- 5 files changed, 77 insertions(+), 126 deletions(-) delete mode 100644 container/src/root/macro/common/common.hh diff --git a/container/src/root/macro/common/common.hh b/container/src/root/macro/common/common.hh deleted file mode 100644 index 9bbcec4..0000000 --- a/container/src/root/macro/common/common.hh +++ /dev/null @@ -1,90 +0,0 @@ -// docker-finance | modern accounting for the power-user -// -// Copyright (C) 2021-2024 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 . - -//! \file -//! \author Aaron Fiore (Founder, Evergreen Crypto LLC) -//! \note File intended to be loaded into ROOT.cern framework / Cling interpreter -//! \since docker-finance 1.0.0 - -#ifndef CONTAINER_SRC_ROOT_MACRO_COMMON_COMMON_HH_ -#define CONTAINER_SRC_ROOT_MACRO_COMMON_COMMON_HH_ - -#include -#include -#include - -//! \namespace docker_finance -//! \since docker-finance 1.0.0 -namespace docker_finance -{ -//! \namespace docker_finance::macro -//! \brief ROOT macros -//! \since docker-finance 1.0.0 -namespace macro -{ -//! \namespace docker_finance::macro::internal -//! \brief ROOT macros for internal use only -//! \since docker-finance 1.0.0 -namespace internal -{ -//! \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& 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::string cmd{".L ./" + path}; - Command::cmd_handler({cmd}); - } - - //! \brief Load given file paths - static void load(const std::initializer_list& commands) - { - for (const auto& cmd : commands) - Command::load(cmd); - } -}; -} // namespace internal -} // namespace macro -} // namespace docker_finance - -#endif // CONTAINER_SRC_ROOT_MACRO_COMMON_COMMON_HH_ - -// # vim: sw=2 sts=2 si ai et diff --git a/container/src/root/macro/common/utility.hh b/container/src/root/macro/common/utility.hh index 81c1363..7deac85 100644 --- a/container/src/root/macro/common/utility.hh +++ b/container/src/root/macro/common/utility.hh @@ -24,6 +24,8 @@ #define CONTAINER_SRC_ROOT_MACRO_COMMON_UTILITY_HH_ #include +#include +#include #include #include @@ -41,6 +43,47 @@ namespace macro //! \since docker-finance 1.0.0 namespace internal { +//! \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& 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::string cmd{".L ./" + path}; + Command::cmd_handler({cmd}); + } + + //! \brief Load given file paths + static void load(const std::initializer_list& commands) + { + for (const auto& cmd : commands) + Command::load(cmd); + } +}; + //! \namespace docker_finance::macro::internal::utility //! \brief To help grease the wheels of the machine //! \since docker-finance 1.0.0 @@ -71,6 +114,37 @@ std::string make_timestamp() } } // namespace utility } // namespace internal + +//! \brief Load file by path +//! \ingroup cpp_macro +//! \details +//! Example: +//!
  root [0] docker_finance::macro::load("test/test.C")
+//! +//! Will load: +//!
  root/macro/test/test.C
+//! +//! \note Parent directory is `root/macro` +void load(const std::string& path) +{ + internal::Command::load(path); +} + +//! \brief Wrapper to load files by list of paths +//! \ingroup cpp_macro +//! \details +//! Example: +//!
  root [0] docker_finance::macro::load({"test/test.C", "../src/hash.hh"})
+//! +//! Will load: +//!
  root/macro/test/test.C and root/src/hash.hh
+//! +//! \note Parent directory is `root/macro` +void load(const std::initializer_list& paths) +{ + for (const auto& path : paths) + internal::Command::load(path); +} } // namespace macro } // namespace docker_finance diff --git a/container/src/root/macro/rootlogon.C b/container/src/root/macro/rootlogon.C index 99bd7dc..3e9304c 100644 --- a/container/src/root/macro/rootlogon.C +++ b/container/src/root/macro/rootlogon.C @@ -23,12 +23,10 @@ #ifndef CONTAINER_SRC_ROOT_MACRO_ROOTLOGON_C_ #define CONTAINER_SRC_ROOT_MACRO_ROOTLOGON_C_ -#include #include -#include // NOTE: the one-and-only header at startup that's not manually loaded -#include "./common/common.hh" +#include "./common/utility.hh" //! \namespace docker_finance //! \since docker-finance 1.0.0 @@ -129,37 +127,6 @@ void help() // TODO(unassigned): add multi-threading example of generating numbers and/or hashes } - -//! \brief Load file by path -//! \ingroup cpp_macro -//! \details -//! Example: -//!
  root [0] docker_finance::macro::load("test/test.C")
-//! -//! Will load: -//!
  root/macro/test/test.C
-//! -//! \note Parent directory is `root/macro` -void load(const std::string& path) -{ - internal::Command::load(path); -} - -//! \brief Wrapper to load files by list of paths -//! \ingroup cpp_macro -//! \details -//! Example: -//!
  root [0] docker_finance::macro::load({"test/test.C", "../src/hash.hh"})
-//! -//! Will load: -//!
  root/macro/test/test.C and root/src/hash.hh
-//! -//! \note Parent directory is `root/macro` -void load(const std::initializer_list& paths) -{ - for (const auto& path : paths) - internal::Command::load(path); -} } // namespace macro } // namespace docker_finance diff --git a/container/src/root/macro/test/test.C b/container/src/root/macro/test/test.C index c1f8fa7..49cf452 100644 --- a/container/src/root/macro/test/test.C +++ b/container/src/root/macro/test/test.C @@ -30,7 +30,7 @@ #include #include -#include "../common/common.hh" +#include "../common/utility.hh" //! \namespace docker_finance //! \since docker-finance 1.0.0 diff --git a/container/src/root/macro/web/server.C b/container/src/root/macro/web/server.C index f6bb4d8..828222d 100644 --- a/container/src/root/macro/web/server.C +++ b/container/src/root/macro/web/server.C @@ -27,7 +27,7 @@ #include -#include "../common/common.hh" +#include "../common/utility.hh" //! \namespace docker_finance //! \since docker-finance 1.0.0