VR-Engage  2.3
Loading...
Searching...
No Matches
makVre::DtImGuiLogPrinter Class Reference

Detailed Description

All log text is stored in a single contiguous ImGuiTextBuffer with a parallel offset table that records where each line starts, its length, and its severity level. This design uses one heap allocation for all text (the ImGuiTextBuffer grows geometrically), avoids per-line std::string overhead, and makes oldest-line eviction O(1) by advancing a head index rather than shifting memory.

Attach an instance to one or more DtOutputStream objects (DtFatal, DtWarn, DtInfo, DtVerbose, DtDebug). Every write() call appends text to the buffer. Call drawContents() from an ImGui rendering pass to display the captured log with text search, severity filtering, auto-scroll, and color-coded lines.

Thread safety: write() may be called from any thread. draw methods must be called from the ImGui (main) thread only.

#include <debugLogPrinter.h>

Inheritance diagram for makVre::DtImGuiLogPrinter:
[legend]

Classes

struct  LineInfo
 

Public Member Functions

 DtImGuiLogPrinter (int maxLines=10000)
 
virtual ~DtImGuiLogPrinter ()
 
 DtImGuiLogPrinter (const DtImGuiLogPrinter &)=delete
 
DtImGuiLogPrinter & operator= (const DtImGuiLogPrinter &)=delete
 
virtual void write (const std::string &str, int notify_level, bool newLine) override
 
void drawContents ()
 
void drawDetachedWindow ()
 
void clear ()
 
void connectToAllStreams ()
 
void disconnectFromAllStreams ()
 
bool isConnected () const
 
bool isDetached () const
 
void setDetached (bool detached)
 

Private Member Functions

void drawToolbar ()
 
void drawLogRegion ()
 
void takeSnapshot ()
 
void commitPendingLine ()
 
void compactIfNeeded ()
 

Private Attributes

std::mutex myMutex
 
ImGuiTextBuffer myBuf
 
std::vector< LineInfo > myLines
 
int myHead
 
int myLineCount
 
std::string myPendingLine
 
int myPendingLevel
 
int myMaxLines
 
ImGuiTextFilter myFilter
 
bool myLevelVisible [5]
 
bool myAutoScroll
 
bool myDetached
 
bool myCopyMode
 
bool myConnected
 
std::vector< LineInfo > mySnapshot
 
std::string mySnapshotText
 
std::string myCopyText
 
bool myCopyTextDirty
 

Constructor & Destructor Documentation

◆ DtImGuiLogPrinter() [1/2]

makVre::DtImGuiLogPrinter::DtImGuiLogPrinter ( int maxLines = 10000)
explicit

Constructs the log printer.

Parameters
maxLinesMaximum number of lines to retain before discarding the oldest.

Referenced by DtImGuiLogPrinter(), and operator=().

◆ ~DtImGuiLogPrinter()

virtual makVre::DtImGuiLogPrinter::~DtImGuiLogPrinter ( )
virtual

Virtual destructor.

◆ DtImGuiLogPrinter() [2/2]

makVre::DtImGuiLogPrinter::DtImGuiLogPrinter ( const DtImGuiLogPrinter & )
delete

References DtImGuiLogPrinter().

Member Function Documentation

◆ operator=()

DtImGuiLogPrinter & makVre::DtImGuiLogPrinter::operator= ( const DtImGuiLogPrinter & )
delete

References DtImGuiLogPrinter().

◆ write()

virtual void makVre::DtImGuiLogPrinter::write ( const std::string & str,
int notify_level,
bool newLine )
overridevirtual

DtPrinter override — called by every DtOutputStream this printer is connected to.

Parameters
strThe text to log.
notify_levelSeverity (DtNlFatal … DtNlDebug).
newLineTrue when str begins a new logical line.

◆ drawContents()

void makVre::DtImGuiLogPrinter::drawContents ( )

Renders the log contents inside an existing ImGui window or tab.

Draws the toolbar (clear, auto-scroll, severity filters, copy-mode, detach button), search bar, and the scrollable log region.

◆ drawDetachedWindow()

void makVre::DtImGuiLogPrinter::drawDetachedWindow ( )

Renders the log in its own detached ImGui window.

Call this from a draw path that is independent of the debug menu visibility so the detached window stays open even when the main debug menu is hidden. If the user closes the window, the log automatically re-attaches to the inline view.

◆ clear()

void makVre::DtImGuiLogPrinter::clear ( )

Discards all stored log lines.

◆ connectToAllStreams()

