From 09bc4f27e9ebbdc04ae85b33ef26d30e2fd63329 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Mon, 25 Feb 2019 10:18:49 +0100 Subject: [PATCH] [ion] Add Macro to log the storage content --- ion/Makefile | 4 ++++ ion/include/ion/storage.h | 8 ++++++++ ion/src/shared/storage.cpp | 21 +++++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/ion/Makefile b/ion/Makefile index 28aeb0bc2..b2ea8e4ba 100644 --- a/ion/Makefile +++ b/ion/Makefile @@ -35,3 +35,7 @@ tests += $(addprefix ion/test/,\ storage.cpp\ utf8_decoder.cpp\ ) + +ifdef ION_STORAGE_LOG +SFLAGS += -DION_STORAGE_LOG=1 +endif \ No newline at end of file diff --git a/ion/include/ion/storage.h b/ion/include/ion/storage.h index ea59a185f..26867768c 100644 --- a/ion/include/ion/storage.h +++ b/ion/include/ion/storage.h @@ -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(); diff --git a/ion/src/shared/storage.cpp b/ion/src/shared/storage.cpp index e9ca40a02..7e007851f 100644 --- a/ion/src/shared/storage.cpp +++ b/ion/src/shared/storage.cpp @@ -2,6 +2,9 @@ #include #include #include +#if ION_STORAGE_LOG +#include +#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); }