pmt: reformat code, etc.

This commit is contained in:
2025-11-24 18:50:57 +03:00
parent 579b2623a4
commit 11d75e401e
30 changed files with 755 additions and 647 deletions

View File

@@ -34,31 +34,31 @@
#define PART_MAP (*VARS.PartMap)
namespace PartitionManager {
int Main(int argc, char **argv);
int Main(int argc, char** argv);
// Print messages if not using quiet mode
__attribute__((format(printf, 1, 2))) void print(const char *format, ...);
__attribute__((format(printf, 1, 2))) void println(const char *format, ...);
__attribute__((format(printf, 1, 2))) void print(const char* format, ...);
__attribute__((format(printf, 1, 2))) void println(const char* format, ...);
// If there is a delimiter in the string, CLI::detail::split returns; if not, an
// empty vector is returned. And checks duplicate arguments.
std::vector<std::string> splitIfHasDelim(const std::string &s, char delim,
std::vector<std::string> splitIfHasDelim(const std::string& s, char delim,
bool checkForBadUsage = false);
// Process vectors with input strings. Use for [flag(s)]-[other flag(s)]
// situations
void processCommandLine(std::vector<std::string> &vec1,
std::vector<std::string> &vec2, const std::string &s1,
const std::string &s2, char delim,
void processCommandLine(std::vector<std::string>& vec1,
std::vector<std::string>& vec2, const std::string& s1,
const std::string& s2, char delim,
bool checkForBadUsage = false);
// Setting ups buffer size
void setupBufferSize(uint64_t &size, const std::string &entry);
void setupBufferSize(uint64_t& size, const std::string& entry);
std::string getLibVersion();
std::string getAppVersion(); // Not Android app version (an Android app is
// planned!), tells pmt version.
std::string getAppVersion(); // Not Android app version (an Android app is
// planned!), tells pmt version.
enum basic_function_flags {
NO_SU = 1,
@@ -68,28 +68,29 @@ enum basic_function_flags {
// All function classes must inherit from this class.
class basic_function {
public:
CLI::App *cmd = nullptr;
public:
CLI::App* cmd = nullptr;
std::vector<int> flags = {};
virtual bool init(CLI::App &_app) = 0;
virtual bool init(CLI::App& _app) = 0;
virtual bool run() = 0;
[[nodiscard]] virtual bool isUsed() const = 0;
[[nodiscard]] virtual const char *name() const = 0;
[[nodiscard]] virtual const char* name() const = 0;
virtual ~basic_function() = default;
};
// A class for function management.
template <class _Type> class basic_manager {
private:
template <class _Type>
class basic_manager {
private:
std::vector<std::unique_ptr<_Type>> _functions;
public:
void registerFunction(std::unique_ptr<_Type> _func, CLI::App &_app) {
public:
void registerFunction(std::unique_ptr<_Type> _func, CLI::App& _app) {
LOGN(PMTF, INFO) << "registering: " << _func->name() << std::endl;
for (const auto &f : _functions) {
for (const auto& f : _functions) {
if (std::string(_func->name()) == std::string(f->name())) {
LOGN(PMTF, INFO) << "Is already registered: " << _func->name()
<< ". Skipping." << std::endl;
@@ -104,7 +105,7 @@ public:
}
[[nodiscard]] bool hasFlagOnUsedFunction(int flag) const {
for (const auto &func : _functions) {
for (const auto& func : _functions) {
if (func->isUsed()) {
std::for_each(func->flags.begin(), func->flags.end(), [&](const int x) {
LOGN(PMTF, INFO) << "Used flag " << x << " on " << func->name()
@@ -117,9 +118,9 @@ public:
return false;
}
[[nodiscard]] bool isUsed(const std::string &name) const {
[[nodiscard]] bool isUsed(const std::string& name) const {
if (_functions.empty()) return false;
for (const auto &func : _functions) {
for (const auto& func : _functions) {
if (func->name() == name) return func->isUsed();
}
return false;
@@ -127,7 +128,7 @@ public:
[[nodiscard]] bool handleAll() const {
LOGN(PMTF, INFO) << "running caught commands in command-line." << std::endl;
for (const auto &func : _functions) {
for (const auto& func : _functions) {
if (func->isUsed()) {
LOGN(PMTF, INFO) << func->name()
<< " is calling because used in command-line."
@@ -144,7 +145,7 @@ public:
};
class basic_variables final {
public:
public:
basic_variables();
std::unique_ptr<PartitionMap::BuildMap> PartMap;
@@ -165,6 +166,6 @@ using Error = Helper::Error;
extern std::unique_ptr<VariableTable> Variables;
extern FILE *pstdout, *pstderr;
} // namespace PartitionManager
} // namespace PartitionManager
#endif // #ifndef LIBPMT_LIB_HPP
#endif // #ifndef LIBPMT_LIB_HPP