in_memory_proto_stream.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018 The Cartographer Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef CARTOGRAPHER_IO_INTERNAL_IN_MEMORY_PROTO_STREAM_H_
18 #define CARTOGRAPHER_IO_INTERNAL_IN_MEMORY_PROTO_STREAM_H_
19 
20 #include <queue>
21 
25 #include "google/protobuf/message.h"
26 
27 namespace cartographer {
28 namespace io {
29 
32  public:
33  // A callback that is invoked anytime 'WriteProto()' is called on the
34  // 'ForwardingProtoStreamWriter'. When 'Close()' is called on the
35  // 'ForwardingProtoStreamWriter' the callback is invoked with a 'nullptr'.
36  using WriterCallback =
37  std::function<bool(const google::protobuf::Message* proto)>;
38 
39  explicit ForwardingProtoStreamWriter(WriterCallback writer_callback)
40  : writer_callback_(writer_callback) {}
41  ~ForwardingProtoStreamWriter() = default;
42 
43  void WriteProto(const google::protobuf::Message& proto) override;
44  bool Close() override;
45 
46  private:
48 };
49 
52  public:
54  std::queue<std::unique_ptr<google::protobuf::Message>>&& state_chunks)
55  : state_chunks_(std::move(state_chunks)) {}
56  InMemoryProtoStreamReader() = default;
57  ~InMemoryProtoStreamReader() = default;
58 
61  delete;
62 
63  template <typename MessageType>
64  void AddProto(const MessageType& proto) {
65  state_chunks_.push(common::make_unique<MessageType>(proto));
66  }
67 
68  bool ReadProto(google::protobuf::Message* proto) override;
69  bool eof() const override { return state_chunks_.empty(); }
70 
71  private:
72  std::queue<std::unique_ptr<google::protobuf::Message>> state_chunks_;
73 };
74 
75 } // namespace io
76 } // namespace cartographer
77 
78 #endif // CARTOGRAPHER_IO_INTERNAL_IN_MEMORY_PROTO_STREAM_H_
std::queue< std::unique_ptr< google::protobuf::Message > > state_chunks_
std::function< bool(const google::protobuf::Message *proto)> WriterCallback
void WriteProto(const google::protobuf::Message &proto) override
InMemoryProtoStreamReader(std::queue< std::unique_ptr< google::protobuf::Message >> &&state_chunks)
ForwardingProtoStreamWriter(WriterCallback writer_callback)


cartographer
Author(s): The Cartographer Authors
autogenerated on Mon Feb 28 2022 22:00:58