Botan 3.9.0
Crypto and TLS for C&
data_snk.h
Go to the documentation of this file.
1/*
2* DataSink
3* (C) 1999-2007 Jack Lloyd
4* 2017 Philippe Lieser
5*
6* Botan is released under the Simplified BSD License (see license.txt)
7*/
8
9#ifndef BOTAN_DATA_SINK_H_
10#define BOTAN_DATA_SINK_H_
11
12#include <botan/filter.h>
13#include <iosfwd>
14#include <memory>
15
16namespace Botan {
17
18/**
19* This class represents abstract data sink objects.
20*/
21class BOTAN_PUBLIC_API(2, 0) DataSink : public Filter {
22 public:
23 bool attachable() override { return false; }
24};
25
26/**
27* This class represents a data sink which writes its output to a stream.
28*/
29class BOTAN_PUBLIC_API(2, 0) DataSink_Stream final : public DataSink {
30 public:
31 /**
32 * Construct a DataSink_Stream from a stream.
33 * @param stream the stream to write to
34 * @param name identifier
35 */
36 BOTAN_FUTURE_EXPLICIT DataSink_Stream(std::ostream& stream, std::string_view name = "<std::ostream>");
37
38#if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
39
40 /**
41 * Construct a DataSink_Stream from a filesystem path name.
42 * @param pathname the name of the file to open a stream to
43 * @param use_binary indicates whether to treat the file
44 * as a binary file or not
45 */
46 BOTAN_FUTURE_EXPLICIT DataSink_Stream(std::string_view pathname, bool use_binary = false);
47#endif
48
49 DataSink_Stream(const DataSink_Stream& other) = delete;
51 DataSink_Stream& operator=(const DataSink_Stream& other) = delete;
53
54 std::string name() const override { return m_identifier; }
55
56 void write(const uint8_t buf[], size_t len) override;
57
58 void end_msg() override;
59
60 ~DataSink_Stream() override;
61
62 private:
63 const std::string m_identifier;
64
65 // May be null, if m_sink was an external reference
66 std::unique_ptr<std::ostream> m_sink_memory;
67 std::ostream& m_sink;
68};
69
70} // namespace Botan
71
72#endif
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:21
#define BOTAN_FUTURE_EXPLICIT
Definition api.h:52
std::string name() const override
Definition data_snk.h:54
DataSink_Stream(const DataSink_Stream &other)=delete
DataSink_Stream & operator=(const DataSink_Stream &other)=delete
DataSink_Stream(DataSink_Stream &&other)=delete
DataSink_Stream & operator=(DataSink_Stream &&other)=delete
BOTAN_FUTURE_EXPLICIT DataSink_Stream(std::ostream &stream, std::string_view name="<std::ostream>")
Definition data_snk.cpp:43
~DataSink_Stream() override
bool attachable() override
Definition data_snk.h:23
Filter(const Filter &)=delete