<commit_before>//===-- Stream.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_Stream_h_
#define liblldb_Stream_h_
#if defined(__cplusplus)

#include "lldb/lldb-private.h"
#include "lldb/Core/Flags.h"
#include <stdarg.h>

namespace lldb_private {

//----------------------------------------------------------------------
/// @class Stream Stream.h "lldb/Core/Stream.h"
/// @brief A stream class that can stream formatted output to a file.
//----------------------------------------------------------------------
class Stream
{
public:
    //------------------------------------------------------------------
    /// \a m_flags bit values.
    //------------------------------------------------------------------
    enum
    {
        eVerbose    = (1 << 0), ///< If set, verbose logging is enabled
        eDebug      = (1 << 1), ///< If set, debug logging is enabled
        eAddPrefix  = (1 << 2), ///< Add number prefixes for binary, octal and hex when eBinary is clear
        eBinary     = (1 << 3)  ///< Get and put data as binary instead of as the default string mode.
    };

    //------------------------------------------------------------------
    /// Construct with flags and address size and byte order.
    ///
    /// Construct with dump flags \a flags and the default address
    /// size. \a flags can be any of the above enumeration logical OR'ed
    /// together.
    //------------------------------------------------------------------
    Stream (uint32_t flags,
            uint32_t addr_size,
            lldb::ByteOrder byte_order);

    //------------------------------------------------------------------
    /// Construct a default Stream, not binary, host byte order and
    /// host addr size.
    ///
    //------------------------------------------------------------------
    Stream ();

    //------------------------------------------------------------------
    /// Destructor
    //------------------------------------------------------------------
    virtual
    ~Stream ();

    //------------------------------------------------------------------
    // Subclasses must override these methods
    //------------------------------------------------------------------

    //------------------------------------------------------------------
    /// Flush the stream.
    ///
    /// Subclasses should flush the stream to make any output appear
    /// if the stream has any buffering.
    //------------------------------------------------------------------
    virtual void
    Flush () = 0;

    //------------------------------------------------------------------
    /// Output character bytes to the stream.
    ///
    /// Appends \a src_len characters from the buffer \a src to the
    /// stream.
    ///
    /// @param[in] src
    ///     A buffer containing at least \a src_len bytes of data.
    ///
    /// @param[in] src_len
    ///     A number of bytes to append to the stream.
    ///
    /// @return
    ///     The number of bytes that were appended to the stream.
    //------------------------------------------------------------------
    virtual int
    Write (const void *src, size_t src_len) = 0;

    //------------------------------------------------------------------
    // Member functions
    //------------------------------------------------------------------
    int
    PutChar (char ch);

    //------------------------------------------------------------------
    /// Set the byte_order value.
    ///
    /// Sets the byte order of the data to extract. Extracted values
    /// will be swapped if necessary when decoding.
    ///
    /// @param[in] byte_order
    ///     The byte order value to use when extracting data.
    ///
    /// @return
    ///     The old byte order value.
    //------------------------------------------------------------------
    lldb::ByteOrder
    SetByteOrder (lldb::ByteOrder byte_order);

    //------------------------------------------------------------------
    /// Format a C string from a printf style format and variable
    /// arguments and encode and append the resulting C string as hex
    /// bytes.
    ///
    /// @param[in] format
    ///     A printf style format string.
    ///
    /// @param[in] ...
    ///     Any additional arguments needed for the printf format string.
    ///
    /// @return
    ///     The number of bytes that were appended to the stream.
    //------------------------------------------------------------------
    int
    PrintfAsRawHex8 (const char *format, ...)  __attribute__ ((format (printf, 2, 3)));

    //------------------------------------------------------------------
    /// Format a C string from a printf style format and variable
    /// arguments and encode and append the resulting C string as hex
    /// bytes.
    ///
    /// @param[in] format
    ///     A printf style format string.
    ///
    /// @param[in] ...
    ///     Any additional arguments needed for the printf format string.
    ///
    /// @return
    ///     The number of bytes that were appended to the stream.
    //------------------------------------------------------------------
    int
    PutHex8 (uint8_t uvalue);

    int
    PutNHex8 (size_t n, uint8_t uvalue);

    int
    PutHex16 (uint16_t uvalue,
              lldb::ByteOrder byte_order = lldb::eByteOrderInvalid);

    int
    PutHex32 (uint32_t uvalue,
              lldb::ByteOrder byte_order = lldb::eByteOrderInvalid);

