diff options
author | TheCharlatan <seb.kung@gmail.com> | 2023-07-29 12:03:35 +0200 |
---|---|---|
committer | TheCharlatan <seb.kung@gmail.com> | 2023-08-05 10:42:53 +0200 |
commit | e4af2408f2ac59788567b6fc8cb3a68fc43da9fe (patch) | |
tree | cde480915e567295a700b55c191febc7ea4bdc42 /src/dbwrapper.h | |
parent | ef941ff1281e76308c3e746e592375bec023e9e4 (diff) |
refactor: Pimpl leveldb::Iterator for CDBIterator
Hide the leveldb::Iterator member variable with a pimpl in order not to
expose it directly in the header.
Also, move CDBWrapper::NewIterator to the dbwrapper implementation to
use the pimpl for CDBIterator initialziation.
The context of this commit is an effort to decouple the dbwrapper header
file from leveldb includes. To this end, the includes are moved to the
dbwrapper implementation file. This is done as part of the kernel
project to reduce the number of required includes for users of the
kernel.
Diffstat (limited to 'src/dbwrapper.h')
-rw-r--r-- | src/dbwrapper.h | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/dbwrapper.h b/src/dbwrapper.h index 2e6cc4d81e..9bcb79c169 100644 --- a/src/dbwrapper.h +++ b/src/dbwrapper.h @@ -26,7 +26,6 @@ #include <vector> namespace leveldb { class Env; -class Iterator; } static const size_t DBWRAPPER_PREALLOC_KEY_SIZE = 64; @@ -136,9 +135,12 @@ public: class CDBIterator { +public: + struct IteratorImpl; + private: const CDBWrapper &parent; - leveldb::Iterator *piter; + const std::unique_ptr<IteratorImpl> m_impl_iter; void SeekImpl(Span<const std::byte> ssKey); Span<const std::byte> GetKeyImpl() const; @@ -150,8 +152,7 @@ public: * @param[in] _parent Parent CDBWrapper instance. * @param[in] _piter The original leveldb iterator. */ - CDBIterator(const CDBWrapper &_parent, leveldb::Iterator *_piter) : - parent(_parent), piter(_piter) { }; + CDBIterator(const CDBWrapper& _parent, std::unique_ptr<IteratorImpl> _piter); ~CDBIterator(); bool Valid() const; @@ -315,10 +316,7 @@ public: // Get an estimate of LevelDB memory usage (in bytes). size_t DynamicMemoryUsage() const; - CDBIterator *NewIterator() - { - return new CDBIterator(*this, pdb->NewIterator(iteroptions)); - } + CDBIterator* NewIterator(); /** * Return true if the database managed by this class contains no entries. |