1 | /* |
2 | * Copyright 2017 Google Inc. |
3 | * |
4 | * Use of this source code is governed by a BSD-style license that can be |
5 | * found in the LICENSE file. |
6 | */ |
7 | |
8 | #ifndef SKSL_OUTPUTSTREAM |
9 | #define SKSL_OUTPUTSTREAM |
10 | |
11 | #include "src/sksl/SkSLDefines.h" |
12 | #include "src/sksl/SkSLString.h" |
13 | |
14 | namespace SkSL { |
15 | |
16 | class OutputStream { |
17 | public: |
18 | virtual bool isValid() const { |
19 | return true; |
20 | } |
21 | |
22 | virtual void write8(uint8_t b) = 0; |
23 | |
24 | void write16(uint16_t i) { |
25 | this->write8((uint8_t) i); |
26 | this->write8((uint8_t) (i >> 8)); |
27 | } |
28 | |
29 | void write32(uint32_t i) { |
30 | this->write8((uint8_t) i); |
31 | this->write8((uint8_t) (i >> 8)); |
32 | this->write8((uint8_t) (i >> 16)); |
33 | this->write8((uint8_t) (i >> 24)); |
34 | } |
35 | |
36 | virtual void writeText(const char* s) = 0; |
37 | |
38 | virtual void write(const void* s, size_t size) = 0; |
39 | |
40 | void writeString(String s); |
41 | |
42 | void printf(const char format[], ...) SKSL_PRINTF_LIKE(2, 3); |
43 | |
44 | void appendVAList(const char format[], va_list args); |
45 | |
46 | virtual ~OutputStream() {} |
47 | |
48 | private: |
49 | static const int kBufferSize = 1024; |
50 | }; |
51 | |
52 | } // namespace SkSL |
53 | |
54 | #endif |
55 | |