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 : #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.
34 0 : virtual int32_t CopyTo(ByteArray* array) { return ByteArray::CopyTo(array); }
35 0 : virtual int32_t CopyTo(ByteArray* array, int32_t offset, int32_t length) {
36 0 : return ByteArray::CopyTo(array, offset, length);
37 : }
38 0 : virtual int32_t CopyTo(int32_t dst_offset,
39 : ByteArray* array,
40 : int32_t src_offset,
41 : int32_t length) {
42 0 : return ByteArray::CopyTo(dst_offset, array, src_offset, length);
43 : }
44 0 : 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_
|