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 #ifndef SFNTLY_CPP_SRC_SFNTLY_DATA_GROWABLE_MEMORY_BYTE_ARRAY_H_
18 #define SFNTLY_CPP_SRC_SFNTLY_DATA_GROWABLE_MEMORY_BYTE_ARRAY_H_
19 
20 #include "sfntly/data/byte_array.h"
21 
22 namespace sfntly {
23 
24 // Note: This is not really a port of Java version. Instead, this wraps a
25 //       std::vector inside and let it grow by calling resize().
26 class GrowableMemoryByteArray : public ByteArray,
27                                 public RefCounted<GrowableMemoryByteArray> {
28  public:
29   GrowableMemoryByteArray();
30   virtual ~GrowableMemoryByteArray();
31   virtual int32_t CopyTo(OutputStream* os, int32_t offset, int32_t length);
32 
33   // Make gcc -Woverloaded-virtual happy.
CopyTo(ByteArray * array)34   virtual int32_t CopyTo(ByteArray* array) { return ByteArray::CopyTo(array); }
CopyTo(ByteArray * array,int32_t offset,int32_t length)35   virtual int32_t CopyTo(ByteArray* array, int32_t offset, int32_t length) {
36     return ByteArray::CopyTo(array, offset, length);
37   }
CopyTo(int32_t dst_offset,ByteArray * array,int32_t src_offset,int32_t length)38   virtual int32_t CopyTo(int32_t dst_offset,
39                          ByteArray* array,
40                          int32_t src_offset,
41                          int32_t length) {
42     return ByteArray::CopyTo(dst_offset, array, src_offset, length);
43   }
CopyTo(OutputStream * os)44   virtual int32_t CopyTo(OutputStream* os) { return ByteArray::CopyTo(os); }
45 
46  protected:
47   virtual void InternalPut(int32_t index, byte_t b);
48   virtual int32_t InternalPut(int32_t index,
49                               byte_t* b,
50                               int32_t offset,
51                               int32_t length);
52   virtual byte_t InternalGet(int32_t index);
53   virtual int32_t InternalGet(int32_t index,
54                               byte_t* b,
55                               int32_t offset,
56                               int32_t length);
57   virtual void Close();
58   virtual byte_t* Begin();
59 
60  private:
61   ByteVector b_;
62 };
63 
64 }  // namespace sfntly
65 
66 #endif  // SFNTLY_CPP_SRC_SFNTLY_DATA_GROWABLE_MEMORY_BYTE_ARRAY_H_
67