Line data Source code
1 : /*
2 : * Copyright 2011 Google Inc. All Rights Reserved.
3 : *
4 : * Licensed under the Apache License, Version 2.0 (the "License");
5 : * you may not use this file except in compliance with the License.
6 : * You may obtain a copy of the License at
7 : *
8 : * http://www.apache.org/licenses/LICENSE-2.0
9 : *
10 : * Unless required by applicable law or agreed to in writing, software
11 : * distributed under the License is distributed on an "AS IS" BASIS,
12 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 : * See the License for the specific language governing permissions and
14 : * limitations under the License.
15 : */
16 :
17 : #include "sfntly/port/memory_output_stream.h"
18 :
19 : namespace sfntly {
20 :
21 0 : MemoryOutputStream::MemoryOutputStream() {
22 0 : }
23 :
24 0 : MemoryOutputStream::~MemoryOutputStream() {
25 0 : }
26 :
27 0 : void MemoryOutputStream::Write(ByteVector* buffer) {
28 0 : store_.insert(store_.end(), buffer->begin(), buffer->end());
29 0 : }
30 :
31 0 : void MemoryOutputStream::Write(ByteVector* buffer,
32 : int32_t offset,
33 : int32_t length) {
34 0 : assert(buffer);
35 0 : if (offset >= 0 && length > 0) {
36 0 : store_.insert(store_.end(),
37 0 : buffer->begin() + offset,
38 0 : buffer->begin() + offset + length);
39 : } else {
40 : #if !defined(SFNTLY_NO_EXCEPTION)
41 : throw IndexOutOfBoundException();
42 : #endif
43 : }
44 0 : }
45 :
46 0 : void MemoryOutputStream::Write(byte_t* buffer, int32_t offset, int32_t length) {
47 0 : assert(buffer);
48 0 : if (offset >= 0 && length > 0) {
49 0 : store_.insert(store_.end(), buffer + offset, buffer + offset + length);
50 : } else {
51 : #if !defined(SFNTLY_NO_EXCEPTION)
52 : throw IndexOutOfBoundException();
53 : #endif
54 : }
55 0 : }
56 :
57 0 : void MemoryOutputStream::Write(byte_t b) {
58 0 : store_.push_back(b);
59 0 : }
60 :
61 0 : byte_t* MemoryOutputStream::Get() {
62 0 : if (store_.empty()) {
63 0 : return NULL;
64 : }
65 0 : return &(store_[0]);
66 : }
67 :
68 0 : size_t MemoryOutputStream::Size() {
69 0 : return store_.size();
70 : }
71 :
72 : } // namespace sfntly
|