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_STRING_STREAM_H_ | 5 #ifndef V8_STRING_STREAM_H_ |
6 #define V8_STRING_STREAM_H_ | 6 #define V8_STRING_STREAM_H_ |
7 | 7 |
8 #include "src/handles.h" | 8 #include "src/handles.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 17 matching lines...) Expand all Loading... |
28 public: | 28 public: |
29 ~HeapStringAllocator() { DeleteArray(space_); } | 29 ~HeapStringAllocator() { DeleteArray(space_); } |
30 virtual char* allocate(unsigned bytes) V8_OVERRIDE; | 30 virtual char* allocate(unsigned bytes) V8_OVERRIDE; |
31 virtual char* grow(unsigned* bytes) V8_OVERRIDE; | 31 virtual char* grow(unsigned* bytes) V8_OVERRIDE; |
32 | 32 |
33 private: | 33 private: |
34 char* space_; | 34 char* space_; |
35 }; | 35 }; |
36 | 36 |
37 | 37 |
38 // Allocator for use when no new c++ heap allocation is allowed. | |
39 // Given a preallocated buffer up front and does no allocation while | |
40 // building message. | |
41 class NoAllocationStringAllocator V8_FINAL : public StringAllocator { | |
42 public: | |
43 NoAllocationStringAllocator(char* memory, unsigned size); | |
44 virtual char* allocate(unsigned bytes) V8_OVERRIDE { return space_; } | |
45 virtual char* grow(unsigned* bytes) V8_OVERRIDE; | |
46 | |
47 private: | |
48 unsigned size_; | |
49 char* space_; | |
50 }; | |
51 | |
52 | |
53 class FmtElm V8_FINAL { | 38 class FmtElm V8_FINAL { |
54 public: | 39 public: |
55 FmtElm(int value) : type_(INT) { // NOLINT | 40 FmtElm(int value) : type_(INT) { // NOLINT |
56 data_.u_int_ = value; | 41 data_.u_int_ = value; |
57 } | 42 } |
58 explicit FmtElm(double value) : type_(DOUBLE) { | 43 explicit FmtElm(double value) : type_(DOUBLE) { |
59 data_.u_double_ = value; | 44 data_.u_double_ = value; |
60 } | 45 } |
61 FmtElm(const char* value) : type_(C_STR) { // NOLINT | 46 FmtElm(const char* value) : type_(C_STR) { // NOLINT |
62 data_.u_c_str_ = value; | 47 data_.u_c_str_ = value; |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 unsigned capacity_; | 146 unsigned capacity_; |
162 unsigned length_; // does not include terminating 0-character | 147 unsigned length_; // does not include terminating 0-character |
163 char* buffer_; | 148 char* buffer_; |
164 | 149 |
165 bool full() const { return (capacity_ - length_) == 1; } | 150 bool full() const { return (capacity_ - length_) == 1; } |
166 int space() const { return capacity_ - length_; } | 151 int space() const { return capacity_ - length_; } |
167 | 152 |
168 DISALLOW_IMPLICIT_CONSTRUCTORS(StringStream); | 153 DISALLOW_IMPLICIT_CONSTRUCTORS(StringStream); |
169 }; | 154 }; |
170 | 155 |
171 | |
172 // Utility class to print a list of items to a stream, divided by a separator. | |
173 class SimpleListPrinter V8_FINAL { | |
174 public: | |
175 explicit SimpleListPrinter(StringStream* stream, char separator = ',') { | |
176 separator_ = separator; | |
177 stream_ = stream; | |
178 first_ = true; | |
179 } | |
180 | |
181 void Add(const char* str) { | |
182 if (first_) { | |
183 first_ = false; | |
184 } else { | |
185 stream_->Put(separator_); | |
186 } | |
187 stream_->Add(str); | |
188 } | |
189 | |
190 private: | |
191 bool first_; | |
192 char separator_; | |
193 StringStream* stream_; | |
194 }; | |
195 | |
196 } } // namespace v8::internal | 156 } } // namespace v8::internal |
197 | 157 |
198 #endif // V8_STRING_STREAM_H_ | 158 #endif // V8_STRING_STREAM_H_ |
OLD | NEW |