1464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com/* 2464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com * Copyright 2011 Google Inc. All Rights Reserved. 3464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com * 4464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com * Licensed under the Apache License, Version 2.0 (the "License"); 5464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com * you may not use this file except in compliance with the License. 6464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com * You may obtain a copy of the License at 7464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com * 8464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com * http://www.apache.org/licenses/LICENSE-2.0 9464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com * 10464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com * Unless required by applicable law or agreed to in writing, software 11464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com * distributed under the License is distributed on an "AS IS" BASIS, 12464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com * See the License for the specific language governing permissions and 14464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com * limitations under the License. 15464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com */ 16464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com 175af34fd773f8cfee82321393504f558ddf67c628arthurhsu@google.com#ifndef SFNTLY_CPP_SRC_SFNTLY_DATA_GROWABLE_MEMORY_BYTE_ARRAY_H_ 185af34fd773f8cfee82321393504f558ddf67c628arthurhsu@google.com#define SFNTLY_CPP_SRC_SFNTLY_DATA_GROWABLE_MEMORY_BYTE_ARRAY_H_ 19464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com 20464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com#include "sfntly/data/byte_array.h" 21464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com 22464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.comnamespace sfntly { 23464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com 2432a01c7c6e7be46dda9bfc78de9ce32d99e4c8b7arthurhsu@google.com// Note: This is not really a port of Java version. Instead, this wraps a 2532a01c7c6e7be46dda9bfc78de9ce32d99e4c8b7arthurhsu@google.com// std::vector inside and let it grow by calling resize(). 26464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.comclass GrowableMemoryByteArray : public ByteArray, 27464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com public RefCounted<GrowableMemoryByteArray> { 28464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com public: 29464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com GrowableMemoryByteArray(); 30464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com virtual ~GrowableMemoryByteArray(); 3132a01c7c6e7be46dda9bfc78de9ce32d99e4c8b7arthurhsu@google.com virtual int32_t CopyTo(OutputStream* os, int32_t offset, int32_t length); 3232a01c7c6e7be46dda9bfc78de9ce32d99e4c8b7arthurhsu@google.com 3332a01c7c6e7be46dda9bfc78de9ce32d99e4c8b7arthurhsu@google.com // Make gcc -Woverloaded-virtual happy. 3432a01c7c6e7be46dda9bfc78de9ce32d99e4c8b7arthurhsu@google.com virtual int32_t CopyTo(ByteArray* array) { return ByteArray::CopyTo(array); } 3532a01c7c6e7be46dda9bfc78de9ce32d99e4c8b7arthurhsu@google.com virtual int32_t CopyTo(ByteArray* array, int32_t offset, int32_t length) { 3632a01c7c6e7be46dda9bfc78de9ce32d99e4c8b7arthurhsu@google.com return ByteArray::CopyTo(array, offset, length); 3732a01c7c6e7be46dda9bfc78de9ce32d99e4c8b7arthurhsu@google.com } 3832a01c7c6e7be46dda9bfc78de9ce32d99e4c8b7arthurhsu@google.com virtual int32_t CopyTo(int32_t dst_offset, 3932a01c7c6e7be46dda9bfc78de9ce32d99e4c8b7arthurhsu@google.com ByteArray* array, 4032a01c7c6e7be46dda9bfc78de9ce32d99e4c8b7arthurhsu@google.com int32_t src_offset, 4132a01c7c6e7be46dda9bfc78de9ce32d99e4c8b7arthurhsu@google.com int32_t length) { 4232a01c7c6e7be46dda9bfc78de9ce32d99e4c8b7arthurhsu@google.com return ByteArray::CopyTo(dst_offset, array, src_offset, length); 4332a01c7c6e7be46dda9bfc78de9ce32d99e4c8b7arthurhsu@google.com } 4432a01c7c6e7be46dda9bfc78de9ce32d99e4c8b7arthurhsu@google.com virtual int32_t CopyTo(OutputStream* os) { return ByteArray::CopyTo(os); } 45464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com 46464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com protected: 4732a01c7c6e7be46dda9bfc78de9ce32d99e4c8b7arthurhsu@google.com virtual void InternalPut(int32_t index, byte_t b); 48246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com virtual int32_t InternalPut(int32_t index, 4932a01c7c6e7be46dda9bfc78de9ce32d99e4c8b7arthurhsu@google.com byte_t* b, 50246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com int32_t offset, 51464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com int32_t length); 52246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com virtual byte_t InternalGet(int32_t index); 53246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com virtual int32_t InternalGet(int32_t index, 5432a01c7c6e7be46dda9bfc78de9ce32d99e4c8b7arthurhsu@google.com byte_t* b, 55246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com int32_t offset, 56464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com int32_t length); 57246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com virtual void Close(); 58246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com virtual byte_t* Begin(); 59464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com 60464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com private: 61464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com ByteVector b_; 62464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com}; 63464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com 64464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com} // namespace sfntly 65464987db923362e596195f9eebd34fc508c9a41arthurhsu@google.com 665af34fd773f8cfee82321393504f558ddf67c628arthurhsu@google.com#endif // SFNTLY_CPP_SRC_SFNTLY_DATA_GROWABLE_MEMORY_BYTE_ARRAY_H_ 67