pmt: add [] operators to Map_t and builder

This commit is contained in:
2025-09-07 10:53:59 +03:00
parent ab35740fb6
commit 1984825dec
3 changed files with 35 additions and 0 deletions

View File

@@ -84,6 +84,9 @@ public:
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;
Info operator[](int index) const;
BasicInf operator[](const std::string_view& name) const;
operator std::vector<Info>() const; operator std::vector<Info>() const;
operator int() const; operator int() const;
@@ -350,6 +353,16 @@ public:
*/ */
const Map_t &operator*() const; const Map_t &operator*() const;
/**
* Get Info structure with given index
*/
Info operator[](int index) const;
/**
* Get BasicInfo structure with given index
*/
BasicInf operator[](const std::string_view& name) const;
/** /**
* Get map contents as vector (PartitionManager::Info type). * Get map contents as vector (PartitionManager::Info type).
*/ */

View File

@@ -416,6 +416,14 @@ const Map_t &basic_partition_map_builder::operator*() const {
return _current_map; return _current_map;
} }
Info basic_partition_map_builder::operator[](const int index) const {
return _current_map[index];
}
BasicInf basic_partition_map_builder::operator[](const std::string_view& name) const {
return _current_map[name];
}
basic_partition_map_builder::operator std::vector<Info>() const { basic_partition_map_builder::operator std::vector<Info>() const {
return _current_map; return _current_map;
} }

View File

@@ -229,6 +229,20 @@ bool basic_partition_map::operator!=(const basic_partition_map &other) const {
return !(*this == other); return !(*this == other);
} }
Info basic_partition_map::operator[](const int index) const {
if (_count == 0 || index >= _count) return {};
return _data[index];
}
BasicInf basic_partition_map::operator[](const std::string_view& name) const {
if (_count == 0) return {};
if (const int i = _index_of(name); name == _data[i].name)
return {_data[i].props.size, _data[i].props.isLogical};
return {};
}
basic_partition_map::operator std::vector<Info>() const { basic_partition_map::operator std::vector<Info>() const {
std::vector<Info> v; std::vector<Info> v;
if (_count == 0) return {}; if (_count == 0) return {};