1 //===-- StreamBuffer.h ------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_StreamBuffer_h_
11 #define liblldb_StreamBuffer_h_
13 #include "lldb/Core/Stream.h"
14 #include "llvm/ADT/SmallVector.h"
18 namespace lldb_private {
20 template <unsigned N> class StreamBuffer : public Stream {
22 StreamBuffer() : Stream(0, 4, lldb::eByteOrderBig), m_packet() {}
24 StreamBuffer(uint32_t flags, uint32_t addr_size, lldb::ByteOrder byte_order)
25 : Stream(flags, addr_size, byte_order), m_packet() {}
27 virtual ~StreamBuffer() {}
29 virtual void Flush() {
30 // Nothing to do when flushing a buffer based stream...
33 virtual size_t Write(const void *s, size_t length) {
35 m_packet.append((const char *)s, ((const char *)s) + length);
39 void Clear() { m_packet.clear(); }
41 // Beware, this might not be NULL terminated as you can expect from
42 // StringString as there may be random bits in the llvm::SmallVector. If
43 // you are using this class to create a C string, be sure the call PutChar
45 // after you have created your string, or use StreamString.
46 const char *GetData() const { return m_packet.data(); }
48 size_t GetSize() const { return m_packet.size(); }
51 llvm::SmallVector<char, N> m_packet;
54 } // namespace lldb_private
56 #endif // #ifndef liblldb_StreamBuffer_h_