Storage Engine API
snapshot.h
Go to the documentation of this file.
1 // snapshot.h
2 
31 #pragma once
32 
33 #include "mongo/util/assert_util.h"
34 
35 namespace mongo {
36 
37 class SnapshotId {
38  static const uint64_t kNullId = 0;
39 
40 public:
41  SnapshotId() : _id(kNullId) {}
42 
43  // 0 is NULL
44  explicit SnapshotId(uint64_t id) : _id(id) {
45  invariant(id != kNullId);
46  }
47 
48  bool isNull() const {
49  return _id == kNullId;
50  }
51 
52  bool operator==(const SnapshotId& other) const {
53  return _id == other._id;
54  }
55 
56  bool operator!=(const SnapshotId& other) const {
57  return _id != other._id;
58  }
59 
60  std::string toString() const {
61  return std::to_string(_id);
62  }
63 
64 private:
65  uint64_t _id;
66 };
67 
68 template <typename T>
69 class Snapshotted {
70 public:
71  Snapshotted() : _id(), _value() {}
72 
73  Snapshotted(SnapshotId id, const T& value) : _id(id), _value(value) {}
74 
75  void reset() {
76  *this = Snapshotted();
77  }
78 
79  void setValue(const T& t) {
80  _value = t;
81  }
82 
84  return _id;
85  }
86  const T& value() const {
87  return _value;
88  }
89  T& value() {
90  return _value;
91  }
92 
93 private:
95  T _value;
96 };
97 }
SnapshotId _id
Definition: snapshot.h:94
void reset()
Definition: snapshot.h:75
Definition: snapshot.h:69
SnapshotId()
Definition: snapshot.h:41
Copyright (C) 2014 MongoDB Inc.
Definition: bson_collection_catalog_entry.cpp:38
Snapshotted(SnapshotId id, const T &value)
Definition: snapshot.h:73
static const uint64_t kNullId
Definition: snapshot.h:38
SnapshotId snapshotId() const
Definition: snapshot.h:83
const T & value() const
Definition: snapshot.h:86
T _value
Definition: snapshot.h:95
uint64_t _id
Definition: snapshot.h:65
bool isNull() const
Definition: snapshot.h:48
T & value()
Definition: snapshot.h:89
SnapshotId(uint64_t id)
Definition: snapshot.h:44
Snapshotted()
Definition: snapshot.h:71
bool operator!=(const SnapshotId &other) const
Definition: snapshot.h:56
std::string toString() const
Definition: snapshot.h:60
Definition: snapshot.h:37
void setValue(const T &t)
Definition: snapshot.h:79
bool operator==(const SnapshotId &other) const
Definition: snapshot.h:52