]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/llvm/tools/lldb/include/lldb/Core/StreamBuffer.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.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 <stdio.h>
14 #include <string>
15 #include "llvm/ADT/SmallVector.h"
16 #include "lldb/Core/Stream.h"
17
18 namespace lldb_private {
19
20 template <unsigned N>
21 class StreamBuffer : public Stream
22 {
23 public:
24     StreamBuffer () :
25         Stream (0, 4, lldb::eByteOrderBig),
26         m_packet ()
27     {
28     }
29
30
31     StreamBuffer (uint32_t flags,
32                   uint32_t addr_size,
33                   lldb::ByteOrder byte_order) :
34         Stream (flags, addr_size, byte_order),
35         m_packet ()
36     {
37     }
38
39     virtual
40     ~StreamBuffer ()
41     {
42     }
43
44     virtual void
45     Flush ()
46     {
47         // Nothing to do when flushing a buffer based stream...
48     }
49
50     virtual size_t
51     Write (const void *s, size_t length)
52     {
53         if (s && length)
54             m_packet.append ((const char *)s, ((const char *)s) + length);
55         return length;
56     }
57
58     void
59     Clear()
60     {
61         m_packet.clear();
62     }
63
64     // Beware, this might not be NULL terminated as you can expect from
65     // StringString as there may be random bits in the llvm::SmallVector. If
66     // you are using this class to create a C string, be sure the call PutChar ('\0')
67     // after you have created your string, or use StreamString.
68     const char *
69     GetData () const
70     {
71         return m_packet.data();
72     }
73
74     size_t
75     GetSize() const
76     {
77         return m_packet.size();
78     }
79
80 protected:
81     llvm::SmallVector<char, N> m_packet;
82
83 };
84
85 } // namespace lldb_private
86
87 #endif  // #ifndef liblldb_StreamBuffer_h_