pmt: ready for release

- Fix memory leaks
 - Writed functions and apply
 - Test pmt and verify stability
This commit is contained in:
2025-08-06 21:58:05 +03:00
parent 670f2bfad5
commit 6294482b39
29 changed files with 1033 additions and 502 deletions

View File

@@ -39,19 +39,17 @@ struct _entry {
};
/**
* 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();
int _index_of(const std::string_view name) const;
[[nodiscard]] int _index_of(std::string_view name) const;
public:
_entry* _data;
size_t _count, _capacity;
size_t _count{}, _capacity{};
struct _returnable_entry {
uint64_t size;
@@ -60,20 +58,20 @@ public:
using BasicInf = _returnable_entry;
basic_partition_map(const std::string name, uint64_t size, bool logical);
basic_partition_map(const std::string& name, uint64_t size, bool logical);
basic_partition_map(const basic_partition_map& other);
basic_partition_map();
~basic_partition_map();
bool insert(const std::string name, uint64_t size, bool logical);
bool insert(const std::string& name, uint64_t size, bool logical);
void merge(const basic_partition_map& map);
uint64_t get_size(const std::string_view name) const;
bool is_logical(const std::string_view name) const;
_returnable_entry get_all(const std::string_view name) const;
bool find(const std::string_view name) const;
std::string find_(const std::string name) const;
size_t size() const;
bool empty() const;
[[nodiscard]] uint64_t get_size(std::string_view name) const;
[[nodiscard]] bool is_logical(std::string_view name) const;
[[nodiscard]] _returnable_entry get_all(std::string_view name) const;
[[nodiscard]] bool find(std::string_view name) const;
[[nodiscard]] std::string find_(const std::string& name) const;
[[nodiscard]] size_t size() const;
[[nodiscard]] bool empty() const;
void clear();
basic_partition_map& operator=(const basic_partition_map& map);
@@ -84,10 +82,10 @@ public:
public:
_entry* ptr;
iterator(_entry* p);
explicit iterator(_entry* p);
auto operator*() -> std::pair<std::string&, decltype(_entry::props)&>;
_entry* operator->();
auto operator*() const -> std::pair<std::string&, decltype(_entry::props)&>;
_entry* operator->() const;
iterator& operator++();
iterator operator++(int);
bool operator!=(const iterator& other) const;
@@ -98,7 +96,7 @@ public:
public:
const _entry* ptr;
constant_iterator(const _entry* p);
explicit constant_iterator(const _entry* p);
auto operator*() const -> std::pair<const std::string&, const decltype(_entry::props)&>;
const _entry* operator->() const;
@@ -109,13 +107,11 @@ public:
};
/* for-each support */
iterator begin();
iterator end();
[[nodiscard]] iterator begin() const;
[[nodiscard]] iterator end() const;
constant_iterator begin() const;
constant_iterator cbegin() const;
constant_iterator end() const;
constant_iterator cend() const;
[[nodiscard]] constant_iterator cbegin() const;
[[nodiscard]] constant_iterator cend() const;
};
using Map_t = basic_partition_map;
@@ -126,16 +122,14 @@ private:
std::string _workdir;
bool _any_generating_error, _map_builded;
bool _is_real_block_dir(const std::string_view path) const;
[[nodiscard]] static bool _is_real_block_dir(std::string_view path);
Map_t _build_map(std::string_view path, bool logical = false);
void _insert_logicals(Map_t&& logicals);
void _map_build_check() const;
uint64_t _get_size(const std::string path);
[[nodiscard]] uint64_t _get_size(const std::string& path);
public:
/**
* Default constructor
* -------------------
* By default, it searches the directories in the
* defaultEntryList in PartitionMap.cpp in order and
* uses the directory it finds.
@@ -143,189 +137,145 @@ public:
basic_partition_map_builder();
/**
* Secondary constructor
* ---------------------
* It has one arguments:
* - Directory path to search
* A constructor with input. Need search path
*/
basic_partition_map_builder(const std::string_view path);
explicit basic_partition_map_builder(std::string_view path);
/**
* getAll()
* --------
* Returns the current list content in Map_t type.
* If no list is created, returns std::nullopt.
*/
Map_t getAll() const;
[[nodiscard]] Map_t getAll() const;
/**
* get(name)
* ---------
* WARNING: Learn about std::optional before using this function.
*
* Returns information of a specific partition in
* Map_temp_t type. If the partition is not in the
* currently created list, returns std::nullopt.
*/
std::optional<std::pair<uint64_t, bool>> get(const std::string_view name) const;
[[nodiscard]] std::optional<std::pair<uint64_t, bool>> get(std::string_view name) const;
/**
* getLogicalPartitionList()
* -------------------------
* WARNING: Learn about std::optional before using this function.
*
* If there is a logical partition(s) in the created
* list, it returns a list of type std::list (containing
* data of type std::string). If there is no logical
* partition in the created list, it returns std::nullopt.
*/
std::optional<std::list<std::string>> getLogicalPartitionList() const;
[[nodiscard]] std::optional<std::list<std::string>> getLogicalPartitionList() const;
/**
* getPhysicalPartitionList()
* --------------------------
* WARNING: Learn about std::optional before using this function.
*
* The physical partitions in the created list are
* returned as std::list type. If there is no content
* due to any problem, returns std::nullopt.
*/
std::optional<std::list<std::string>> getPhysicalPartitionList() const;
[[nodiscard]] std::optional<std::list<std::string>> getPhysicalPartitionList() const;
/**
* The partitions in the created list are returned as std::list
* If there is no content due to any problem, returns std::nullopt
*/
[[nodiscard]] std::optional<std::list<std::string>> getPartitionList() const;
/**
* getRealLinkPathOf(name)
* -----------------------
* WARNING: Learn about std::optional before using this function.
*
* Returns the full link path of the entered partition
* name in the current search directory as std::string.
* If the partition is not in the list, an empty
* std::string is returned.
*/
std::string getRealLinkPathOf(const std::string_view name) const;
[[nodiscard]] std::string getRealLinkPathOf(std::string_view name) const;
/**
* getRealPathOf(name)
* -------------------
* WARNING: Learn about std::optional before using this function.
*
* Returns the actual path of the partition as
* std::string. Like /dev/block/sda5
*/
std::string getRealPathOf(const std::string_view name) const;
[[nodiscard]] std::string getRealPathOf(std::string_view name) const;
/**
* getCurrentWorkDir()
* -------------------
* WARNING: Learn about std::optional before using this function.
*
* If it exists, the path to the search string is
* returned as std::string. If it does not exist,
* an empty std::string is returned.
*/
std::string getCurrentWorkDir() const;
[[nodiscard]] std::string getCurrentWorkDir() const;
/**
* hasPartition(name)
* ------------------
* Returns whether the entered partition name is in the
* created partition list as a bool.
*/
bool hasPartition(const std::string_view name) const;
[[nodiscard]] bool hasPartition(std::string_view name) const;
/**
* isLogical(name)
* ---------------
* Returns the bool type status of whether the
* entered section name is marked as logical in the
* created list. Alternatively, the current section
* information can be retrieved with the Get() function
* entered partition name is marked as logical in the
* created list. Alternatively, the current partition
* information can be retrieved with the get() function
* and checked for logicality.
*/
bool isLogical(const std::string_view name) const;
[[nodiscard]] bool isLogical(std::string_view name) const;
/**
* clear()
* -------
* The created list and the current search index name are cleared.
*/
void clear();
/**
* readDirectory(path)
* -------------------
* The entered path is defined as the new search
* directory and the search is performed in the entered
* directory. If everything goes well, true is returned.
*/
bool readDirectory(const std::string_view path);
bool readDirectory(std::string_view path);
/**
* Reads default /dev entries and builds map.
*/
bool readDefaultDirectories();
/**
* empty()
* -------
* Whether the current list is empty or not is returned
* as bool type. If there is content in the list, true
* is returned, otherwise false is returned.
*/
bool empty() const;
[[nodiscard]] bool empty() const;
/**
* sizeOf(name)
* ------------
* WARNING: Learn about std::optional before using this function.
*
* If it exists, the size of the partition with the
* entered name is returned as uint64_t type.
* If it does not exist, 0 is returned.
*/
uint64_t sizeOf(const std::string_view name) const;
[[nodiscard]] uint64_t sizeOf(std::string_view name) const;
/**
* == operator
* -----------
* If the content lists of the two created objects are
* the same (checked only according to the partition
* names), true is returned, otherwise false is returned
*/
friend bool operator==(basic_partition_map_builder& lhs, basic_partition_map_builder& rhs);
friend bool operator==(const basic_partition_map_builder& lhs, const basic_partition_map_builder& rhs);
/**
* != operator
* -----------
* The opposite logic of the == operator.
*/
friend bool operator!=(basic_partition_map_builder& lhs, basic_partition_map_builder& rhs);
friend bool operator!=(const basic_partition_map_builder& lhs, const basic_partition_map_builder& rhs);
/**
* Boolean operator
* ----------------
* You can check whether the object was created
* successfully. If the problem did not occur, true is
* returned, if it did, false is returned.
*/
operator bool() const;
explicit operator bool() const;
/**
* ! operator
* ----------
* Returns true if the object creation failed (i.e., there's a problem),
* and false if the object is correctly created.
*/
bool operator!() const;
/**
* () operator
* -----------
* Build map with input path. Implementation of readDirectory().
*/
bool operator()(const std::string_view path);
bool operator()(std::string_view path);
};
using Error = Helper::Error;
/**
* getLibVersion()
* ---------------
* To get the version information of libpartition_map
* library. It is returned as std::string type.
*/