[ion] Add Macro to log the storage content

This commit is contained in:
Émilie Feral
2019-02-25 10:18:49 +01:00
parent 2e6e7f93f7
commit 09bc4f27e9
3 changed files with 33 additions and 0 deletions

View File

@@ -35,3 +35,7 @@ tests += $(addprefix ion/test/,\
storage.cpp\
utf8_decoder.cpp\
)
ifdef ION_STORAGE_LOG
SFLAGS += -DION_STORAGE_LOG=1
endif

View File

@@ -48,6 +48,9 @@ public:
bool operator!=(const Record & other) const {
return !(*this == other);
}
#if ION_STORAGE_LOG
void log();
#endif
uint32_t checksum();
bool isNull() const {
return m_fullNameCRC32 == 0;
@@ -76,6 +79,11 @@ public:
};
Storage();
#if ION_STORAGE_LOG
void log();
#endif
size_t availableSize();
uint32_t checksum();

View File

@@ -2,6 +2,9 @@
#include <string.h>
#include <assert.h>
#include <new>
#if ION_STORAGE_LOG
#include<iostream>
#endif
namespace Ion {
@@ -49,6 +52,15 @@ Storage::Record::Record(const char * baseName, const char * extension) {
new (this) Record(baseName, strlen(baseName), extension, strlen(extension));
}
#if ION_STORAGE_LOG
void Storage::Record::log() {
std::cout << "Name: " << fullName() << std::endl;
std::cout << " Value (" << value().size << "): " << (char *)value().buffer << "\n\n" << std::endl;
}
#endif
uint32_t Storage::Record::checksum() {
uint32_t crc32Results[2];
crc32Results[0] = m_fullNameCRC32;
@@ -82,6 +94,15 @@ Storage::Storage() :
overrideSizeAtPosition(m_buffer, 0);
}
#if ION_STORAGE_LOG
void Storage::log() {
for (char * p : *this) {
const char * currentName = fullNameOfRecordStarting(p);
Record(currentName).log();
}
}
#endif
size_t Storage::availableSize() {
return k_storageSize-(endBuffer()-m_buffer)-sizeof(record_size_t);
}