1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. 2 // This source code is licensed under both the GPLv2 (found in the 3 // COPYING file in the root directory) and Apache 2.0 License 4 // (found in the LICENSE.Apache file in the root directory). 5 6 #pragma once 7 8 #include "rocksdb/cache.h" 9 #include "rocksdb/rocksdb_namespace.h" 10 11 namespace ROCKSDB_NAMESPACE { 12 13 template <typename T> 14 class SimpleDeleter : public Cache::Deleter { 15 public: GetInstance()16 static SimpleDeleter* GetInstance() { 17 static auto deleter = new SimpleDeleter; 18 return deleter; 19 } 20 operator()21 void operator()(const Slice& /* key */, void* value) override { 22 T* const t = static_cast<T*>(value); 23 delete t; 24 } 25 26 private: 27 SimpleDeleter() = default; 28 }; 29 30 template <typename T> 31 class SimpleDeleter<T[]> : public Cache::Deleter { 32 public: GetInstance()33 static SimpleDeleter* GetInstance() { 34 static auto deleter = new SimpleDeleter; 35 return deleter; 36 } 37 operator()38 void operator()(const Slice& /* key */, void* value) override { 39 T* const t = static_cast<T*>(value); 40 delete[] t; 41 } 42 43 private: 44 SimpleDeleter() = default; 45 }; 46 47 } // namespace ROCKSDB_NAMESPACE 48