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_PORT_MEMORY_OUTPUT_STREAM_H_ 18 #define SFNTLY_CPP_SRC_SFNTLY_PORT_MEMORY_OUTPUT_STREAM_H_ 19 20 #include <cstddef> 21 #include <vector> 22 23 #include "sfntly/port/type.h" 24 #include "sfntly/port/output_stream.h" 25 26 namespace sfntly { 27 28 // OutputStream backed by STL vector 29 30 class MemoryOutputStream : public OutputStream { 31 public: 32 MemoryOutputStream(); 33 virtual ~MemoryOutputStream(); 34 Close()35 virtual void Close() {} // no-op Flush()36 virtual void Flush() {} // no-op 37 virtual void Write(std::vector<uint8_t>* buffer); 38 virtual void Write(std::vector<uint8_t>* buffer, int32_t offset, int32_t length); 39 virtual void Write(uint8_t* buffer, int32_t offset, int32_t length); 40 virtual void Write(uint8_t b); 41 42 uint8_t* Get(); 43 size_t Size(); 44 45 private: 46 std::vector<uint8_t> store_; 47 }; 48 49 } // namespace sfntly 50 51 #endif // SFNTLY_CPP_SRC_SFNTLY_PORT_MEMORY_OUTPUT_STREAM_H_ 52