| 1 |
/* |
| 2 |
* Copyright (C) 2025 Linux Studio Plugins Project <https://lsp-plug.in/> |
| 3 |
* (C) 2025 Vladimir Sadovnikov <[email protected]> |
| 4 |
* |
| 5 |
* This file is part of lsp-runtime-lib |
| 6 |
* Created on: 14 июн. 2018 г. |
| 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_IOUTSEQUENCE_H_ |
| 23 |
#define LSP_PLUG_IN_IO_IOUTSEQUENCE_H_ |
| 24 |
|
| 25 |
#include <lsp-plug.in/runtime/version.h> |
| 26 |
#include <lsp-plug.in/runtime/LSPString.h> |
| 27 |
#include <lsp-plug.in/common/types.h> |
| 28 |
#include <lsp-plug.in/common/status.h> |
| 29 |
|
| 30 |
namespace lsp |
| 31 |
{ |
| 32 |
namespace io |
| 33 |
{ |
| 34 |
class IOutSequence |
| 35 |
{ |
| 36 |
protected: |
| 37 |
status_t nErrorCode; |
| 38 |
|
| 39 |
protected: |
| 40 |
inline status_t set_error(status_t error) { return nErrorCode = error; } |
| 41 |
|
| 42 |
public: |
| 43 |
explicit IOutSequence(); |
| 44 |
IOutSequence(const IOutSequence &) = delete; |
| 45 |
IOutSequence(IOutSequence &&) = delete; |
| 46 |
virtual ~IOutSequence(); |
| 47 |
|
| 48 |
IOutSequence & operator = (const IOutSequence &) = delete; |
| 49 |
IOutSequence & operator = (IOutSequence &&) = delete; |
| 50 |
|
| 51 |
public: |
| 52 |
/** |
| 53 |
* Return last error code |
| 54 |
* @return last error code |
| 55 |
*/ |
| 56 |
inline status_t last_error() const { return nErrorCode; }; |
| 57 |
|
| 58 |
/** |
| 59 |
* Write single character to output stream |
| 60 |
* @param c character to write |
| 61 |
* @return status of operation |
| 62 |
*/ |
| 63 |
virtual status_t write(lsp_wchar_t c); |
| 64 |
|
| 65 |
/** |
| 66 |
* Write single character to output stream and trailing end-of-line |
| 67 |
* @param c character to write |
| 68 |
* @return status of operation |
| 69 |
*/ |
| 70 |
virtual status_t writeln(lsp_wchar_t c); |
| 71 |
|
| 72 |
/** |
| 73 |
* Write multiple characters to output stream |
| 74 |
* @param c array of characters to write |
| 75 |
* @param count number of characters to write |
| 76 |
* @return status of operation |
| 77 |
*/ |
| 78 |
virtual status_t write(const lsp_wchar_t *c, size_t count); |
| 79 |
|
| 80 |
/** |
| 81 |
* Write multiple characters to output stream and end-of-line |
| 82 |
* @param c array of characters to write |
| 83 |
* @param count number of characters to write |
| 84 |
* @return status of operation |
| 85 |
*/ |
| 86 |
virtual status_t writeln(const lsp_wchar_t *c, size_t count); |
| 87 |
|
| 88 |
/** |
| 89 |
* Write null-terminated ASCII string to output |
| 90 |
* @param s ASCII string to write |
| 91 |
* @return status of operation |
| 92 |
*/ |
| 93 |
virtual status_t write_ascii(const char *s); |
| 94 |
|
| 95 |
/** |
| 96 |
* Write ASCII character sequence to output |
| 97 |
* @param s ASCII string to write |
| 98 |
* @param count number of characters to write |
| 99 |
* @return status of operation |
| 100 |
*/ |
| 101 |
virtual status_t write_ascii(const char *s, size_t count); |
| 102 |
|
| 103 |
/** |
| 104 |
* Write zero-terminated ASCII string to output and end-of-line |
| 105 |
* @param s ASCII string to write |
| 106 |
* @return status of operation |
| 107 |
*/ |
| 108 |
virtual status_t writeln_ascii(const char *s); |
| 109 |
|
| 110 |
/** |
| 111 |
* Write string to output stream |
| 112 |
* @param s string to write |
| 113 |
* @return status of operation |
| 114 |
*/ |
| 115 |
virtual status_t write(const LSPString *s); |
| 116 |
|
| 117 |
/** |
| 118 |
* Write string to output stream and end-of-line |
| 119 |
* @param s string to write |
| 120 |
* @return status of operation |
| 121 |
*/ |
| 122 |
virtual status_t writeln(const LSPString *s); |
| 123 |
|
| 124 |
/** |
| 125 |
* Write substring to output stream |
| 126 |
* @param s string to write |
| 127 |
* @param first index of first character to write substring from |
| 128 |
* @return status of operation |
| 129 |
*/ |
| 130 |
virtual status_t write(const LSPString *s, ssize_t first); |
| 131 |
|
| 132 |
/** |
| 133 |
* Write substring to output stream and end-of-line |
| 134 |
* @param s string to write |
| 135 |
* @param first index of first character to write substring from |
| 136 |
* @return status of operation |
| 137 |
*/ |
| 138 |
virtual status_t writeln(const LSPString *s, ssize_t first); |
| 139 |
|
| 140 |
/** |
| 141 |
* Write substring to output stream |
| 142 |
* @param s string to write |
| 143 |
* @param first index of first character to write substring from |
| 144 |
* @param last index of last character to write substring |
| 145 |
* @return status of operation |
| 146 |
*/ |
| 147 |
virtual status_t write(const LSPString *s, ssize_t first, ssize_t last); |
| 148 |
|
| 149 |
/** |
| 150 |
* Write substring to output stream and end-of-line |
| 151 |
* @param s string to write |
| 152 |
* @param first index of first character to write substring from |
| 153 |
* @param last index of last character to write substring |
| 154 |
* @return status of operation |
| 155 |
*/ |
| 156 |
virtual status_t writeln(const LSPString *s, ssize_t first, ssize_t last); |
| 157 |
|
| 158 |
/** |
| 159 |
* Flush all underlying buffers |
| 160 |
* @return status of operation |
| 161 |
*/ |
| 162 |
virtual status_t flush(); |
| 163 |
|
| 164 |
/** |
| 165 |
* Close character output stream |
| 166 |
* @return status of operation |
| 167 |
*/ |
| 168 |
virtual status_t close(); |
| 169 |
}; |
| 170 |
|
| 171 |
} /* namespace io */ |
| 172 |
} /* namespace lsp */ |
| 173 |
|
| 174 |
#endif /* LSP_PLUG_IN_IO_IOUTSEQUENCE_H_ */ |