Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 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 | |
Ethan Nicholas | daed259 | 2021-03-04 14:30:25 -0500 | [diff] [blame] | 11 | #include "include/private/SkSLDefines.h" |
| 12 | #include "include/private/SkSLString.h" |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 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 | |
Ethan Nicholas | c18bb51 | 2020-07-28 14:46:53 -0400 | [diff] [blame] | 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 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 36 | virtual void writeText(const char* s) = 0; |
| 37 | |
| 38 | virtual void write(const void* s, size_t size) = 0; |
| 39 | |
John Stiles | e1589a1 | 2020-10-08 13:56:46 -0400 | [diff] [blame] | 40 | void writeString(const String& s); |
Ethan Nicholas | 842d31b | 2019-01-22 10:59:11 -0500 | [diff] [blame] | 41 | |
John Stiles | 1dd2b4b | 2021-02-02 16:05:57 -0500 | [diff] [blame] | 42 | void printf(const char format[], ...) SK_PRINTF_LIKE(2, 3); |
Ethan Nicholas | 842d31b | 2019-01-22 10:59:11 -0500 | [diff] [blame] | 43 | |
| 44 | void appendVAList(const char format[], va_list args); |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 45 | |
| 46 | virtual ~OutputStream() {} |
Ethan Nicholas | 842d31b | 2019-01-22 10:59:11 -0500 | [diff] [blame] | 47 | |
| 48 | private: |
| 49 | static const int kBufferSize = 1024; |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 50 | }; |
| 51 | |
John Stiles | a6841be | 2020-08-06 14:11:56 -0400 | [diff] [blame] | 52 | } // namespace SkSL |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 53 | |
| 54 | #endif |