Debian Codegraph @

modules/lsp-runtime-lib/include/lsp-plug.in/io/IOutStream.h

raw
1 /*
2 * Copyright (C) 2024 Linux Studio Plugins Project <https://lsp-plug.in/>
3 * (C) 2024 Vladimir Sadovnikov <[email protected]>
4 *
5 * This file is part of lsp-runtime-lib
6 * Created on: 14 нояб. 2017 г.
7 *
8 * lsp-runtime-lib is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version.
12 *
13 * lsp-runtime-lib is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with lsp-runtime-lib. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22 #ifndef LSP_PLUG_IN_IO_IOUTSTREAM_H_
23 #define LSP_PLUG_IN_IO_IOUTSTREAM_H_
24
25 #include <lsp-plug.in/runtime/version.h>
26 #include <lsp-plug.in/common/types.h>
27 #include <lsp-plug.in/common/status.h>
28
29 namespace lsp
30 {
31 namespace io
32 {
33 class IOutStream
34 {
35 protected:
36 status_t nErrorCode;
37
38 protected:
39 inline status_t set_error(status_t error) { return nErrorCode = error; }
40
41 public:
42 explicit IOutStream();
43 IOutStream(const IOutStream &) = delete;
44 IOutStream(IOutStream &&) = delete;
45 virtual ~IOutStream();
46
47 IOutStream & operator = (const IOutStream &) = delete;
48 IOutStream & operator = (IOutStream &&) = delete;
49
50 public:
51 /** Get last I/O error code
52 *
53 * @return last I/O error code
54 */
55 inline status_t last_error() const { return nErrorCode; };
56
57 /** The current read position
58 *
59 * @return current write position or error code
60 */
61 virtual wssize_t position();
62
63 /** Write the data to output stream.
64 * The implementation should write the most possible amount
65 * of bytes before exit. Such behaviour will simplify the caller's
66 * implementation.
67 *
68 * @param buf buffer to write
69 * @param count number of bytes
70 * @return number of bytes actually written or negative error code
71 */
72 virtual ssize_t write(const void *buf, size_t count);
73
74 /**
75 * Write a single byte to underlying storage
76 * @param v byte to write
77 * @deprecated use write_byte
78 * @return number of bytes actually written or negative error code
79 */
80 [[deprecated]]
81 virtual ssize_t writeb(int v);
82
83 /**
84 * Write a single byte to underlying storage
85 * @param v byte to write
86 * @return number of bytes actually written or negative error code
87 */
88 virtual status_t write_byte(int v);
89
90 /** Seek the stream to the specified position from the beginning
91 *
92 * @param position the specified position
93 * @return real position or negative value on error
94 */
95 virtual wssize_t seek(wsize_t position);
96
97 /**
98 * Flush buffers to underlying storage
99 * @return status of operation
100 */
101 virtual status_t flush();
102
103 /** Close the clip data stream
104 *
105 * @return status of operation
106 */
107 virtual status_t close();
108 };
109
110 /**
111 * Finalize output stream according to wrapping flags
112 * @param os output stream to finalize
113 * @param wrap_flags wrap fiags
114 * @return status of operation
115 */
116 status_t finalize(io::IOutStream *os, size_t wrap_flags);
117
118 } /* namespace io */
119 } /* namespace lsp */
120
121 #endif /* LSP_PLUG_IN_IO_IOUTSTREAM_H_ */