From efe5b4d6f89e99a4dfcc5daeb6bf499ed4c1ec43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Thu, 7 May 2020 14:11:17 +0200 Subject: [PATCH] [ion/storage] Private constructor and cleaner sharedStorage() --- ion/include/ion/storage.h | 4 ++-- ion/src/shared/storage.cpp | 35 +++++++++++++++++------------------ 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/ion/include/ion/storage.h b/ion/include/ion/storage.h index 851222b53..e18607612 100644 --- a/ion/include/ion/storage.h +++ b/ion/include/ion/storage.h @@ -86,8 +86,6 @@ public: uint32_t m_fullNameCRC32; }; - Storage(); - #if ION_STORAGE_LOG void log(); #endif @@ -126,6 +124,8 @@ private: constexpr static uint32_t Magic = 0xEE0BDDBA; constexpr static size_t k_maxRecordSize = (1 << sizeof(record_size_t)*8); + Storage(); + /* Getters/Setters on recordID */ const char * fullNameOfRecord(const Record record); Record::ErrorStatus setFullNameOfRecord(const Record record, const char * fullName); diff --git a/ion/src/shared/storage.cpp b/ion/src/shared/storage.cpp index 75fd7d747..95a9fd29d 100644 --- a/ion/src/shared/storage.cpp +++ b/ion/src/shared/storage.cpp @@ -28,10 +28,7 @@ constexpr char Storage::seqExtension[]; constexpr char Storage::eqExtension[]; Storage * Storage::sharedStorage() { - static Storage * storage = nullptr; - if (storage == nullptr) { - storage = new (staticStorageArea) Storage(); - } + static Storage * storage = new (staticStorageArea) Storage(); return storage; } @@ -90,20 +87,6 @@ Storage::Record::Record(const char * basename, int basenameLength, const char * // STORAGE -Storage::Storage() : - m_magicHeader(Magic), - m_buffer(), - m_magicFooter(Magic), - m_delegate(nullptr), - m_lastRecordRetrieved(nullptr), - m_lastRecordRetrievedPointer(nullptr) -{ - assert(m_magicHeader == Magic); - assert(m_magicFooter == Magic); - // Set the size of the first record to 0 - overrideSizeAtPosition(m_buffer, 0); -} - #if ION_STORAGE_LOG void Storage::log() { for (char * p : *this) { @@ -305,6 +288,22 @@ void Storage::destroyRecordsWithExtension(const char * extension) { } } +// PRIVATE + +Storage::Storage() : + m_magicHeader(Magic), + m_buffer(), + m_magicFooter(Magic), + m_delegate(nullptr), + m_lastRecordRetrieved(nullptr), + m_lastRecordRetrievedPointer(nullptr) +{ + assert(m_magicHeader == Magic); + assert(m_magicFooter == Magic); + // Set the size of the first record to 0 + overrideSizeAtPosition(m_buffer, 0); +} + const char * Storage::fullNameOfRecord(const Record record) { char * p = pointerOfRecord(record); if (p != nullptr) {