[ion] Method to destroy all records with given extension in Storage

This commit is contained in:
Léa Saviot
2018-10-02 11:51:53 +02:00
committed by Émilie Feral
parent 5a5deedb84
commit 1830070a95
2 changed files with 16 additions and 0 deletions

View File

@@ -82,6 +82,8 @@ public:
Record recordBaseNamedWithExtension(const char * baseName, const char * extension);
Record recordBaseNamedWithExtensions(const char * baseName, const char * extension[], size_t numberOfExtensions);
// Record destruction
void destroyRecordsWithExtension(const char * extension);
private:
constexpr static uint32_t Magic = 0xEE0BDDBA;
constexpr static size_t k_maxRecordSize = (1 << sizeof(record_size_t)*8);

View File

@@ -183,6 +183,20 @@ Storage::Record Storage::recordBaseNamedWithExtensions(const char * baseName, co
return Record();
}
void Storage::destroyRecordsWithExtension(const char * extension) {
size_t extensionLength = strlen(extension);
char * currentRecordStart = (char *)m_buffer;
while (currentRecordStart != nullptr && sizeOfRecordStarting(currentRecordStart) != 0) {
const char * currentFullName = fullNameOfRecordStarting(currentRecordStart);
if (FullNameHasExtension(currentFullName, extension, extensionLength)) {
Record currentRecord(currentFullName);
currentRecord.destroy();
continue;
}
currentRecordStart = *(RecordIterator(currentRecordStart).operator++());
}
}
const char * Storage::fullNameOfRecord(const Record record) {
for (char * p : *this) {
Record currentRecord(fullNameOfRecordStarting(p));