]> git.sesse.net Git - plocate/blob - serializer.h
Release plocate 1.1.7.
[plocate] / serializer.h
1 #ifndef _SERIALIZER_H
2 #define _SERIALIZER_H 1
3
4 #include "options.h"
5
6 #include <assert.h>
7 #include <queue>
8 #include <stdint.h>
9 #include <string>
10
11 class ResultReceiver {
12 public:
13         virtual ~ResultReceiver() = default;
14         virtual void print(uint64_t seq, uint64_t skip, const std::string msg) = 0;
15 };
16
17 class Serializer : public ResultReceiver {
18 public:
19         ~Serializer() { assert(limit_left <= 0 || pending.empty()); }
20         void print(uint64_t seq, uint64_t skip, const std::string msg) override;
21
22 private:
23         uint64_t next_seq = 0;
24         struct Element {
25                 uint64_t seq, skip;
26                 std::string msg;
27
28                 bool operator<(const Element &other) const
29                 {
30                         return seq > other.seq;
31                 }
32         };
33         std::priority_queue<Element> pending;
34 };
35
36 #endif  // !defined(_SERIALIZER_H)