| 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 июн. 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_IINSEQUENCE_H_ |
| 23 |
#define LSP_PLUG_IN_IO_IINSEQUENCE_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 |
#include <lsp-plug.in/runtime/LSPString.h> |
| 29 |
|
| 30 |
namespace lsp |
| 31 |
{ |
| 32 |
namespace io |
| 33 |
{ |
| 34 |
class IOutSequence; |
| 35 |
|
| 36 |
class IInSequence |
| 37 |
{ |
| 38 |
protected: |
| 39 |
status_t nErrorCode; |
| 40 |
|
| 41 |
protected: |
| 42 |
inline status_t set_error(status_t error) { return nErrorCode = error; } |
| 43 |
|
| 44 |
public: |
| 45 |
explicit IInSequence(); |
| 46 |
IInSequence(const IInSequence &) = delete; |
| 47 |
IInSequence(IInSequence &&) = delete; |
| 48 |
virtual ~IInSequence(); |
| 49 |
|
| 50 |
IInSequence & operator = (const IInSequence &) = delete; |
| 51 |
IInSequence & operator = (IInSequence &&) = delete; |
| 52 |
|
| 53 |
public: |
| 54 |
/** |
| 55 |
* Return last error code |
| 56 |
* @return last error code |
| 57 |
*/ |
| 58 |
inline status_t last_error() const { return nErrorCode; }; |
| 59 |
|
| 60 |
/** |
| 61 |
* Read amount of characters |
| 62 |
* @param dst target buffer to read |
| 63 |
* @param count number of characters to read |
| 64 |
* @return actual number of characters read or negative value on end of stream |
| 65 |
*/ |
| 66 |
virtual ssize_t read(lsp_wchar_t *dst, size_t count); |
| 67 |
|
| 68 |
/** |
| 69 |
* Read single character |
| 70 |
* @return code of single character or negative value on end of stream |
| 71 |
*/ |
| 72 |
virtual lsp_swchar_t read(); |
| 73 |
|
| 74 |
/** |
| 75 |
* Read single line |
| 76 |
* @param s string to store value |
| 77 |
* @return status of operation |
| 78 |
*/ |
| 79 |
virtual status_t read_line(LSPString *s, bool force = false); |
| 80 |
|
| 81 |
/** |
| 82 |
* Skip amount of characters |
| 83 |
* @param count number of characters to skip |
| 84 |
* @return number of skipped characters or negative error code |
| 85 |
*/ |
| 86 |
virtual ssize_t skip(size_t count); |
| 87 |
|
| 88 |
/** |
| 89 |
* Close input stream |
| 90 |
* @return status of operation |
| 91 |
*/ |
| 92 |
virtual status_t close(); |
| 93 |
|
| 94 |
/** |
| 95 |
* Mark position of the input sequence |
| 96 |
* @param limit the read limit after that the mark becomes invalid, |
| 97 |
* negative value is allowed to check support of mark() and reset() |
| 98 |
* calls by sequence |
| 99 |
* @return status of operation |
| 100 |
* - STATUS_NOT_SUPPORTED if feature is not supported by this sequence |
| 101 |
*/ |
| 102 |
virtual status_t mark(ssize_t limit); |
| 103 |
|
| 104 |
/** |
| 105 |
* Sink all data to the output sequence |
| 106 |
* @param os pointer to the output stream |
| 107 |
* @return number of characters processed or negative error code |
| 108 |
*/ |
| 109 |
virtual wssize_t sink(IOutSequence *os, size_t buf_size = 0x1000); |
| 110 |
|
| 111 |
/** |
| 112 |
* Reset position to the sequence to previously set mark |
| 113 |
* @return status of operation |
| 114 |
* - STATUS_NOT_FOUND if mark was not set or became invalid |
| 115 |
* - STATUS_NOT_SUPPORTED if feature is not supported by this sequence |
| 116 |
*/ |
| 117 |
virtual status_t reset(); |
| 118 |
|
| 119 |
}; |
| 120 |
|
| 121 |
} /* namespace io */ |
| 122 |
} /* namespace lsp */ |
| 123 |
|
| 124 |
#endif /* LSP_PLUG_IN_IO_IINSEQUENCE_H_ */ |