jorlow@chromium.org | f67e15e | 2011-03-18 22:37:00 +0000 | [diff] [blame] | 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_WRITE_BATCH_INTERNAL_H_ |
| 6 | #define STORAGE_LEVELDB_DB_WRITE_BATCH_INTERNAL_H_ |
| 7 | |
jorlow@chromium.org | 4671a69 | 2011-03-30 18:35:40 +0000 | [diff] [blame^] | 8 | #include "leveldb/write_batch.h" |
jorlow@chromium.org | f67e15e | 2011-03-18 22:37:00 +0000 | [diff] [blame] | 9 | |
| 10 | namespace leveldb { |
| 11 | |
| 12 | // WriteBatchInternal provides static methods for manipulating a |
| 13 | // WriteBatch that we don't want in the public WriteBatch interface. |
| 14 | class WriteBatchInternal { |
| 15 | public: |
| 16 | static void PutLargeValueRef(WriteBatch* batch, |
| 17 | const Slice& key, |
| 18 | const LargeValueRef& large_ref); |
| 19 | |
| 20 | // Return the number of entries in the batch. |
| 21 | static int Count(const WriteBatch* batch); |
| 22 | |
| 23 | // Set the count for the number of entries in the batch. |
| 24 | static void SetCount(WriteBatch* batch, int n); |
| 25 | |
| 26 | // Return the seqeunce number for the start of this batch. |
| 27 | static SequenceNumber Sequence(const WriteBatch* batch); |
| 28 | |
| 29 | // Store the specified number as the seqeunce number for the start of |
| 30 | // this batch. |
| 31 | static void SetSequence(WriteBatch* batch, SequenceNumber seq); |
| 32 | |
| 33 | static Slice Contents(const WriteBatch* batch) { |
| 34 | return Slice(batch->rep_); |
| 35 | } |
| 36 | |
| 37 | static size_t ByteSize(const WriteBatch* batch) { |
| 38 | return batch->rep_.size(); |
| 39 | } |
| 40 | |
| 41 | static void SetContents(WriteBatch* batch, const Slice& contents); |
| 42 | |
| 43 | static Status InsertInto(const WriteBatch* batch, MemTable* memtable); |
| 44 | |
| 45 | // Iterate over the contents of a write batch. |
| 46 | class Iterator { |
| 47 | public: |
| 48 | explicit Iterator(const WriteBatch& batch); |
| 49 | bool Done() const { return done_; } |
| 50 | void Next(); |
| 51 | ValueType op() const { return op_; } |
| 52 | const Slice& key() const { return key_; } |
| 53 | const Slice& value() const { return value_; } |
| 54 | SequenceNumber sequence_number() const { return seq_; } |
| 55 | Status status() const { return status_; } |
| 56 | |
| 57 | private: |
| 58 | void GetNextEntry(); |
| 59 | |
| 60 | Slice input_; |
| 61 | bool done_; |
| 62 | ValueType op_; |
| 63 | Slice key_; |
| 64 | Slice value_; |
| 65 | SequenceNumber seq_; |
| 66 | Status status_; |
| 67 | }; |
| 68 | }; |
| 69 | |
| 70 | } |
| 71 | |
| 72 | |
| 73 | #endif // STORAGE_LEVELDB_DB_WRITE_BATCH_INTERNAL_H_ |