aboutsummaryrefslogtreecommitdiff
path: root/include/lldb/Core/StreamBuffer.h
blob: 3b18573021b34cb58427b873c48fe49d7cb8d9bd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//===-- StreamBuffer.h ------------------------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef liblldb_StreamBuffer_h_
#define liblldb_StreamBuffer_h_

#include "lldb/Utility/Stream.h"
#include "llvm/ADT/SmallVector.h"
#include <stdio.h>
#include <string>

namespace lldb_private {

template <unsigned N> class StreamBuffer : public Stream {
public:
  StreamBuffer() : Stream(0, 4, lldb::eByteOrderBig), m_packet() {}

  StreamBuffer(uint32_t flags, uint32_t addr_size, lldb::ByteOrder byte_order)
      : Stream(flags, addr_size, byte_order), m_packet() {}

  virtual ~StreamBuffer() {}

  virtual void Flush() {
    // Nothing to do when flushing a buffer based stream...
  }

  virtual size_t Write(const void *s, size_t length) {
    if (s && length)
      m_packet.append((const char *)s, ((const char *)s) + length);
    return length;
  }

  void Clear() { m_packet.clear(); }

  // Beware, this might not be NULL terminated as you can expect from
  // StringString as there may be random bits in the llvm::SmallVector. If
  // you are using this class to create a C string, be sure the call PutChar
  // ('\0')
  // after you have created your string, or use StreamString.
  const char *GetData() const { return m_packet.data(); }

  size_t GetSize() const { return m_packet.size(); }

protected:
  llvm::SmallVector<char, N> m_packet;
};

} // namespace lldb_private

#endif // #ifndef liblldb_StreamBuffer_h_