Feathercoin  0.5.0
P2P Digital Currency
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
snapshot.h
Go to the documentation of this file.
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 #ifndef STORAGE_LEVELDB_DB_SNAPSHOT_H_
6 #define STORAGE_LEVELDB_DB_SNAPSHOT_H_
7 
8 #include "leveldb/db.h"
9 
10 namespace leveldb {
11 
12 class SnapshotList;
13 
14 // Snapshots are kept in a doubly-linked list in the DB.
15 // Each SnapshotImpl corresponds to a particular sequence number.
16 class SnapshotImpl : public Snapshot {
17  public:
18  SequenceNumber number_; // const after creation
19 
20  private:
21  friend class SnapshotList;
22 
23  // SnapshotImpl is kept in a doubly-linked circular list
26 
27  SnapshotList* list_; // just for sanity checks
28 };
29 
30 class SnapshotList {
31  public:
33  list_.prev_ = &list_;
34  list_.next_ = &list_;
35  }
36 
37  bool empty() const { return list_.next_ == &list_; }
38  SnapshotImpl* oldest() const { assert(!empty()); return list_.next_; }
39  SnapshotImpl* newest() const { assert(!empty()); return list_.prev_; }
40 
42  SnapshotImpl* s = new SnapshotImpl;
43  s->number_ = seq;
44  s->list_ = this;
45  s->next_ = &list_;
46  s->prev_ = list_.prev_;
47  s->prev_->next_ = s;
48  s->next_->prev_ = s;
49  return s;
50  }
51 
52  void Delete(const SnapshotImpl* s) {
53  assert(s->list_ == this);
54  s->prev_->next_ = s->next_;
55  s->next_->prev_ = s->prev_;
56  delete s;
57  }
58 
59  private:
60  // Dummy head of doubly-linked list of snapshots
62 };
63 
64 } // namespace leveldb
65 
66 #endif // STORAGE_LEVELDB_DB_SNAPSHOT_H_
SnapshotImpl * prev_
Definition: snapshot.h:24
SnapshotImpl * newest() const
Definition: snapshot.h:39
bool empty() const
Definition: snapshot.h:37
SnapshotImpl list_
Definition: snapshot.h:61
SnapshotList * list_
Definition: snapshot.h:27
uint64_t SequenceNumber
Definition: dbformat.h:63
const SnapshotImpl * New(SequenceNumber seq)
Definition: snapshot.h:41
SnapshotImpl * next_
Definition: snapshot.h:25
void Delete(const SnapshotImpl *s)
Definition: snapshot.h:52
SequenceNumber number_
Definition: snapshot.h:18
SnapshotImpl * oldest() const
Definition: snapshot.h:38