summaryrefslogtreecommitdiffstats
path: root/courgette/streams.h
diff options
context:
space:
mode:
Diffstat (limited to 'courgette/streams.h')
-rw-r--r--courgette/streams.h32
1 files changed, 13 insertions, 19 deletions
diff --git a/courgette/streams.h b/courgette/streams.h
index 2543e99..ff65d13 100644
--- a/courgette/streams.h
+++ b/courgette/streams.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -121,21 +121,21 @@ class SinkStream {
~SinkStream() {}
// Appends |byte_count| bytes from |data| to the stream.
- CheckBool Write(const void* data, size_t byte_count);
+ CheckBool Write(const void* data, size_t byte_count) WARN_UNUSED_RESULT;
// Appends the 'varint32' encoding of |value| to the stream.
- CheckBool WriteVarint32(uint32 value);
+ CheckBool WriteVarint32(uint32 value) WARN_UNUSED_RESULT;
// Appends the 'varint32' encoding of |value| to the stream.
- CheckBool WriteVarint32Signed(int32 value);
+ CheckBool WriteVarint32Signed(int32 value) WARN_UNUSED_RESULT;
// Appends the 'varint32' encoding of |value| to the stream.
// On platforms where sizeof(size_t) != sizeof(int32), do a safety check.
- CheckBool WriteSizeVarint32(size_t value);
+ CheckBool WriteSizeVarint32(size_t value) WARN_UNUSED_RESULT;
// Contents of |other| are appended to |this| stream. The |other| stream
// becomes retired.
- CheckBool Append(SinkStream* other);
+ CheckBool Append(SinkStream* other) WARN_UNUSED_RESULT;
// Returns the number of bytes in this SinkStream
size_t Length() const { return buffer_.size(); }
@@ -144,26 +144,20 @@ class SinkStream {
// Writing to the stream invalidates the pointer. The SinkStream continues to
// own the memory.
const uint8* Buffer() const {
- return reinterpret_cast<const uint8*>(buffer_.c_str());
+ return reinterpret_cast<const uint8*>(buffer_.data());
}
// Hints that the stream will grow by an additional |length| bytes.
// Caller must be prepared to handle memory allocation problems.
- CheckBool Reserve(size_t length) {
- buffer_.reserve(length + buffer_.length());
- //TODO(tommi): return false when allocation fails.
- return true;
+ CheckBool Reserve(size_t length) WARN_UNUSED_RESULT {
+ return buffer_.reserve(length + buffer_.size());
}
// Finished with this stream and any storage it has.
void Retire();
private:
- // Use a string to manage the stream's memory.
- typedef std::basic_string<char,
- std::char_traits<char>,
- MemoryAllocator<char> > SinkBuffer;
- SinkBuffer buffer_;
+ NoThrowBuffer<char> buffer_;
DISALLOW_COPY_AND_ASSIGN(SinkStream);
};
@@ -222,15 +216,15 @@ class SinkStreamSet {
// CopyTo serializes the streams in this SinkStreamSet into a single target
// stream. The serialized format may be re-read by initializing a
// SourceStreamSet with a buffer containing the data.
- CheckBool CopyTo(SinkStream* combined_stream);
+ CheckBool CopyTo(SinkStream* combined_stream) WARN_UNUSED_RESULT;
// Writes the streams of |set| into the corresponding streams of |this|.
// Stream zero first has some metadata written to it. |set| becomes retired.
// Partner to SourceStreamSet::ReadSet.
- CheckBool WriteSet(SinkStreamSet* set);
+ CheckBool WriteSet(SinkStreamSet* set) WARN_UNUSED_RESULT;
private:
- CheckBool CopyHeaderTo(SinkStream* stream);
+ CheckBool CopyHeaderTo(SinkStream* stream) WARN_UNUSED_RESULT;
size_t count_;
SinkStream streams_[kMaxStreams];