pmt: Improve libpartition_map types and some functions.
- Add new operators to Map_t. - Add new flags to info function. - Move some local pmt function(s) to libhelper. - Etc...
This commit is contained in:
@@ -324,6 +324,11 @@ std::string pathDirname(std::string_view entry);
|
||||
*/
|
||||
uint64_t getRandomOffset(uint64_t size, uint64_t bufferSize);
|
||||
|
||||
/**
|
||||
* Convert input size to input multiple
|
||||
*/
|
||||
std::string convertTo(uint64_t size, const std::string &multiple);
|
||||
|
||||
// -------------------------------
|
||||
// Android - not throws Helper::Error
|
||||
// -------------------------------
|
||||
|
||||
@@ -241,5 +241,12 @@ uint64_t getRandomOffset(const uint64_t size, const uint64_t bufferSize) {
|
||||
return rand() % maxOffset;
|
||||
}
|
||||
|
||||
std::string convertTo(const uint64_t size, const std::string &multiple) {
|
||||
if (multiple == "KB") return std::to_string(TO_KB(size));
|
||||
if (multiple == "MB") return std::to_string(TO_MB(size));
|
||||
if (multiple == "GB") return std::to_string(TO_GB(size));
|
||||
return std::to_string(size);
|
||||
}
|
||||
|
||||
std::string getLibVersion() { MKVERSION("libhelper"); }
|
||||
} // namespace Helper
|
||||
|
||||
@@ -83,6 +83,8 @@ public:
|
||||
|
||||
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;
|
||||
|
||||
@@ -370,7 +370,7 @@ bool basic_partition_map_builder::doForPartitionList(
|
||||
for (const auto &partition : partitions) {
|
||||
if (!hasPartition(partition))
|
||||
throw Error("Couldn't find partition: %s", partition.data());
|
||||
if (!func(partition, {sizeOf(partition), isLogical(partition)})) {
|
||||
if (!func(partition, _current_map[partition])) {
|
||||
err = true;
|
||||
LOGN(MAP, ERROR) << "Failed progress for " << partition << " partition."
|
||||
<< std::endl;
|
||||
|
||||
@@ -185,8 +185,7 @@ std::string basic_partition_map::find_(const std::string &name) const {
|
||||
size_t basic_partition_map::size() const { return _count; }
|
||||
|
||||
bool basic_partition_map::empty() const {
|
||||
if (_count > 0) return false;
|
||||
return true;
|
||||
return _count > 0;
|
||||
}
|
||||
|
||||
void basic_partition_map::clear() {
|
||||
@@ -229,6 +228,14 @@ bool basic_partition_map::operator!=(const basic_partition_map &other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
basic_partition_map::operator bool() const{
|
||||
return _count > 0;
|
||||
}
|
||||
|
||||
bool basic_partition_map::operator!() const{
|
||||
return _count == 0;
|
||||
}
|
||||
|
||||
Info basic_partition_map::operator[](const int index) const {
|
||||
if (_count == 0 || index >= _count) return {};
|
||||
return _data[index];
|
||||
|
||||
Reference in New Issue
Block a user