Debian Codegraph @

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

raw
1 /*
2 * Copyright (C) 2023 Linux Studio Plugins Project <https://lsp-plug.in/>
3 * (C) 2023 Vladimir Sadovnikov <[email protected]>
4 *
5 * This file is part of lsp-runtime-lib
6 * Created on: 19 авг. 2019 г.
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_OUTMEMORYSTREAM_H_
23 #define LSP_PLUG_IN_IO_OUTMEMORYSTREAM_H_
24
25 #include <lsp-plug.in/runtime/version.h>
26 #include <lsp-plug.in/io/IOutStream.h>
27
28 namespace lsp
29 {
30 namespace io
31 {
32
33 class OutMemoryStream: public IOutStream
34 {
35 private:
36 uint8_t *pData;
37 size_t nSize;
38 size_t nCapacity;
39 size_t nQuantity;
40 size_t nPosition;
41
42 public:
43 explicit OutMemoryStream();
44 explicit OutMemoryStream(size_t quantity);
45 OutMemoryStream(const OutMemoryStream &) = delete;
46 OutMemoryStream(OutMemoryStream &&) = delete;
47 virtual ~OutMemoryStream() override;
48
49 OutMemoryStream & operator = (const OutMemoryStream &) = delete;
50 OutMemoryStream & operator = (OutMemoryStream &&) = delete;
51
52 public:
53 /**
54 * Get current contents of the memory buffer
55 * @return contents of the memory buffer, may be NULL if there is no data
56 */
57 const uint8_t *data() const { return pData; }
58
59 /**
60 * Get current size of memory buffer
61 * @return size of memory buffer
62 */
63 const size_t size() const { return nSize; }
64
65 /**
66 * Get capacity of the memory buffer
67 * @return capacity of the memory buffer
68 */
69 const size_t capacity() const { return nCapacity; }
70
71 /**
72 * Get grow quantity of the memory buffer
73 * @return grow quantity
74 */
75 const size_t quantity() const { return nQuantity; }
76
77 /**
78 * Release the internal buffer and return it's contents
79 * @return the pointer to data that should be free()'d after use
80 */
81 uint8_t *release();
82
83 /**
84 * Drop internal stream data and reset position
85 */
86 void drop();
87
88 /** Reset the size of memory buffer
89 *
90 */
91 void clear();
92
93 /** Reduce the buffer size to the specified value if it was greater
94 * @return true if the size has been reduced
95 */
96 bool reduce(size_t size);
97
98 /**
99 * Reserve amount of data
100 * @param amount amount of bytes to reserve
101 * @return status of operation
102 */
103 status_t reserve(size_t amount);
104
105 public: // io::IOutStream
106 virtual wssize_t position() override;
107 virtual ssize_t write(const void *buf, size_t count) override;
108 virtual ssize_t writeb(int v) override;
109 virtual status_t write_byte(int v) override;
110 virtual wssize_t seek(wsize_t position) override;
111 virtual status_t flush() override;
112 virtual status_t close() override;
113 };
114
115 } /* namespace io */
116 } /* namespace lsp */
117
118 #endif /* LSP_PLUG_IN_IO_OUTMEMORYSTREAM_H_ */