]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Core/StreamBuffer.h
MFV r316931: 6268 zfs diff confused by moving a file to another directory
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Core / StreamBuffer.h
1 //===-- StreamBuffer.h ------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef liblldb_StreamBuffer_h_
11 #define liblldb_StreamBuffer_h_
12
13 #include "lldb/Utility/Stream.h"
14 #include "llvm/ADT/SmallVector.h"
15 #include <stdio.h>
16 #include <string>
17
18 namespace lldb_private {
19
20 template <unsigned N> class StreamBuffer : public Stream {
21 public:
22   StreamBuffer() : Stream(0, 4, lldb::eByteOrderBig), m_packet() {}
23
24   StreamBuffer(uint32_t flags, uint32_t addr_size, lldb::ByteOrder byte_order)
25       : Stream(flags, addr_size, byte_order), m_packet() {}
26
27   virtual ~StreamBuffer() {}
28
29   virtual void Flush() {
30     // Nothing to do when flushing a buffer based stream...
31   }
32
33   virtual size_t Write(const void *s, size_t length) {
34     if (s && length)
35       m_packet.append((const char *)s, ((const char *)s) + length);
36     return length;
37   }
38
39   void Clear() { m_packet.clear(); }
40
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
44   // ('\0')
45   // after you have created your string, or use StreamString.
46   const char *GetData() const { return m_packet.data(); }
47
48   size_t GetSize() const { return m_packet.size(); }
49
50 protected:
51   llvm::SmallVector<char, N> m_packet;
52 };
53
54 } // namespace lldb_private
55
56 #endif // #ifndef liblldb_StreamBuffer_h_