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

@@ -17,7 +17,7 @@
#ifndef LIBPARTITION_MAP_LIB_HPP
#define LIBPARTITION_MAP_LIB_HPP
#include <cstdint> // for uint64_t
#include <cstdint> // for uint64_t
#include <exception>
#include <functional>
#include <libhelper/lib.hpp>
@@ -27,7 +27,7 @@
#include <optional>
#include <string>
#include <string_view>
#include <utility> // for std::pair
#include <utility> // for std::pair
namespace PartitionMap {
struct _entry {
@@ -52,74 +52,73 @@ using Info = _entry;
* to be easily manipulated and modified only on this class.
*/
class basic_partition_map {
private:
private:
void _resize_map();
[[nodiscard]] int _index_of(std::string_view name) const;
public:
_entry *_data;
public:
_entry* _data;
size_t _count{}, _capacity{};
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 &&other) noexcept;
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&& other) noexcept;
basic_partition_map();
~basic_partition_map();
bool insert(const std::string &name, uint64_t size, bool logical);
void merge(const basic_partition_map &map);
bool insert(const std::string& name, uint64_t size, bool logical);
void merge(const basic_partition_map& map);
void clear();
[[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]] std::string find_(const std::string& name) const;
[[nodiscard]] size_t size() const;
[[nodiscard]] bool empty() const;
basic_partition_map &operator=(const basic_partition_map &map);
basic_partition_map& operator=(const basic_partition_map& map);
bool operator==(const basic_partition_map &other) const;
bool operator!=(const basic_partition_map &other) const;
bool operator==(const basic_partition_map& other) const;
bool operator!=(const basic_partition_map& other) const;
bool operator!() const;
explicit operator bool() const;
Info operator[](int index) const;
BasicInf operator[](const std::string_view &name) const;
BasicInf operator[](const std::string_view& name) const;
explicit operator std::vector<Info>() const;
explicit operator int() const;
class iterator {
public:
_entry *ptr;
public:
_entry* ptr;
explicit iterator(_entry *p);
explicit iterator(_entry* p);
auto operator*() const
-> std::pair<std::string &, decltype(_entry::props) &>;
_entry *operator->() const;
iterator &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;
bool operator==(const iterator &other) const;
bool operator!=(const iterator& other) const;
bool operator==(const iterator& other) const;
};
class constant_iterator {
public:
const _entry *ptr;
public:
const _entry* ptr;
explicit 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;
constant_iterator &operator++();
-> std::pair<const std::string&, const decltype(_entry::props)&>;
const _entry* operator->() const;
constant_iterator& operator++();
constant_iterator operator++(int);
bool operator!=(const constant_iterator &other) const;
bool operator==(const constant_iterator &other) const;
bool operator!=(const constant_iterator& other) const;
bool operator==(const constant_iterator& other) const;
};
/* for-each support */
@@ -133,20 +132,20 @@ using Partition_t = _entry;
using Map_t = basic_partition_map;
class basic_partition_map_builder final {
private:
private:
Map_t _current_map;
std::string _workdir;
bool _any_generating_error, _map_builded;
Map_t _build_map(std::string_view path, bool logical = false);
void _insert_logicals(Map_t &&logicals);
void _insert_logicals(Map_t&& logicals);
void _map_build_check() const;
[[nodiscard]] static bool _is_real_block_dir(std::string_view path);
[[nodiscard]] uint64_t _get_size(const std::string &path);
[[nodiscard]] uint64_t _get_size(const std::string& path);
public:
public:
/**
* By default, it searches the directories in the
* defaultEntryList in PartitionMap.cpp in order and
@@ -162,7 +161,7 @@ public:
/**
* Move constructor
*/
basic_partition_map_builder(basic_partition_map_builder &&other) noexcept;
basic_partition_map_builder(basic_partition_map_builder&& other) noexcept;
/**
* Returns the current list content in Map_t type.
@@ -174,8 +173,8 @@ public:
* Map_temp_t type. If the partition is not in the
* currently created list, returns std::nullopt.
*/
[[nodiscard]] std::optional<std::pair<uint64_t, bool>>
get(std::string_view name) const;
[[nodiscard]] std::optional<std::pair<uint64_t, bool>> get(
std::string_view name) const;
/**
* If there is a logical partition(s) in the created
@@ -183,16 +182,16 @@ public:
* data of type std::string). If there is no logical
* partition in the created list, it returns std::nullopt.
*/
[[nodiscard]] std::optional<std::list<std::string>>
getLogicalPartitionList() const;
[[nodiscard]] std::optional<std::list<std::string>> getLogicalPartitionList()
const;
/**
* 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.
*/
[[nodiscard]] 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
@@ -244,17 +243,17 @@ public:
/**
* Copy partition list to vec, current vec contents are cleaned
*/
bool copyPartitionsToVector(std::vector<std::string> &vec) const;
bool copyPartitionsToVector(std::vector<std::string>& vec) const;
/**
* Copy logical partition list to vec, current vec contents are cleaned
*/
bool copyLogicalPartitionsToVector(std::vector<std::string> &vec) const;
bool copyLogicalPartitionsToVector(std::vector<std::string>& vec) const;
/**
* Copy physical partition list to vec, current vec contents are cleaned
*/
bool copyPhysicalPartitionsToVector(std::vector<std::string> &vec) const;
bool copyPhysicalPartitionsToVector(std::vector<std::string>& vec) const;
/**
* The created list and the current search index name are cleared.
@@ -265,26 +264,26 @@ public:
* Do input function (lambda) for all partitions.
*/
bool doForAllPartitions(
const std::function<bool(std::string, BasicInf)> &func) const;
const std::function<bool(std::string, BasicInf)>& func) const;
/**
* Do input function (lambda) for physical partitions.
*/
bool doForPhysicalPartitions(
const std::function<bool(std::string, BasicInf)> &func) const;
const std::function<bool(std::string, BasicInf)>& func) const;
/**
* Do input function (lambda) for logical partitions.
*/
bool doForLogicalPartitions(
const std::function<bool(std::string, BasicInf)> &func) const;
const std::function<bool(std::string, BasicInf)>& func) const;
/**
* Do input function (lambda) for input partition list.
*/
bool doForPartitionList(
const std::vector<std::string> &partitions,
const std::function<bool(std::string, BasicInf)> &func) const;
const std::vector<std::string>& partitions,
const std::function<bool(std::string, BasicInf)>& func) const;
/**
* The entered path is defined as the new search
@@ -317,14 +316,14 @@ public:
* the same (checked only according to the partition
* names), true is returned, otherwise false is returned
*/
friend bool operator==(const basic_partition_map_builder &lhs,
const basic_partition_map_builder &rhs);
friend bool operator==(const basic_partition_map_builder& lhs,
const basic_partition_map_builder& rhs);
/**
* The opposite logic of the == operator.
*/
friend bool operator!=(const basic_partition_map_builder &lhs,
const basic_partition_map_builder &rhs);
friend bool operator!=(const basic_partition_map_builder& lhs,
const basic_partition_map_builder& rhs);
/**
* You can check whether the object was created
@@ -347,12 +346,12 @@ public:
/**
* Get Map_t object reference
*/
Map_t &operator*();
Map_t& operator*();
/**
* Get constant Map_t object reference
*/
const Map_t &operator*() const;
const Map_t& operator*() const;
/**
* Get Info structure with given index
@@ -362,7 +361,7 @@ public:
/**
* Get BasicInfo structure with given index
*/
BasicInf operator[](const std::string_view &name) const;
BasicInf operator[](const std::string_view& name) const;
/**
* Get map contents as vector (PartitionManager::Info type).
@@ -402,7 +401,7 @@ constexpr uint64_t FAT16_FS = 0x3631544146;
constexpr uint64_t FAT32_FS = 0x3233544146;
constexpr uint64_t NTFS_FS = 0x5346544E;
constexpr uint64_t MSDOS_FS = 0x4d44;
} // namespace FileSystemMagic
} // namespace FileSystemMagic
namespace AndroidMagic {
constexpr uint64_t BOOT_IMAGE = 0x2144494F52444E41;
@@ -413,23 +412,23 @@ constexpr uint64_t VBMETA_IMAGE = 0x425641;
constexpr uint64_t SUPER_IMAGE = 0x7265797573;
constexpr uint64_t SPARSE_IMAGE = 0x3AFF26ED;
constexpr uint64_t ELF =
0x464C457F; // It makes more sense than between file systems
0x464C457F; // It makes more sense than between file systems
constexpr uint64_t RAW = 0x00000000;
} // namespace AndroidMagic
} // namespace AndroidMagic
extern std::map<uint64_t, std::string> FileSystemMagicMap;
extern std::map<uint64_t, std::string> AndroidMagicMap;
extern std::map<uint64_t, std::string> MagicMap;
size_t getMagicLength(uint64_t magic);
bool hasMagic(uint64_t magic, ssize_t buf, const std::string &path);
bool hasMagic(uint64_t magic, ssize_t buf, const std::string& path);
std::string formatMagic(uint64_t magic);
} // namespace Extras
} // namespace PartitionMap
} // namespace Extras
} // namespace PartitionMap
#define MAP "libpartition_map"
#define COMMON_LAMBDA_PARAMS \
(const std::string &partition, const PartitionMap::BasicInf props)
#define COMMON_LAMBDA_PARAMS \
(const std::string& partition, const PartitionMap::BasicInf props)
#endif // #ifndef LIBPARTITION_MAP_LIB_HPP
#endif // #ifndef LIBPARTITION_MAP_LIB_HPP