小组成员:姚凯文(kevinyao0901),姜嘉琪
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.0 KiB

  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. #ifndef STORAGE_LEVELDB_DB_WRITE_BATCH_INTERNAL_H_
  5. #define STORAGE_LEVELDB_DB_WRITE_BATCH_INTERNAL_H_
  6. #include "leveldb/write_batch.h"
  7. namespace leveldb {
  8. // WriteBatchInternal provides static methods for manipulating a
  9. // WriteBatch that we don't want in the public WriteBatch interface.
  10. class WriteBatchInternal {
  11. public:
  12. // Return the number of entries in the batch.
  13. static int Count(const WriteBatch* batch);
  14. // Set the count for the number of entries in the batch.
  15. static void SetCount(WriteBatch* batch, int n);
  16. // Return the seqeunce number for the start of this batch.
  17. static SequenceNumber Sequence(const WriteBatch* batch);
  18. // Store the specified number as the seqeunce number for the start of
  19. // this batch.
  20. static void SetSequence(WriteBatch* batch, SequenceNumber seq);
  21. static Slice Contents(const WriteBatch* batch) {
  22. return Slice(batch->rep_);
  23. }
  24. static size_t ByteSize(const WriteBatch* batch) {
  25. return batch->rep_.size();
  26. }
  27. static void SetContents(WriteBatch* batch, const Slice& contents);
  28. static Status InsertInto(const WriteBatch* batch, MemTable* memtable);
  29. // Iterate over the contents of a write batch.
  30. class Iterator {
  31. public:
  32. explicit Iterator(const WriteBatch& batch);
  33. bool Done() const { return done_; }
  34. void Next();
  35. ValueType op() const { return op_; }
  36. const Slice& key() const { return key_; }
  37. const Slice& value() const { return value_; }
  38. SequenceNumber sequence_number() const { return seq_; }
  39. Status status() const { return status_; }
  40. private:
  41. void GetNextEntry();
  42. Slice input_;
  43. bool done_;
  44. ValueType op_;
  45. Slice key_;
  46. Slice value_;
  47. SequenceNumber seq_;
  48. Status status_;
  49. };
  50. };
  51. }
  52. #endif // STORAGE_LEVELDB_DB_WRITE_BATCH_INTERNAL_H_