forked from stellar/stellar-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBucketInputIterator.h
59 lines (45 loc) · 1.75 KB
/
BucketInputIterator.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#pragma once
// Copyright 2017 Stellar Development Foundation and contributors. Licensed
// under the Apache License, Version 2.0. See the COPYING file at the root
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0
#include "bucket/LedgerCmp.h"
#include "util/XDRStream.h"
#include "xdr/Stellar-ledger.h"
#include <memory>
namespace stellar
{
class Bucket;
// Helper class that reads through the entries in a bucket.
class BucketInputIterator
{
std::shared_ptr<Bucket const> mBucket;
// Validity and current-value of the iterator is funneled into a
// pointer. If
// non-null, it points to mEntry.
BucketEntry const* mEntryPtr{nullptr};
XDRInputFileStream mIn;
BucketEntry mEntry;
bool mSeenMetadata{false};
bool mSeenOtherEntries{false};
BucketMetadata mMetadata;
void loadEntry();
public:
operator bool() const;
// In general, BucketInputIterators will read-and-extract the first (and
// only) METAENTRY in a bucket if it's present, immediately upon opening the
// input stream. This should be transparent and ignorable in most cases,
// clients will just retrieve the _default_ BucketMetadata from the iterator
// in case it was constructed on a pre-METAENTRY bucket. In the unusual case
// (such as testing) where the client is interested in whether or not there
// _was_ a METAENTRY or not, the `seenMetadata` method here will indicate.
bool seenMetadata() const;
BucketMetadata const& getMetadata() const;
BucketEntry const& operator*();
BucketInputIterator(std::shared_ptr<Bucket const> bucket);
~BucketInputIterator();
BucketInputIterator& operator++();
std::streamoff pos();
size_t size() const;
void seek(std::streamoff offset);
};
}