blob: 108acb42924f6f5fcb78f650fe156821237ea7d4 (
plain)
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
|
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2026
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#pragma once
#include "td/utils/ChangesProcessor.h"
#include "td/utils/common.h"
namespace td {
// It is not about handling gaps.
// It is about finding mem processed PTS.
// All checks must be done before.
class PtsManager {
public:
using PtsId = ChangesProcessor<int32>::Id;
void init(int32 pts) {
db_pts_ = pts;
mem_pts_ = pts;
state_helper_.clear();
}
// 0 if not a checkpoint
PtsId add_pts(int32 pts) {
if (pts > 0) {
mem_pts_ = pts;
}
return state_helper_.add(pts);
}
// return db_pts
int32 finish(PtsId pts_id) {
state_helper_.finish(pts_id, [&](int32 pts) {
if (pts != 0) {
db_pts_ = pts;
}
});
return db_pts_;
}
int32 db_pts() const {
return db_pts_;
}
int32 mem_pts() const {
return mem_pts_;
}
private:
int32 db_pts_ = -1;
int32 mem_pts_ = -1;
ChangesProcessor<int32> state_helper_;
};
} // namespace td
|