/root/bitcoin/src/leveldb/table/iterator.cc
| Line | Count | Source | 
| 1 |  | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. | 
| 2 |  | // Use of this source code is governed by a BSD-style license that can be | 
| 3 |  | // found in the LICENSE file. See the AUTHORS file for names of contributors. | 
| 4 |  |  | 
| 5 |  | #include "leveldb/iterator.h" | 
| 6 |  |  | 
| 7 |  | namespace leveldb { | 
| 8 |  |  | 
| 9 | 0 | Iterator::Iterator() { | 
| 10 | 0 |   cleanup_head_.function = nullptr; | 
| 11 | 0 |   cleanup_head_.next = nullptr; | 
| 12 | 0 | } | 
| 13 |  |  | 
| 14 | 0 | Iterator::~Iterator() { | 
| 15 | 0 |   if (!cleanup_head_.IsEmpty()) { | 
| 16 | 0 |     cleanup_head_.Run(); | 
| 17 | 0 |     for (CleanupNode* node = cleanup_head_.next; node != nullptr;) { | 
| 18 | 0 |       node->Run(); | 
| 19 | 0 |       CleanupNode* next_node = node->next; | 
| 20 | 0 |       delete node; | 
| 21 | 0 |       node = next_node; | 
| 22 | 0 |     } | 
| 23 | 0 |   } | 
| 24 | 0 | } | 
| 25 |  |  | 
| 26 | 0 | void Iterator::RegisterCleanup(CleanupFunction func, void* arg1, void* arg2) { | 
| 27 | 0 |   assert(func != nullptr); | 
| 28 | 0 |   CleanupNode* node; | 
| 29 | 0 |   if (cleanup_head_.IsEmpty()) { | 
| 30 | 0 |     node = &cleanup_head_; | 
| 31 | 0 |   } else { | 
| 32 | 0 |     node = new CleanupNode(); | 
| 33 | 0 |     node->next = cleanup_head_.next; | 
| 34 | 0 |     cleanup_head_.next = node; | 
| 35 | 0 |   } | 
| 36 | 0 |   node->function = func; | 
| 37 | 0 |   node->arg1 = arg1; | 
| 38 | 0 |   node->arg2 = arg2; | 
| 39 | 0 | } | 
| 40 |  |  | 
| 41 |  | namespace { | 
| 42 |  |  | 
| 43 |  | class EmptyIterator : public Iterator { | 
| 44 |  |  public: | 
| 45 | 0 |   EmptyIterator(const Status& s) : status_(s) {} | 
| 46 | 0 |   ~EmptyIterator() override = default; | 
| 47 |  |  | 
| 48 | 0 |   bool Valid() const override { return false; } | 
| 49 | 0 |   void Seek(const Slice& target) override {} | 
| 50 | 0 |   void SeekToFirst() override {} | 
| 51 | 0 |   void SeekToLast() override {} | 
| 52 | 0 |   void Next() override { assert(false); } | 
| 53 | 0 |   void Prev() override { assert(false); } | 
| 54 | 0 |   Slice key() const override { | 
| 55 | 0 |     assert(false); | 
| 56 | 0 |     return Slice(); | 
| 57 | 0 |   } | 
| 58 | 0 |   Slice value() const override { | 
| 59 | 0 |     assert(false); | 
| 60 | 0 |     return Slice(); | 
| 61 | 0 |   } | 
| 62 | 0 |   Status status() const override { return status_; } | 
| 63 |  |  | 
| 64 |  |  private: | 
| 65 |  |   Status status_; | 
| 66 |  | }; | 
| 67 |  |  | 
| 68 |  | }  // anonymous namespace | 
| 69 |  |  | 
| 70 | 0 | Iterator* NewEmptyIterator() { return new EmptyIterator(Status::OK()); } | 
| 71 |  |  | 
| 72 | 0 | Iterator* NewErrorIterator(const Status& status) { | 
| 73 | 0 |   return new EmptyIterator(status); | 
| 74 | 0 | } | 
| 75 |  |  | 
| 76 |  | }  // namespace leveldb |