pmt: Improve performance and functions

- Added two new functions
 - Improved functions
 - Reformatted code (scripts and src/ include/)
 - Increased processing speed with multi-threading
This commit is contained in:
2025-08-07 14:49:24 +03:00
parent 6294482b39
commit 8b3e886eee
17 changed files with 678 additions and 453 deletions

View File

@@ -34,73 +34,82 @@
#define PMTF "libpmt-function-manager"
namespace PartitionManager {
// All function classes must inherit from this class.
class basic_function {
public:
CLI::App *cmd = nullptr;
// All function classes must inherit from this class.
class basic_function {
public:
CLI::App* cmd = nullptr;
virtual bool init(CLI::App &_app) = 0;
virtual bool run() = 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;
virtual ~basic_function() = default;
};
[[nodiscard]] virtual bool isUsed() const = 0;
[[nodiscard]] virtual const char *name() const = 0;
// A class for function management.
class basic_function_manager final {
private:
std::vector<std::unique_ptr<basic_function>> _functions;
virtual ~basic_function() = default;
};
public:
void registerFunction(std::unique_ptr<basic_function> _func, CLI::App& _app);
// A class for function management.
class basic_function_manager final {
private:
std::vector<std::unique_ptr<basic_function> > _functions;
[[nodiscard]] bool handleAll() const;
};
public:
void registerFunction(std::unique_ptr<basic_function> _func, CLI::App &_app);
// Sets logs file automatically
class logSetter final { public: logSetter(); };
[[nodiscard]] bool handleAll() const;
};
class basic_variables final {
private:
logSetter setLogSetting;
// Sets logs file automatically
class logSetter final { public: logSetter(); };
public:
basic_variables();
~basic_variables();
class basic_variables final {
private:
logSetter setLogSetting;
PartitionMap::BuildMap* PartMap;
public:
basic_variables();
~basic_variables();
std::string searchPath, logFile;
bool onLogical;
bool quietProcess;
bool verboseMode;
bool viewVersion;
bool forceProcess;
};
PartitionMap::BuildMap *PartMap;
using FunctionBase = basic_function;
using FunctionManager = basic_function_manager;
using VariableTable = basic_variables;
using Error = Helper::Error;
std::string searchPath, logFile;
bool onLogical;
bool quietProcess;
bool verboseMode;
bool viewVersion;
bool forceProcess;
};
extern VariableTable* Variables;
using FunctionBase = basic_function;
using FunctionManager = basic_function_manager;
using VariableTable = basic_variables;
using Error = Helper::Error;
int Main(int argc, char** argv);
extern VariableTable *Variables;
// Print messages if not using quiet mode
__attribute__((format(printf, 1, 2)))
void print(const char* format, ...);
int Main(int argc, char **argv);
// 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, bool checkForBadUsage = false);
// Print messages if not using quiet mode
__attribute__((format(printf, 1, 2)))
void print(const char *format, ...);
// 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, bool checkForBadUsage = false);
// Format it input and return
__attribute__((format(printf, 1, 2)))
std::string format(const char *format, ...);
std::string getLibVersion();
std::string getAppVersion(); // Not Android app version (an Android app is planned!), tells pmt version.
// 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, 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, bool checkForBadUsage = false);
// Setting ups buffer size
void setupBufferSize(int &size, const std::string &partition);
std::string getLibVersion();
std::string getAppVersion(); // Not Android app version (an Android app is planned!), tells pmt version.
} // namespace PartitionManager
#endif // #ifndef LIBPMT_LIB_HPP