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.
5 #include "leveldb/iterator.h"
10 cleanup_.function = NULL;
14 Iterator::~Iterator() {
15 if (cleanup_.function != NULL) {
16 (*cleanup_.function)(cleanup_.arg1, cleanup_.arg2);
17 for (Cleanup* c = cleanup_.next; c != NULL; ) {
18 (*c->function)(c->arg1, c->arg2);
19 Cleanup* next = c->next;
26 void Iterator::RegisterCleanup(CleanupFunction func, void* arg1, void* arg2) {
29 if (cleanup_.function == NULL) {
33 c->next = cleanup_.next;
42 class EmptyIterator : public Iterator {
44 EmptyIterator(const Status& s) : status_(s) { }
45 virtual bool Valid() const { return false; }
46 virtual void Seek(const Slice& target) { }
47 virtual void SeekToFirst() { }
48 virtual void SeekToLast() { }
49 virtual void Next() { assert(false); }
50 virtual void Prev() { assert(false); }
51 Slice key() const { assert(false); return Slice(); }
52 Slice value() const { assert(false); return Slice(); }
53 virtual Status status() const { return status_; }
59 Iterator* NewEmptyIterator() {
60 return new EmptyIterator(Status::OK());
63 Iterator* NewErrorIterator(const Status& status) {
64 return new EmptyIterator(status);
67 } // namespace leveldb