    int
    PutHex64 (uint64_t uvalue,
              lldb::ByteOrder byte_order = lldb::eByteOrderInvalid);

    int
    PutMaxHex64 (uint64_t uvalue,
                 size_t byte_size,
                 lldb::ByteOrder byte_order = lldb::eByteOrderInvalid);
    int
    PutFloat (float f,
              lldb::ByteOrder byte_order = lldb::eByteOrderInvalid);

    int
    PutDouble (double d,
               lldb::ByteOrder byte_order = lldb::eByteOrderInvalid);

    int
    PutLongDouble (long double ld,
                   lldb::ByteOrder byte_order = lldb::eByteOrderInvalid);

    int
    PutPointer (void *ptr);

    // Append \a src_len bytes from \s to the stream as hex characters
    // (two ascii characters per byte of input data)
    int
    PutBytesAsRawHex8 (const void *src,
                       size_t src_len,
                       lldb::ByteOrder src_byte_order = lldb::eByteOrderInvalid,
                       lldb::ByteOrder dst_byte_order = lldb::eByteOrderInvalid);

    // Append \a src_len bytes from \s to the stream as binary data.
    int
    PutRawBytes (const void *s, 
                 size_t src_len,
                 lldb::ByteOrder src_byte_order = lldb::eByteOrderInvalid,
                 lldb::ByteOrder dst_byte_order = lldb::eByteOrderInvalid);

    int
    PutCStringAsRawHex8 (const char *s);

    //------------------------------------------------------------------
    /// Output a NULL terminated C string \a cstr to the stream \a s.
    ///
    /// @param[in] cstr
    ///     A NULL terminated C string.
    ///
    /// @return
    ///     A reference to this class so multiple things can be streamed
    ///     in one statement.
    //------------------------------------------------------------------
    Stream&
    operator<< (const char *cstr);

    //------------------------------------------------------------------
    /// Output a pointer value \a p to the stream \a s.
    ///
    /// @param[in] p
    ///     A void pointer.
    ///
    /// @return
    ///     A reference to this class so multiple things can be streamed<commit_msg>typeo fix in comment<commit_after>//===-- Stream.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_Stream_h_
#define liblldb_Stream_h_
#if defined(__cplusplus)

#include "lldb/lldb-private.h"
#include "lldb/Core/Flags.h"
#include <stdarg.h>

namespace lldb_private {

//----------------------------------------------------------------------
/// @class Stream Stream.h "lldb/Core/Stream.h"
/// @brief A stream class that can stream formatted output to a file.
//----------------------------------------------------------------------
class Stream
{
public:
    //------------------------------------------------------------------
    /// \a m_flags bit values.
    //------------------------------------------------------------------
    enum
    {
        eVerbose    = (1 << 0), ///< If set, verbose logging is enabled
        eDebug      = (1 << 1), ///< If set, debug logging is enabled
        eAddPrefix  = (1 << 2), ///< Add number prefixes for binary, octal and hex when eBinary is clear
        eBinary     = (1 << 3)  ///< Get and put data as binary instead of as the default string mode.
    };

    //------------------------------------------------------------------
    /// Construct with flags and address size and byte order.
    ///
    /// Construct with dump flags \a flags and the default address
    /// size. \a flags can be any of the above enumeration logical OR'ed
    /// together.
    //------------------------------------------------------------------
    Stream (uint32_t flags,
            uint32_t addr_size,
            lldb::ByteOrder byte_order);

    //------------------------------------------------------------------
    /// Construct a default Stream, not binary, host byte order and
    /// host addr size.
    ///
    //------------------------------------------------------------------
    Stream ();

    //------------------------------------------------------------------
    /// Destructor
    //------------------------------------------------------------------
    virtual
    ~Stream ();

    //------------------------------------------------------------------
    // Subclasses must override these methods
    //------------------------------------------------------------------

    //------------------------------------------------------------------
    /// Flush the stream.
    ///
    /// Subclasses should flush the stream to make any output appear
    /// if the stream has any buffering.
    //------------------------------------------------------------------
    virtual void
    Flush () = 0;

    //------------------------------------------------------------------
    /// Output character bytes to the stream.
    ///
    /// Appends \a src_len characters from the buffer \a src to the
    /// stream.
    ///
    /// @param[in] src
    ///     A buffer containing at least \a src_len bytes of data.
    ///
    /// @param[in] src_len
    ///     A number of bytes to append to the stream.
    ///
    /// @return
    ///     The number of bytes that were appended to the stream.
    //------------------------------------------------------------------
    virtual int
    Write (const void *src, size_t src_len) = 0;

