| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_OSTREAMS_H_ | 5 #ifndef V8_OSTREAMS_H_ |
| 6 #define V8_OSTREAMS_H_ | 6 #define V8_OSTREAMS_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdio.h> | 9 #include <stdio.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 } | 76 } |
| 77 ~OStringStream() { deallocate(data_, capacity_); } | 77 ~OStringStream() { deallocate(data_, capacity_); } |
| 78 | 78 |
| 79 size_t size() const { return size_; } | 79 size_t size() const { return size_; } |
| 80 size_t capacity() const { return capacity_; } | 80 size_t capacity() const { return capacity_; } |
| 81 const char* data() const { return data_; } | 81 const char* data() const { return data_; } |
| 82 | 82 |
| 83 // Internally, our character data is always 0-terminated. | 83 // Internally, our character data is always 0-terminated. |
| 84 const char* c_str() const { return data(); } | 84 const char* c_str() const { return data(); } |
| 85 | 85 |
| 86 virtual OStringStream& write(const char* s, size_t n) V8_OVERRIDE; | 86 virtual OStringStream& write(const char* s, size_t n) OVERRIDE; |
| 87 virtual OStringStream& flush() V8_OVERRIDE; | 87 virtual OStringStream& flush() OVERRIDE; |
| 88 | 88 |
| 89 private: | 89 private: |
| 90 // Primitive allocator interface, can be extracted if needed. | 90 // Primitive allocator interface, can be extracted if needed. |
| 91 static char* allocate (size_t n) { return new char[n]; } | 91 static char* allocate (size_t n) { return new char[n]; } |
| 92 static void deallocate (char* s, size_t n) { delete[] s; } | 92 static void deallocate (char* s, size_t n) { delete[] s; } |
| 93 | 93 |
| 94 void reserve(size_t requested_capacity); | 94 void reserve(size_t requested_capacity); |
| 95 | 95 |
| 96 size_t size_; | 96 size_t size_; |
| 97 size_t capacity_; | 97 size_t capacity_; |
| 98 char* data_; | 98 char* data_; |
| 99 | 99 |
| 100 DISALLOW_COPY_AND_ASSIGN(OStringStream); | 100 DISALLOW_COPY_AND_ASSIGN(OStringStream); |
| 101 }; | 101 }; |
| 102 | 102 |
| 103 | 103 |
| 104 // An output stream writing to a file. | 104 // An output stream writing to a file. |
| 105 class OFStream: public OStream { | 105 class OFStream: public OStream { |
| 106 public: | 106 public: |
| 107 explicit OFStream(FILE* f) : f_(f) { } | 107 explicit OFStream(FILE* f) : f_(f) { } |
| 108 virtual ~OFStream() { } | 108 virtual ~OFStream() { } |
| 109 | 109 |
| 110 virtual OFStream& write(const char* s, size_t n) V8_OVERRIDE; | 110 virtual OFStream& write(const char* s, size_t n) OVERRIDE; |
| 111 virtual OFStream& flush() V8_OVERRIDE; | 111 virtual OFStream& flush() OVERRIDE; |
| 112 | 112 |
| 113 private: | 113 private: |
| 114 FILE* const f_; | 114 FILE* const f_; |
| 115 | 115 |
| 116 DISALLOW_COPY_AND_ASSIGN(OFStream); | 116 DISALLOW_COPY_AND_ASSIGN(OFStream); |
| 117 }; | 117 }; |
| 118 | 118 |
| 119 | 119 |
| 120 // Wrappers to disambiguate uint16_t and uc16. | 120 // Wrappers to disambiguate uint16_t and uc16. |
| 121 struct AsUC16 { | 121 struct AsUC16 { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 134 // of printable ASCII range. Additionally escapes '\' making escaping | 134 // of printable ASCII range. Additionally escapes '\' making escaping |
| 135 // reversible. | 135 // reversible. |
| 136 OStream& operator<<(OStream& os, const AsReversiblyEscapedUC16& c); | 136 OStream& operator<<(OStream& os, const AsReversiblyEscapedUC16& c); |
| 137 | 137 |
| 138 // Writes the given character to the output escaping everything outside | 138 // Writes the given character to the output escaping everything outside |
| 139 // of printable ASCII range. | 139 // of printable ASCII range. |
| 140 OStream& operator<<(OStream& os, const AsUC16& c); | 140 OStream& operator<<(OStream& os, const AsUC16& c); |
| 141 } } // namespace v8::internal | 141 } } // namespace v8::internal |
| 142 | 142 |
| 143 #endif // V8_OSTREAMS_H_ | 143 #endif // V8_OSTREAMS_H_ |
| OLD | NEW |