| 1 |
/* |
| 2 |
* Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/> |
| 3 |
* (C) 2020 Vladimir Sadovnikov <[email protected]> |
| 4 |
* |
| 5 |
* This file is part of lsp-runtime-lib |
| 6 |
* Created on: 16 июн. 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_INSEQUENCE_H_ |
| 23 |
#define LSP_PLUG_IN_IO_INSEQUENCE_H_ |
| 24 |
|
| 25 |
#include <lsp-plug.in/runtime/version.h> |
| 26 |
#include <lsp-plug.in/common/types.h> |
| 27 |
#include <lsp-plug.in/io/charset.h> |
| 28 |
#include <lsp-plug.in/io/Path.h> |
| 29 |
#include <lsp-plug.in/io/File.h> |
| 30 |
#include <lsp-plug.in/io/CharsetDecoder.h> |
| 31 |
#include <lsp-plug.in/io/IInSequence.h> |
| 32 |
#include <lsp-plug.in/io/IInStream.h> |
| 33 |
#include <lsp-plug.in/stdlib/stdio.h> |
| 34 |
|
| 35 |
namespace lsp |
| 36 |
{ |
| 37 |
namespace io |
| 38 |
{ |
| 39 |
class InSequence: public IInSequence |
| 40 |
{ |
| 41 |
protected: |
| 42 |
IInStream *pIS; |
| 43 |
size_t nWrapFlags; |
| 44 |
CharsetDecoder sDecoder; |
| 45 |
LSPString sLine; |
| 46 |
|
| 47 |
private: |
| 48 |
lsp_swchar_t read_internal(); |
| 49 |
|
| 50 |
public: |
| 51 |
explicit InSequence(); |
| 52 |
InSequence(const InSequence &) = delete; |
| 53 |
InSequence(InSequence &&) = delete; |
| 54 |
virtual ~InSequence(); |
| 55 |
|
| 56 |
InSequence & operator = (const InSequence &) = delete; |
| 57 |
InSequence & operator = (InSequence &&) = delete; |
| 58 |
|
| 59 |
public: |
| 60 |
/** Wrap stdio file descriptor. The Sequence should be in closed state. |
| 61 |
* |
| 62 |
* @param fd file descriptor |
| 63 |
* @param close close file descriptor on close() |
| 64 |
* @param charset character set to use, system charset if NULL |
| 65 |
* @return status of operation |
| 66 |
*/ |
| 67 |
status_t wrap(FILE *fd, bool close, const char *charset = NULL); |
| 68 |
|
| 69 |
/** Wrap native file descriptor. The Sequence should be in closed state. |
| 70 |
* |
| 71 |
* @param fd file descriptor |
| 72 |
* @param close close file descriptor on close() |
| 73 |
* @param charset character set to use, system charset if NULL |
| 74 |
* @return status of operation |
| 75 |
*/ |
| 76 |
status_t wrap_native(fhandle_t fd, bool close, const char *charset = NULL); |
| 77 |
|
| 78 |
/** Wrap file descriptor. The Sequence should be in closed state. |
| 79 |
* |
| 80 |
* @param fd file descriptor |
| 81 |
* @param flags wrapping flags |
| 82 |
* @param charset character set to use, system charset if NULL |
| 83 |
* @return status of operation |
| 84 |
*/ |
| 85 |
status_t wrap(File *fd, size_t flags, const char *charset = NULL); |
| 86 |
|
| 87 |
/** Wrap input stream. The Sequence should be in closed state. |
| 88 |
* |
| 89 |
* @param is input stream to wrap |
| 90 |
* @param flags wrapping flags |
| 91 |
* @param charset character set to use, system charset if NULL |
| 92 |
* @return status of operation |
| 93 |
*/ |
| 94 |
status_t wrap(IInStream *is, size_t flags, const char *charset = NULL); |
| 95 |
|
| 96 |
/** Open input stream associated with file. The Sequence should be in closed state. |
| 97 |
* |
| 98 |
* @param path file location path |
| 99 |
* @param charset character set to use, system charset if NULL |
| 100 |
* @return status of operation |
| 101 |
*/ |
| 102 |
status_t open(const char *path, const char *charset = NULL); |
| 103 |
|
| 104 |
/** Open input stream associated with file. The Sequence should be in closed state. |
| 105 |
* |
| 106 |
* @param path file location path |
| 107 |
* @param charset character set to use, system charset if NULL |
| 108 |
* @return status of operation |
| 109 |
*/ |
| 110 |
status_t open(const LSPString *path, const char *charset = NULL); |
| 111 |
|
| 112 |
/** Open input stream associated with file. Before open currently open stream is closed and it's |
| 113 |
* state is reset. |
| 114 |
* |
| 115 |
* @param path file location path |
| 116 |
* @param charset character set to use, system charset if NULL |
| 117 |
* @return status of operation |
| 118 |
*/ |
| 119 |
status_t open(const Path *path, const char *charset = NULL); |
| 120 |
|
| 121 |
virtual ssize_t read(lsp_wchar_t *dst, size_t count); |
| 122 |
|
| 123 |
virtual lsp_swchar_t read(); |
| 124 |
|
| 125 |
virtual status_t read_line(LSPString *s, bool force = false); |
| 126 |
|
| 127 |
virtual ssize_t skip(size_t count); |
| 128 |
|
| 129 |
virtual status_t close(); |
| 130 |
}; |
| 131 |
} |
| 132 |
} /* namespace lsp */ |
| 133 |
|
| 134 |
#endif /* LSP_PLUG_IN_IO_INSEQUENCE_H_ */ |