DP3
utils.h
Go to the documentation of this file.
1 // Copyright (C) 2023 ASTRON (Netherlands Institute for Radio Astronomy)
2 // SPDX-License-Identifier: GPL-3.0-or-later
3 
4 #ifndef DP3_PYTHONDP3_UTILS_H_
5 #define DP3_PYTHONDP3_UTILS_H_
6 
7 #include <ostream>
8 #include <string>
9 
10 namespace dp3::pythondp3 {
11 
12 // The purpose of the ostream_wrapper is to make it possible pass a
13 // C++ std::ostream to python to be used there as text stream.
14 // A python text stream should implement a write() method that accepts a str.
15 // The python documentation on the io module explicitly states that passing
16 // anything else but a str to the write method of a text stream is an error,
17 // see https://docs.python.org/3/library/io.html#module-io.
18 // Therefore the wrapper only accepts strings, even though a C++ output stream
19 // accepts many different types.
20 
22  public:
23  ostream_wrapper(std::ostream& output_stream)
24  : output_stream_(output_stream) {}
25  void write(std::string& text) { output_stream_ << text; }
26 
27  private:
28  std::ostream& output_stream_;
29 };
30 
31 } // namespace dp3::pythondp3
32 
33 #endif // DP3_PYTHONDP3_UTILS_H_
Definition: utils.h:21
ostream_wrapper(std::ostream &output_stream)
Definition: utils.h:23
void write(std::string &text)
Definition: utils.h:25
Definition: PyDpBuffer.h:9