Make the internal disk data structures all const, to allow us to pass them to

the GUI UI thread safely.
This commit is contained in:
David Given
2022-02-24 22:46:10 +01:00
parent 4a0fc3d566
commit eade2e279e
22 changed files with 331 additions and 276 deletions

View File

@@ -6,12 +6,18 @@ std::string Sector::statusToString(Status status)
{
switch (status)
{
case Status::OK: return "OK";
case Status::BAD_CHECKSUM: return "bad checksum";
case Status::MISSING: return "sector not found";
case Status::DATA_MISSING: return "present but no data found";
case Status::CONFLICT: return "conflicting data";
default: return fmt::format("unknown error {}", status);
case Status::OK:
return "OK";
case Status::BAD_CHECKSUM:
return "bad checksum";
case Status::MISSING:
return "sector not found";
case Status::DATA_MISSING:
return "present but no data found";
case Status::CONFLICT:
return "conflicting data";
default:
return fmt::format("unknown error {}", status);
}
}
@@ -19,42 +25,48 @@ std::string Sector::statusToChar(Status status)
{
switch (status)
{
case Status::OK: return "";
case Status::MISSING: return "?";
case Status::BAD_CHECKSUM: return "!";
case Status::DATA_MISSING: return "!";
case Status::CONFLICT: return "*";
default: return "?";
case Status::OK:
return "";
case Status::MISSING:
return "?";
case Status::BAD_CHECKSUM:
return "!";
case Status::DATA_MISSING:
return "!";
case Status::CONFLICT:
return "*";
default:
return "?";
}
}
Sector::Status Sector::stringToStatus(const std::string& value)
{
if (value == "OK")
return Status::OK;
if (value == "bad checksum")
return Status::BAD_CHECKSUM;
if ((value == "sector not found") || (value == "MISSING"))
return Status::MISSING;
if (value == "present but no data found")
return Status::DATA_MISSING;
if (value == "conflicting data")
return Status::CONFLICT;
return Status::INTERNAL_ERROR;
if (value == "OK")
return Status::OK;
if (value == "bad checksum")
return Status::BAD_CHECKSUM;
if ((value == "sector not found") || (value == "MISSING"))
return Status::MISSING;
if (value == "present but no data found")
return Status::DATA_MISSING;
if (value == "conflicting data")
return Status::CONFLICT;
return Status::INTERNAL_ERROR;
}
bool sectorPointerSortPredicate(std::shared_ptr<Sector>& lhs, std::shared_ptr<Sector>& rhs)
bool sectorPointerSortPredicate(
std::shared_ptr<const Sector>& lhs, std::shared_ptr<const Sector>& rhs)
{
return *lhs < *rhs;
return *lhs < *rhs;
}
bool sectorPointerEqualsPredicate(std::shared_ptr<Sector>& lhs, std::shared_ptr<Sector>& rhs)
bool sectorPointerEqualsPredicate(
std::shared_ptr<const Sector>& lhs, std::shared_ptr<const Sector>& rhs)
{
if (!lhs && !rhs)
return true;
if (!lhs || !rhs)
return false;
return *lhs == *rhs;
if (!lhs && !rhs)
return true;
if (!lhs || !rhs)
return false;
return *lhs == *rhs;
}