diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 67edf50..8450573 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -4,7 +4,8 @@ "includePath": [ "${workspaceFolder}/srclib/libhelper/include", "${workspaceFolder}/srclib/libpartition_map/include", - "${workspaceFolder}/include" + "${workspaceFolder}/include", + "${workspaceFolder}/src/functions" ] } ], diff --git a/include/PartitionManager/lib.hpp b/include/PartitionManager/lib.hpp index 40d4f27..09a4867 100755 --- a/include/PartitionManager/lib.hpp +++ b/include/PartitionManager/lib.hpp @@ -29,36 +29,41 @@ #include #include #include +#include #include #include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignore "-Wdeprecated-declarations" +#include +#pragma GCC diagnostic pop + #define PMT "libpmt" #define PMTE "pmt" #define PMTF "libpmt-function-manager" -#ifdef NEED_BASIC_FUNCTION_CLASSES -#include -#pragma GCC diagnostic push -#pragma GCC diagnostic ignore "-Wdeprecated-declarations" -#include -#pragma GCC diagnostic pop -#endif // #ifdef NEED_BASIC_FUNCTION_CLASSES - namespace PartitionManager { -class basic_function { /** - * Example variables for writing your function: - * public: - * CLI::App cmd* = nullptr; + * basic_function + * -------------- + * 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 const char* name() = 0; virtual ~basic_function() = default; }; +/** + * basic_function_manager + * ---------------------- + * A class for function management. + */ class basic_function_manager { private: std::vector> _functions; @@ -93,7 +98,7 @@ VariableTable* Variables; int Main(int argc, char** argv); std::string getLibVersion(); -std::string getAppVersion(); // Not Android app version (an Android app is planned!), tells pmt and libs versions. +std::string getAppVersion(); // Not Android app version (an Android app is planned!), tells pmt version. } // namespace PartitionManager diff --git a/src/FunctionManager.cpp b/src/FunctionManager.cpp index 11853b8..a7eb832 100755 --- a/src/FunctionManager.cpp +++ b/src/FunctionManager.cpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include namespace PartitionManager { diff --git a/src/Lib.cpp b/src/Lib.cpp index 8ca429b..dd38e39 100755 --- a/src/Lib.cpp +++ b/src/Lib.cpp @@ -17,17 +17,18 @@ #include #include #include -#include +#include +#include #include "functions/functions.hpp" namespace PartitionManager { -VariableTable::VariableTable() : PartMap(), - searchPath(""), - onLogical(false), - silentProcess(false), - verboseMode(false), - viewVersion(false) +basic_variables::basic_variables() : PartMap(), + searchPath(""), + onLogical(false), + silentProcess(false), + verboseMode(false), + viewVersion(false) {} VariableTable* Variables = new VariableTable(); @@ -44,10 +45,10 @@ try { // try-catch start AppMain.add_flag("-V,--verbose", Variables->verboseMode, "Detailed information is written on the screen while the transaction is being carried out"); AppMain.add_flag("-v,--version", Variables->viewVersion, "Print version and exit"); - FuncManager.registerFunction(std::make_unique, AppMain); - FuncManager.registerFunction(std::make_unique, AppMain); - FuncManager.registerFunction(std::make_unique, AppMain); - FuncManager.registerFunction(std::make_unique, AppMain); + FuncManager.registerFunction(std::make_unique(), AppMain); + FuncManager.registerFunction(std::make_unique(), AppMain); + FuncManager.registerFunction(std::make_unique(), AppMain); + FuncManager.registerFunction(std::make_unique(), AppMain); CLI11_PARSE(AppMain, argc, argv); @@ -56,7 +57,7 @@ try { // try-catch start LOGN(PMTE, INFO) << "used command: " << used << std::endl; if (!Variables->searchPath.empty()) - Variables->PartMap(searchPath); + Variables->PartMap(Variables->searchPath); if (!Variables->PartMap) { if (Variables->searchPath.empty()) @@ -67,7 +68,7 @@ try { // try-catch start } catch (Helper::Error &error) { // catch Helper::Error - if (!Variables->silentProcess) fprintf(stde9rr, "%s: %s.\n", argv[0], error.what()); + if (!Variables->silentProcess) fprintf(stderr, "%s: %s.\n", argv[0], error.what()); delete Variables; return -1; @@ -79,4 +80,18 @@ try { // try-catch start } // try-catch block end } +std::string getLibVersion() +{ + char vinfo[512]; + sprintf(vinfo, MKVERSION("libpmt")); + return std::string(vinfo); +} + +std::string getAppVersion() +{ + char vinfo[512]; + sprintf(vinfo, MKVERSION("pmt")); + return std::string(vinfo); +} + } // namespace PartitionManager diff --git a/src/Main.cpp b/src/Main.cpp index 7f1e68e..aac9596 100755 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -14,7 +14,7 @@ limitations under the License. */ -#include +#include int main(int argc, char** argv) { diff --git a/src/functions/functions.hpp b/src/functions/functions.hpp index 9d97b42..f9e090d 100755 --- a/src/functions/functions.hpp +++ b/src/functions/functions.hpp @@ -14,7 +14,7 @@ limitations under the License. */ -#include +#include namespace PartitionManager { diff --git a/srclib/libhelper/include/libhelper/lib.hpp b/srclib/libhelper/include/libhelper/lib.hpp index 83683f8..4cd0689 100755 --- a/srclib/libhelper/include/libhelper/lib.hpp +++ b/srclib/libhelper/include/libhelper/lib.hpp @@ -81,7 +81,7 @@ void set(std::string_view name, std::string_view file); void setProgramName(std::string_view name); void setLogFile(std::string_view file); void setPrinting(int state); -void setLoggingState(int state); // Disable/enable logginf +void setLoggingState(int state); // Disable/enable logging void reset(); } // namespace LoggingProperties @@ -196,4 +196,7 @@ std::string getLibVersion(); #define LOGNF_IF(name, file, level, condition) \ if (condition) Helper::Logger(level, __func__, file, name, __FILE__, __LINE__) +#define MKVERSION(name) \ + "%s %s [%s %s]\nBuildType: %s\nCMakeVersion: %s\nCompilerVersion: %s\nBuildFlags: %s\n", name, BUILD_VERSION, BUILD_DATE, BUILD_TIME, BUILD_TYPE, BUILD_CMAKE_VERSION, BUILD_COMPILER_VERSION, BUILD_FLAGS + #endif // #ifndef LIBHELPER_LIB_HPP diff --git a/srclib/libhelper/src/Utilities.cpp b/srclib/libhelper/src/Utilities.cpp index 745c9a3..4d0065c 100755 --- a/srclib/libhelper/src/Utilities.cpp +++ b/srclib/libhelper/src/Utilities.cpp @@ -173,7 +173,7 @@ std::string pathDirname(const std::string_view entry) std::string getLibVersion() { char vinfo[512]; - sprintf(vinfo, "libhelper %s [%s %s]\nBuildType: %s\nCMakeVersion: %s\nCompilerVersion: %s\nBuildFlags: %s\n", BUILD_VERSION, BUILD_DATE, BUILD_TIME, BUILD_TYPE, BUILD_CMAKE_VERSION, BUILD_COMPILER_VERSION, BUILD_FLAGS); + sprintf(vinfo, MKVERSION("libhelper")); return std::string(vinfo); } diff --git a/srclib/libpartition_map/include/libpartition_map/lib.hpp b/srclib/libpartition_map/include/libpartition_map/lib.hpp index 514ef49..da3b266 100755 --- a/srclib/libpartition_map/include/libpartition_map/lib.hpp +++ b/srclib/libpartition_map/include/libpartition_map/lib.hpp @@ -38,6 +38,12 @@ struct _entry { } props; }; +/** + * basic_partition_map + * ------------------- + * The main type of the library. The Builder class is designed + * to be easily manipulated and modified only on this class. + */ class basic_partition_map { private: void _resize_map(); @@ -139,16 +145,14 @@ public: /** * Secondary constructor * --------------------- - * It has two arguments: + * It has one arguments: * - Directory path to search */ basic_partition_map_builder(const std::string_view path); /** * getAll() - * ------ - * WARNING: Learn about std::optional before using this function. - * + * -------- * Returns the current list content in Map_t type. * If no list is created, returns std::nullopt. */ @@ -304,10 +308,17 @@ public: /** * ! operator * ---------- - * Returns true if the object creation failed (i.e., there's a problem), - * and false if the object is correctly created. + * Returns true if the object creation failed (i.e., there's a problem), + * and false if the object is correctly created. */ - bool operator!() const; + bool operator!() const; + + /** + * () operator + * ----------- + * Build map with input path. Implementation of readDirectory(). + */ + bool operator()(const std::string_view path); }; using Error = Helper::Error; diff --git a/srclib/libpartition_map/src/PartitionMap.cpp b/srclib/libpartition_map/src/PartitionMap.cpp index 703f8c0..7f81970 100755 --- a/srclib/libpartition_map/src/PartitionMap.cpp +++ b/srclib/libpartition_map/src/PartitionMap.cpp @@ -211,10 +211,16 @@ bool basic_partition_map_builder::operator!() const return this->_any_generating_error; } +bool basic_partition_map_builder::operator()(const std::string_view path) +{ + LOGN(MAP, INFO) << "calling readDirectory() for building map with " << path << std::endl; + return readDirectory(path); +} + std::string getLibVersion() { char vinfo[512]; - sprintf(vinfo, "libpartition_map %s [%s %s]\nBuildType: %s\nCMakeVersion: %s\nCompilerVersion: %s\nBuildFlags: %s\n", BUILD_VERSION, BUILD_DATE, BUILD_TIME, BUILD_TYPE, BUILD_CMAKE_VERSION, BUILD_COMPILER_VERSION, BUILD_FLAGS); + sprintf(vinfo, MKVERSION("libpartition_map")); return std::string(vinfo); }