OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium 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 // Streams classes. | 5 // Streams classes. |
6 // | 6 // |
7 // These memory-resident streams are used for serialzing data into a sequential | 7 // These memory-resident streams are used for serialzing data into a sequential |
8 // region of memory. | 8 // region of memory. |
9 // Streams are divided into SourceStreams for reading and SinkStreams for | 9 // Streams are divided into SourceStreams for reading and SinkStreams for |
10 // writing. Streams are aggregated into Sets which allows several streams to be | 10 // writing. Streams are aggregated into Sets which allows several streams to be |
11 // used at once. Example: we can write A1, B1, A2, B2 but achive the memory | 11 // used at once. Example: we can write A1, B1, A2, B2 but achive the memory |
12 // layout A1 A2 B1 B2 by writing 'A's to one stream and 'B's to another. | 12 // layout A1 A2 B1 B2 by writing 'A's to one stream and 'B's to another. |
13 #ifndef COURGETTE_STREAMS_H_ | 13 #ifndef COURGETTE_STREAMS_H_ |
14 #define COURGETTE_STREAMS_H_ | 14 #define COURGETTE_STREAMS_H_ |
15 | 15 |
16 #include <stdio.h> // for FILE* | 16 #include <stdio.h> // for FILE* |
17 #include <string> | 17 #include <string> |
18 | 18 |
19 #include "base/basictypes.h" | 19 #include "base/basictypes.h" |
20 | 20 |
| 21 #include "courgette/memory_allocator.h" |
21 #include "courgette/region.h" | 22 #include "courgette/region.h" |
22 | 23 |
23 namespace courgette { | 24 namespace courgette { |
24 | 25 |
25 class SourceStream; | 26 class SourceStream; |
26 class SinkStream; | 27 class SinkStream; |
27 | 28 |
28 // Maximum number of streams in a stream set. | 29 // Maximum number of streams in a stream set. |
29 static const unsigned int kMaxStreams = 10; | 30 static const unsigned int kMaxStreams = 10; |
30 | 31 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 return reinterpret_cast<const uint8*>(buffer_.c_str()); | 145 return reinterpret_cast<const uint8*>(buffer_.c_str()); |
145 } | 146 } |
146 | 147 |
147 // Hints that the stream will grow by an additional |length| bytes. | 148 // Hints that the stream will grow by an additional |length| bytes. |
148 void Reserve(size_t length) { buffer_.reserve(length + buffer_.length()); } | 149 void Reserve(size_t length) { buffer_.reserve(length + buffer_.length()); } |
149 | 150 |
150 // Finished with this stream and any storage it has. | 151 // Finished with this stream and any storage it has. |
151 void Retire(); | 152 void Retire(); |
152 | 153 |
153 private: | 154 private: |
154 std::string buffer_; // Use a string to manage the stream's memory. | 155 // Use a string to manage the stream's memory. |
| 156 typedef std::basic_string<char, |
| 157 std::char_traits<char>, |
| 158 MemoryAllocator<char> > SinkBuffer; |
| 159 SinkBuffer buffer_; |
155 | 160 |
156 DISALLOW_COPY_AND_ASSIGN(SinkStream); | 161 DISALLOW_COPY_AND_ASSIGN(SinkStream); |
157 }; | 162 }; |
158 | 163 |
159 // A SourceStreamSet is a set of SourceStreams. | 164 // A SourceStreamSet is a set of SourceStreams. |
160 class SourceStreamSet { | 165 class SourceStreamSet { |
161 public: | 166 public: |
162 SourceStreamSet(); | 167 SourceStreamSet(); |
163 ~SourceStreamSet(); | 168 ~SourceStreamSet(); |
164 | 169 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 void CopyHeaderTo(SinkStream* stream); | 226 void CopyHeaderTo(SinkStream* stream); |
222 | 227 |
223 size_t count_; | 228 size_t count_; |
224 SinkStream streams_[kMaxStreams]; | 229 SinkStream streams_[kMaxStreams]; |
225 | 230 |
226 DISALLOW_COPY_AND_ASSIGN(SinkStreamSet); | 231 DISALLOW_COPY_AND_ASSIGN(SinkStreamSet); |
227 }; | 232 }; |
228 | 233 |
229 } // namespace | 234 } // namespace |
230 #endif // COURGETTE_STREAMS_H_ | 235 #endif // COURGETTE_STREAMS_H_ |
OLD | NEW |