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

Side by Side Diff: include/ots-memory-stream.h

Issue 6410047: OTS: Adds more layout common table supports.... (Closed) Base URL: http://ots.googlecode.com/svn/trunk/
Patch Set: '' Created 9 years, 10 months 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/gdef.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef OTS_MEMORY_STREAM_H_ 5 #ifndef OTS_MEMORY_STREAM_H_
6 #define OTS_MEMORY_STREAM_H_ 6 #define OTS_MEMORY_STREAM_H_
7 7
8 #include <cstring> 8 #include <cstring>
9 #include <limits> 9 #include <limits>
10 10
11 #include "opentype-sanitiser.h" 11 #include "opentype-sanitiser.h"
12 12
13 namespace ots { 13 namespace ots {
14 14
15 class MemoryStream : public OTSStream { 15 class MemoryStream : public OTSStream {
16 public: 16 public:
17 MemoryStream(void *ptr, size_t length) 17 MemoryStream(void *ptr, size_t length)
18 : ptr_(ptr), length_(length), off_(0) { 18 : ptr_(ptr), length_(length), off_(0) {
19 } 19 }
20 20
21 bool WriteRaw(const void *data, size_t length) { 21 virtual bool WriteRaw(const void *data, size_t length) {
22 if ((off_ + length > length_) || 22 if ((off_ + length > length_) ||
23 (length > std::numeric_limits<size_t>::max() - off_)) { 23 (length > std::numeric_limits<size_t>::max() - off_)) {
24 return false; 24 return false;
25 } 25 }
26 std::memcpy(static_cast<char*>(ptr_) + off_, data, length); 26 std::memcpy(static_cast<char*>(ptr_) + off_, data, length);
27 off_ += length; 27 off_ += length;
28 return true; 28 return true;
29 } 29 }
30 30
31 bool Seek(off_t position) { 31 virtual bool Seek(off_t position) {
32 if (position < 0) return false; 32 if (position < 0) return false;
33 if (static_cast<size_t>(position) > length_) return false; 33 if (static_cast<size_t>(position) > length_) return false;
34 off_ = position; 34 off_ = position;
35 return true; 35 return true;
36 } 36 }
37 37
38 off_t Tell() const { 38 virtual off_t Tell() const {
39 return off_; 39 return off_;
40 } 40 }
41 41
42 private: 42 private:
43 void* const ptr_; 43 void* const ptr_;
44 size_t length_; 44 size_t length_;
45 off_t off_; 45 off_t off_;
46 }; 46 };
47 47
48 class ExpandingMemoryStream : public OTSStream { 48 class ExpandingMemoryStream : public OTSStream {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 private: 96 private:
97 void* ptr_; 97 void* ptr_;
98 size_t length_; 98 size_t length_;
99 const size_t limit_; 99 const size_t limit_;
100 off_t off_; 100 off_t off_;
101 }; 101 };
102 102
103 } // namespace ots 103 } // namespace ots
104 104
105 #endif // OTS_MEMORY_STREAM_H_ 105 #endif // OTS_MEMORY_STREAM_H_
OLDNEW
« no previous file with comments | « no previous file | src/gdef.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698