Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2021 MuseScore Limited and others
9 : *
10 : * This program is free software: you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License version 3 as
12 : * published by the Free Software Foundation.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 : */
22 : #pragma once
23 :
24 : #include <cstdint>
25 : #include <string_view>
26 : #include <vector>
27 :
28 : #ifndef NO_QT_SUPPORT
29 : #include <QString>
30 : #endif
31 :
32 : namespace muse {
33 : class ByteArray;
34 : class String;
35 :
36 : namespace io {
37 : class IODevice;
38 : }
39 :
40 : class TextStream
41 : {
42 : public:
43 2241 : TextStream() = default;
44 : explicit TextStream(io::IODevice* device);
45 : virtual ~TextStream();
46 :
47 : void setDevice(io::IODevice* device);
48 :
49 : void flush();
50 :
51 : TextStream& operator<<(char ch);
52 : TextStream& operator<<(int32_t);
53 : TextStream& operator<<(uint32_t);
54 : TextStream& operator<<(double);
55 : TextStream& operator<<(int64_t);
56 : TextStream& operator<<(uint64_t);
57 : TextStream& operator<<(const char* s);
58 : TextStream& operator<<(std::string_view);
59 : TextStream& operator<<(const ByteArray& b);
60 : TextStream& operator<<(const String& s);
61 :
62 : #ifndef NO_QT_SUPPORT
63 : TextStream& operator<<(const QString& s);
64 : #endif
65 :
66 : private:
67 : void write(const char* ch, size_t len);
68 : io::IODevice* m_device = nullptr;
69 : std::vector<uint8_t> m_buf;
70 : };
71 : }
|