    //------------------------------------------------------------------
    // Member functions
    //------------------------------------------------------------------
    int
    PutChar (char ch);

    //------------------------------------------------------------------
    /// Set the byte_order value.
    ///
    /// Sets the byte order of the data to extract. Extracted values
    /// will be swapped if necessary when decoding.
    ///
    /// @param[in] byte_order
    ///     The byte order value to use when extracting data.
    ///
    /// @return
    ///     The old byte order value.
    //------------------------------------------------------------------
    lldb::ByteOrder
    SetByteOrder (lldb::ByteOrder byte_order);

    //------------------------------------------------------------------
    /// Format a C string from a printf style format and variable
    /// arguments and encode and append the resulting C string as hex
    /// bytes.
    ///
    /// @param[in] format
    ///     A printf style format string.
    ///
    /// @param[in] ...
    ///     Any additional arguments needed for the printf format string.
    ///
    /// @return
    ///     The number of bytes that were appended to the stream.
    //------------------------------------------------------------------
    int
    PrintfAsRawHex8 (const char *format, ...)  __attribute__ ((format (printf, 2, 3)));

    //------------------------------------------------------------------
    /// Format a C string from a printf style format and variable
    /// arguments and encode and append the resulting C string as hex
    /// bytes.
    ///
    /// @param[in] format
    ///     A printf style format string.
    ///
    /// @param[in] ...
    ///     Any additional arguments needed for the printf format string.
    ///
    /// @return
    ///     The number of bytes that were appended to the stream.
    //------------------------------------------------------------------
    int
    PutHex8 (uint8_t uvalue);

    int
    PutNHex8 (size_t n, uint8_t uvalue);

    int
    PutHex16 (uint16_t uvalue,
              lldb::ByteOrder byte_order = lldb::eByteOrderInvalid);

    int
    PutHex32 (uint32_t uvalue,
              lldb::ByteOrder byte_order = lldb::eByteOrderInvalid);

    int
    PutHex64 (uint64_t uvalue,
              lldb::ByteOrder byte_order = lldb::eByteOrderInvalid);

    int
    PutMaxHex64 (uint64_t uvalue,
                 size_t byte_size,
                 lldb::ByteOrder byte_order = lldb::eByteOrderInvalid);
    int
    PutFloat (float f,
              lldb::ByteOrder byte_order = lldb::eByteOrderInvalid);

    int
    PutDouble (double d,
               lldb::ByteOrder byte_order = lldb::eByteOrderInvalid);

    int
    PutLongDouble (long double ld,
                   lldb::ByteOrder byte_order = lldb::eByteOrderInvalid);

    int
    PutPointer (void *ptr);

    // Append \a src_len bytes from \a s to the stream as hex characters
    // (two ascii characters per byte of input data)
    int
    PutBytesAsRawHex8 (const void *src,
                       size_t src_len,
                       lldb::ByteOrder src_byte_order = lldb::eByteOrderInvalid,
                       lldb::ByteOrder dst_byte_order = lldb::eByteOrderInvalid);

    // Append \a src_len bytes from \a s to the stream as binary data.
    int
    PutRawBytes (const void *s, 
                 size_t src_len,
                 lldb::ByteOrder src_byte_order = lldb::eByteOrderInvalid,
                 lldb::ByteOrder dst_byte_order = lldb::eByteOrderInvalid);

    int
    PutCStringAsRawHex8 (const char *s);

    //------------------------------------------------------------------
    /// Output a NULL terminated C string \a cstr to the stream \a s.
    ///
    /// @param[in] cstr
    ///     A NULL terminated C string.
    ///
    /// @return
    ///     A reference to this class so multiple things can be streamed
    ///     in one statement.
    //------------------------------------------------------------------
    Stream&
    operator<< (const char *cstr);

    //------------------------------------------------------------------
    /// Output a pointer value \a p to the stream \a s.
    ///
    /// @param[in] p
    ///     A void pointer.
    ///
    /// @return
    ///     A reference to this class so multiple things can be streamed
{'fraction_non_alphanumeric': 0.3306333312073474, 'fraction_numerical': 0.004974807066777218, 'mean_word_length': 0.9056878949927079, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2457246', 'n_tokens_mistral': 3693, 'n_tokens_neox': 3566, 'n_words': 1230}