Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Side by Side Diff: include/utils/SkFrontBufferedStream.h

Issue 25581002: Hide implementation details: SkFrontBufferedStream (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: namespace -> class. Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/utils/SkFrontBufferedStream.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkStream.h" 8 #include "SkTypes.h"
9 #include "SkTemplates.h" 9
10 class SkStream;
11 class SkStreamRewindable;
10 12
11 /** 13 /**
12 * Specialized stream that only buffers the first X bytes of a stream, 14 * Specialized stream that only buffers the first X bytes of a stream,
13 * where X is passed in by the user. Note that unlike some buffered 15 * where X is passed in by the user. Note that unlike some buffered
14 * stream APIs, once more than those bytes are read, no more buffering 16 * stream APIs, once more than those bytes are read, no more buffering
15 * is done. This stream is designed for a use case where the caller 17 * is done. This stream is designed for a use case where the caller
16 * knows that rewind will only be called from within X bytes (inclusive), 18 * knows that rewind will only be called from within X bytes (inclusive),
17 * and the wrapped stream is not necessarily able to rewind at all. 19 * and the wrapped stream is not necessarily able to rewind at all.
18 */ 20 */
19 class SkFrontBufferedStream : public SkStreamRewindable { 21 class SkFrontBufferedStream {
20 public: 22 public:
21 /** 23 /**
22 * Creates a new stream that wraps and buffers SkStream. 24 * Creates a new stream that wraps and buffers SkStream.
23 * @param stream SkStream to buffer. If NULL, NULL is returned. After 25 * @param stream SkStream to buffer. If NULL, NULL is returned. After
reed1 2013/11/12 17:41:02 Not sure the punctuation is correct in the 2nd/3rd
scroggo 2013/11/12 19:46:54 I don't see the punctuation error. "If NULL, NULL
24 * this call, unref stream and do not refer to it. 26 * this call, unref stream and do not refer to it.
25 * SkFrontBufferedStream is expected to be its only owner. 27 * SkFrontBufferedStream is expected to be its only owner.
26 * @param bufferSize Exact size of the buffer to be used. 28 * @param bufferSize Exact size of the buffer to be used.
27 * @return An SkStream that can buffer up to bufferSize. 29 * @return An SkStream that can buffer up to bufferSize.
28 */ 30 */
29 static SkStreamRewindable* Create(SkStream* stream, size_t bufferSize); 31 static SkStreamRewindable* Create(SkStream* stream, size_t bufferSize);
30
31 virtual size_t read(void* buffer, size_t size) SK_OVERRIDE;
32
33 virtual bool isAtEnd() const SK_OVERRIDE;
34
35 virtual bool rewind() SK_OVERRIDE;
36
37 virtual bool hasPosition() const SK_OVERRIDE { return true; }
38
39 virtual size_t getPosition() const SK_OVERRIDE { return fOffset; }
40
41 virtual bool hasLength() const SK_OVERRIDE;
42
43 virtual size_t getLength() const SK_OVERRIDE;
44
45 virtual SkStreamRewindable* duplicate() const SK_OVERRIDE { return NULL; }
46
47 private:
48 SkAutoTUnref<SkStream> fStream;
49 // Current offset into the stream. Always >= 0.
50 size_t fOffset;
51 // Amount that has been buffered by calls to read. Will always be less than
52 // fBufferSize.
53 size_t fBufferedSoFar;
54 // Total size of the buffer.
55 const size_t fBufferSize;
56 SkAutoTMalloc<char> fBuffer;
57
58 // Private. Use Create.
59 SkFrontBufferedStream(SkStream*, size_t bufferSize);
60
61 // Read up to size bytes from already buffered data, and copy to
62 // dst, if non-NULL. Updates fOffset. Assumes that fOffset is less
63 // than fBufferedSoFar.
64 size_t readFromBuffer(char* dst, size_t size);
65
66 // Buffer up to size bytes from the stream, and copy to dst if non-
67 // NULL. Updates fOffset and fBufferedSoFar. Assumes that fOffset is
68 // less than fBufferedSoFar, and size is greater than 0.
69 size_t bufferAndWriteTo(char* dst, size_t size);
70
71 // Read up to size bytes directly from the stream and into dst if non-
72 // NULL. Updates fOffset. Assumes fOffset is at or beyond the buffered
73 // data, and size is greater than 0.
74 size_t readDirectlyFromStream(char* dst, size_t size);
75
76 typedef SkStream INHERITED;
77 }; 32 };
OLDNEW
« no previous file with comments | « no previous file | src/utils/SkFrontBufferedStream.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698