void makVre::DtImGuiLogPrinter::connectToAllStreams ( )

Connects this printer to all five global DtOutputStream instances.

◆ disconnectFromAllStreams()

void makVre::DtImGuiLogPrinter::disconnectFromAllStreams ( )

Disconnects this printer from all five global DtOutputStream instances.

◆ isConnected()

bool makVre::DtImGuiLogPrinter::isConnected ( ) const

Returns true when the printer is attached to the output streams.

◆ isDetached()

bool makVre::DtImGuiLogPrinter::isDetached ( ) const

Returns true when the log is displayed in its own window.

◆ setDetached()

void makVre::DtImGuiLogPrinter::setDetached ( bool detached)

Sets whether the log is displayed in its own window.

◆ drawToolbar()

void makVre::DtImGuiLogPrinter::drawToolbar ( )
private

Builds the toolbar row (Clear, Auto-scroll, severity filters, Copy Mode, Detach).

◆ drawLogRegion()

void makVre::DtImGuiLogPrinter::drawLogRegion ( )
private

Builds the scrollable log region using the current snapshot.

◆ takeSnapshot()

void makVre::DtImGuiLogPrinter::takeSnapshot ( )
private

Takes a thread-safe snapshot of the line metadata and text into mySnapshot / mySnapshotText.

◆ commitPendingLine()

void makVre::DtImGuiLogPrinter::commitPendingLine ( )
private

Commits the pending partial line into the contiguous buffer.

◆ compactIfNeeded()

void makVre::DtImGuiLogPrinter::compactIfNeeded ( )
private

Compacts the buffer when the oldest lines have been evicted, reclaiming dead space at the front.

Member Data Documentation

◆ myMutex

std::mutex makVre::DtImGuiLogPrinter::myMutex
private

Guards all mutable state accessed by write() and draw().

◆ myBuf

ImGuiTextBuffer makVre::DtImGuiLogPrinter::myBuf
private

Single contiguous text buffer holding all log line text. Lines are null-terminated within the buffer so that c_str()-style pointers can be handed directly to ImGui::TextUnformatted().

◆ myLines

std::vector<LineInfo> makVre::DtImGuiLogPrinter::myLines
private

Offset table describing each line stored in myBuf. Used as a circular array: valid lines are indices [myHead, myHead + lineCount).

◆ myHead

int makVre::DtImGuiLogPrinter::myHead
private

Index of the oldest valid line in myLines (circular).

◆ myLineCount

int makVre::DtImGuiLogPrinter::myLineCount
private

Total number of valid lines currently stored.

◆ myPendingLine

std::string makVre::DtImGuiLogPrinter::myPendingLine
private

Partial line being accumulated before the next newLine==true write.

◆ myPendingLevel

int makVre::DtImGuiLogPrinter::myPendingLevel
private

Notify level for the pending partial line.

◆ myMaxLines

int makVre::DtImGuiLogPrinter::myMaxLines
private

Maximum retained line count.

◆ myFilter

ImGuiTextFilter makVre::DtImGuiLogPrinter::myFilter
private

ImGui text filter for search.

◆ myLevelVisible

bool makVre::DtImGuiLogPrinter::myLevelVisible[5]
private

Per-level visibility toggles (indexed by DtNotifyLevelType).

◆ myAutoScroll

bool makVre::DtImGuiLogPrinter::myAutoScroll
private

Whether to auto-scroll to the bottom on new output.

◆ myDetached

bool makVre::DtImGuiLogPrinter::myDetached
private

Whether the log is shown in its own detached ImGui window.

◆ myCopyMode

bool makVre::DtImGuiLogPrinter::myCopyMode
private

Whether copy-mode is active (read-only InputTextMultiline for selection).

◆ myConnected

bool makVre::DtImGuiLogPrinter::myConnected
private

Whether we are currently attached to the output streams.

◆ mySnapshot

std::vector<LineInfo> makVre::DtImGuiLogPrinter::mySnapshot
private

Frame-local snapshot of LineInfo, built by takeSnapshot().

◆ mySnapshotText

std::string makVre::DtImGuiLogPrinter::mySnapshotText
private

Frame-local snapshot of the text buffer, built by takeSnapshot().

◆ myCopyText

std::string makVre::DtImGuiLogPrinter::myCopyText
private

Cached flattened text for copy-mode InputTextMultiline.

◆ myCopyTextDirty

bool makVre::DtImGuiLogPrinter::myCopyTextDirty
private

True when myCopyText needs rebuilding (filter/severity/line count changed).


The documentation for this class was generated from the following file: