Make classes final if they're not meant to be derived from

This commit is contained in:
Sebastian Messmer 2015-11-27 14:06:40 +01:00
parent b83be2c32d
commit 5c9cc509d7
19 changed files with 30 additions and 26 deletions

View File

@ -10,11 +10,11 @@ namespace blockstore {
namespace caching {
class CachingBlockStore;
class CachedBlock: public Block {
class CachedBlock final: public Block {
public:
//TODO Storing key twice (in parent class and in object pointed to). Once would be enough.
CachedBlock(cpputils::unique_ref<Block> baseBlock, CachingBlockStore *blockStore);
virtual ~CachedBlock();
~CachedBlock();
const void *data() const override;
void write(const void *source, uint64_t offset, uint64_t size) override;

View File

@ -9,7 +9,7 @@ namespace blockstore {
namespace caching {
//TODO Check that this blockstore allows parallel destructing of blocks (otherwise we won't encrypt blocks in parallel)
class CachingBlockStore: public BlockStore {
class CachingBlockStore final: public BlockStore {
public:
explicit CachingBlockStore(cpputils::unique_ref<BlockStore> baseBlockStore);

View File

@ -18,10 +18,10 @@ class CachingBlockStore;
// This is a block that was created in CachingBlockStore, but doesn't exist in the base block store yet.
// It only exists in the cache and it is created in the base block store when destructed.
class NewBlock: public Block {
class NewBlock final: public Block {
public:
NewBlock(const Key &key, cpputils::Data data, CachingBlockStore *blockStore);
virtual ~NewBlock();
~NewBlock();
const void *data() const override;
void write(const void *source, uint64_t offset, uint64_t size) override;

View File

@ -16,7 +16,7 @@ namespace blockstore {
namespace caching {
template<class Key, class Value, uint32_t MAX_ENTRIES>
class Cache {
class Cache final {
public:
//TODO Current MAX_LIFETIME_SEC only considers time since the element was last pushed to the Cache. Also insert a real MAX_LIFETIME_SEC that forces resync of entries that have been pushed/popped often (e.g. the root blob)
//TODO Experiment with good values
@ -25,7 +25,7 @@ public:
static constexpr double MAX_LIFETIME_SEC = PURGE_LIFETIME_SEC + PURGE_INTERVAL; // This is the oldest age an entry can reach (given purging works in an ideal world, i.e. with the ideal interval and in zero time)
Cache();
virtual ~Cache();
~Cache();
uint32_t size() const;
@ -47,6 +47,8 @@ private:
cpputils::LockPool<Key> _currentlyFlushingEntries;
QueueMap<Key, CacheEntry<Key, Value>> _cachedBlocks;
std::unique_ptr<PeriodicTask> _timeoutFlusher;
DISALLOW_COPY_AND_ASSIGN(Cache);
};
template<class Key, class Value, uint32_t MAX_ENTRIES> constexpr double Cache<Key, Value, MAX_ENTRIES>::PURGE_LIFETIME_SEC;

View File

@ -11,7 +11,7 @@ namespace blockstore {
namespace caching {
template<class Key, class Value>
class CacheEntry {
class CacheEntry final {
public:
explicit CacheEntry(Value value): _lastAccess(currentTime()), _value(std::move(value)) {
}

View File

@ -22,6 +22,8 @@ private:
//This member has to be last, so the thread is destructed first. Otherwise the thread might access elements from a
//partly destructed PeriodicTask.
cpputils::LoopThread _thread;
DISALLOW_COPY_AND_ASSIGN(PeriodicTask);
};
}

View File

@ -23,7 +23,7 @@ class QueueMap final {
public:
QueueMap(): _entries(), _sentinel(&_sentinel, &_sentinel) {
}
virtual ~QueueMap() {
~QueueMap() {
for (auto &entry : _entries) {
entry.second.release();
}

View File

@ -22,7 +22,7 @@ template<class Cipher> class EncryptedBlockStore;
//TODO Test EncryptedBlock
template<class Cipher>
class EncryptedBlock: public Block {
class EncryptedBlock final: public Block {
public:
BOOST_CONCEPT_ASSERT((cpputils::CipherConcept<Cipher>));
static boost::optional<cpputils::unique_ref<EncryptedBlock>> TryCreateNew(BlockStore *baseBlockStore, const Key &key, cpputils::Data data, const typename Cipher::EncryptionKey &encKey);
@ -30,7 +30,7 @@ public:
//TODO Storing key twice (in parent class and in object pointed to). Once would be enough.
EncryptedBlock(cpputils::unique_ref<Block> baseBlock, const typename Cipher::EncryptionKey &key, cpputils::Data plaintextWithHeader);
virtual ~EncryptedBlock();
~EncryptedBlock();
const void *data() const override;
void write(const void *source, uint64_t offset, uint64_t count) override;

View File

@ -12,7 +12,7 @@ namespace blockstore {
namespace encrypted {
template<class Cipher>
class EncryptedBlockStore: public BlockStore {
class EncryptedBlockStore final: public BlockStore {
public:
EncryptedBlockStore(cpputils::unique_ref<BlockStore> baseBlockStore, const typename Cipher::EncryptionKey &encKey);

View File

@ -9,11 +9,11 @@ namespace blockstore {
namespace inmemory {
class InMemoryBlockStore;
class InMemoryBlock: public Block {
class InMemoryBlock final: public Block {
public:
InMemoryBlock(const Key &key, cpputils::Data size);
InMemoryBlock(const InMemoryBlock &rhs);
virtual ~InMemoryBlock();
~InMemoryBlock();
const void *data() const override;
void write(const void *source, uint64_t offset, uint64_t size) override;

View File

@ -12,7 +12,7 @@ namespace blockstore {
namespace inmemory {
class InMemoryBlock;
class InMemoryBlockStore: public BlockStoreWithRandomKeys {
class InMemoryBlockStore final: public BlockStoreWithRandomKeys {
public:
InMemoryBlockStore();

View File

@ -14,10 +14,10 @@ namespace blockstore {
namespace ondisk {
class OnDiskBlockStore;
class OnDiskBlock: public Block {
class OnDiskBlock final: public Block {
public:
OnDiskBlock(const Key &key, const boost::filesystem::path &filepath, cpputils::Data data);
virtual ~OnDiskBlock();
~OnDiskBlock();
static boost::optional<cpputils::unique_ref<OnDiskBlock>> LoadFromDisk(const boost::filesystem::path &rootdir, const Key &key);
static boost::optional<cpputils::unique_ref<OnDiskBlock>> CreateOnDisk(const boost::filesystem::path &rootdir, const Key &key, cpputils::Data data);

View File

@ -10,7 +10,7 @@
namespace blockstore {
namespace ondisk {
class OnDiskBlockStore: public BlockStoreWithRandomKeys {
class OnDiskBlockStore final: public BlockStoreWithRandomKeys {
public:
explicit OnDiskBlockStore(const boost::filesystem::path &rootdir);

View File

@ -11,7 +11,7 @@ namespace blockstore {
namespace parallelaccess {
class ParallelAccessBlockStore;
class BlockRef: public Block, public parallelaccessstore::ParallelAccessStore<Block, BlockRef, Key>::ResourceRefBase {
class BlockRef final: public Block, public parallelaccessstore::ParallelAccessStore<Block, BlockRef, Key>::ResourceRefBase {
public:
//TODO Unneccessarily storing Key twice here (in parent class and in _baseBlock).
explicit BlockRef(Block *baseBlock): Block(baseBlock->key()), _baseBlock(baseBlock) {}

View File

@ -11,7 +11,7 @@ namespace blockstore {
namespace parallelaccess {
//TODO Check that this blockstore allows parallel destructing of blocks (otherwise we won't encrypt blocks in parallel)
class ParallelAccessBlockStore: public BlockStore {
class ParallelAccessBlockStore final: public BlockStore {
public:
explicit ParallelAccessBlockStore(cpputils::unique_ref<BlockStore> baseBlockStore);

View File

@ -9,7 +9,7 @@
namespace blockstore {
namespace parallelaccess {
class ParallelAccessBlockStoreAdapter: public parallelaccessstore::ParallelAccessBaseStore<Block, Key> {
class ParallelAccessBlockStoreAdapter final: public parallelaccessstore::ParallelAccessBaseStore<Block, Key> {
public:
explicit ParallelAccessBlockStoreAdapter(BlockStore *baseBlockStore)
:_baseBlockStore(std::move(baseBlockStore)) {

View File

@ -11,10 +11,10 @@ namespace blockstore {
namespace testfake {
class FakeBlockStore;
class FakeBlock: public Block {
class FakeBlock final: public Block {
public:
FakeBlock(FakeBlockStore *store, const Key &key, std::shared_ptr<cpputils::Data> data, bool dirty);
virtual ~FakeBlock();
~FakeBlock();
const void *data() const override;
void write(const void *source, uint64_t offset, uint64_t size) override;

View File

@ -27,7 +27,7 @@ class FakeBlock;
* the data (instead of a direct pointer as InMemoryBlockStore does) and flushing will copy the data back to the
* background. This way, tests are more likely to fail if they use the blockstore wrongly.
*/
class FakeBlockStore: public BlockStoreWithRandomKeys {
class FakeBlockStore final: public BlockStoreWithRandomKeys {
public:
FakeBlockStore();

View File

@ -8,10 +8,10 @@
namespace blockstore {
class FileDoesntExistException: public std::runtime_error {
class FileDoesntExistException final: public std::runtime_error {
public:
explicit FileDoesntExistException(const boost::filesystem::path &filepath);
virtual ~FileDoesntExistException();
~FileDoesntExistException();
};
}