Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:42:58

0001 //===-- StreamBuffer.h ------------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLDB_CORE_STREAMBUFFER_H
0010 #define LLDB_CORE_STREAMBUFFER_H
0011 
0012 #include "lldb/Utility/Stream.h"
0013 #include "llvm/ADT/SmallVector.h"
0014 #include <cstdio>
0015 #include <string>
0016 
0017 namespace lldb_private {
0018 
0019 template <unsigned N> class StreamBuffer : public Stream {
0020 public:
0021   StreamBuffer() : Stream(0, 4, lldb::eByteOrderBig), m_packet() {}
0022 
0023   StreamBuffer(uint32_t flags, uint32_t addr_size, lldb::ByteOrder byte_order)
0024       : Stream(flags, addr_size, byte_order), m_packet() {}
0025 
0026   ~StreamBuffer() override = default;
0027 
0028   void Flush() override {
0029     // Nothing to do when flushing a buffer based stream...
0030   }
0031 
0032   void Clear() { m_packet.clear(); }
0033 
0034   // Beware, this might not be NULL terminated as you can expect from
0035   // StringString as there may be random bits in the llvm::SmallVector. If you
0036   // are using this class to create a C string, be sure the call PutChar ('\0')
0037   // after you have created your string, or use StreamString.
0038   const char *GetData() const { return m_packet.data(); }
0039 
0040   size_t GetSize() const { return m_packet.size(); }
0041 
0042 protected:
0043   llvm::SmallVector<char, N> m_packet;
0044 
0045   size_t WriteImpl(const void *s, size_t length) override {
0046     if (s && length)
0047       m_packet.append((const char *)s, ((const char *)s) + length);
0048     return length;
0049   }
0050 };
0051 
0052 } // namespace lldb_private
0053 
0054 #endif // LLDB_CORE_STREAMBUFFER_H