forked from EvergreenCrypto/docker-finance
root: macro: factor out common code into utility
This commit is contained in:
@@ -24,6 +24,8 @@
|
||||
#define CONTAINER_SRC_ROOT_MACRO_COMMON_UTILITY_HH_
|
||||
|
||||
#include <ctime>
|
||||
#include <initializer_list>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -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<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::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);
|
||||
}
|
||||
};
|
||||
|
||||
//! \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:
|
||||
//! <br>  root [0] docker_finance::macro::load("test/test.C")<br>
|
||||
//!
|
||||
//! Will load:
|
||||
//! <br>  root/macro/test/test.C<br>
|
||||
//!
|
||||
//! \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:
|
||||
//! <br>  root [0] docker_finance::macro::load({"test/test.C", "../src/hash.hh"})<br>
|
||||
//!
|
||||
//! Will load:
|
||||
//! <br>  root/macro/test/test.C and root/src/hash.hh<br>
|
||||
//!
|
||||
//! \note Parent directory is `root/macro`
|
||||
void load(const std::initializer_list<std::string>& paths)
|
||||
{
|
||||
for (const auto& path : paths)
|
||||
internal::Command::load(path);
|
||||
}
|
||||
} // namespace macro
|
||||
} // namespace docker_finance
|
||||
|
||||
|
||||
Reference in New Issue
Block a user