LightsprintSDK 2021.08.08
rr::RRReporter Class Referenceabstract

#include <RRDebug.h>

Inheritance diagram for rr::RRReporter:
rr::RRUniformlyAllocatedNonCopyable rr::RRUniformlyAllocated

Public Member Functions

virtual void customReport (RRReportType type, int indentation, const char *message)=0
 
 RRReporter ()
 
virtual ~RRReporter ()
 
- Public Member Functions inherited from rr::RRUniformlyAllocated
void * operator new (std::size_t n)
 
void * operator new[] (std::size_t n)
 
void operator delete (void *p, std::size_t n)
 
void operator delete[] (void *p, std::size_t n)
 

Static Public Member Functions

static void report (RRReportType type, const char *format,...)
 
static void reportV (RRReportType type, const char *format, va_list &vars)
 
static void indent (int delta)
 
static void assertionFailed (const char *expression, const char *func, const char *file, unsigned line)
 
static void setFilter (bool warnings=true, unsigned infLevel=2, bool timing=true)
 
static void getFilter (bool &warnings, unsigned &infLevel, bool &timing)
 
static RRReportercreateFileReporter (const char *filename, bool caching)
 
static RRReportercreatePrintfReporter ()
 
static RRReportercreateOutputDebugStringReporter ()
 
static RRReportercreateWindowedReporter (class RRSolver *&solver, const char *caption=nullptr, bool closeWhenDone=false)
 
static const char * bytesToString (size_t bytes)
 

Additional Inherited Members

- Protected Member Functions inherited from rr::RRUniformlyAllocatedNonCopyable
 RRUniformlyAllocatedNonCopyable ()
 
 ~RRUniformlyAllocatedNonCopyable ()
 

Detailed Description

Reporting messages.

When you or Lightsprint internals call static RRReporter::report(), message is passed to all existing reporters. At the beginning, there are no reporters, messages are lost. If you encounter problems, it could help to create reporter and check messages.

Thread safe: yes with exception, multiple threads may report at once, multiple threads may create/delete reporters at once, but you must not create/delete reporters and report at the same time (very unlikely case). All new implementations must be at least this thread safe too.

Constructor & Destructor Documentation

◆ RRReporter()

rr::RRReporter::RRReporter ( )

◆ ~RRReporter()

virtual rr::RRReporter::~RRReporter ( )
virtual

Member Function Documentation

◆ customReport()

virtual void rr::RRReporter::customReport ( RRReportType  type,
int  indentation,
const char *  message 
)
pure virtual

Generic report of message. The only function you implement in custom reporter.

It is usually called by Lightsprint internals with message for you.

Parameters
typeType of message.
indentationIndentation for structured messages. Submessages (e.g. messages from subtask) receive parent indentation + 1. Default indentation is 0. Current indentation is modified by indent().
messageMessage converted to plain text.

Thread safe: yes, correct implementation must be thread safe.

◆ report()

static void rr::RRReporter::report ( RRReportType  type,
const char *  format,
  ... 
)
static

Shortcut for customReport() with printf syntax: ls for wide strings, hs for singlebyte etc. Usually called by Lightsprint internals with message for you.

◆ reportV()

static void rr::RRReporter::reportV ( RRReportType  type,
const char *  format,
va_list &  vars 
)
static

Shortcut for customReport() with vprintf syntax.

◆ indent()

static void rr::RRReporter::indent ( int  delta)
static

Modifies indentation of future reports. +1 extends whitespace size, -1 reduces whitespace.

◆ assertionFailed()

static void rr::RRReporter::assertionFailed ( const char *  expression,
const char *  func,
const char *  file,
unsigned  line 
)
static

Shortcut for special type of message: assertion failure. Usually called by Lightsprint debug version internals. Assertion failures are not reported in release version.

◆ setFilter()

static void rr::RRReporter::setFilter ( bool  warnings = true,
unsigned  infLevel = 2,
bool  timing = true 
)
static

Sets filter for reported messages.

Parameters
warningsEnables processing of warning messages (WARN).
infLevelEnables processing of INFx messages for x<=infLevel. E.g. 1 enables only the most important INF1 messages, 2 enables also less important INF2 messages. It's good to set at least level 1, preferrably 2, because some error messages could make better sense in context of surrounding info messages.
timingEnables processing of timing messages (TIMI).

◆ getFilter()

static void rr::RRReporter::getFilter ( bool &  warnings,
unsigned &  infLevel,
bool &  timing 
)
static

Returns parameters passed to setFilter().

◆ createFileReporter()

static RRReporter * rr::RRReporter::createFileReporter ( const char *  filename,
bool  caching 
)
static

Creates reporter that logs all messages to plain text file. Optional caching makes writes faster but last messages may be lost when program crashes.

◆ createPrintfReporter()

static RRReporter * rr::RRReporter::createPrintfReporter ( )
static

Creates reporter that calls printf() on each message, with priority highlighting.

◆ createOutputDebugStringReporter()

static RRReporter * rr::RRReporter::createOutputDebugStringReporter ( )
static

Creates reporter that calls OutputDebugString() on each message.

◆ createWindowedReporter()

static RRReporter * rr::RRReporter::createWindowedReporter ( class RRSolver *&  solver,
const char *  caption = nullptr,
bool  closeWhenDone = false 
)
static

Creates reporter with its own window to display messages.

Supported only in Windows. If user tries to close the window manually, solver->aborting is set; it's cleared later in reporter destructor. Window is closed when both user attempts to close the window and you delete returned reporter. This means that window may exist even when you delete reporter.
Usage example:

// create window
// do any work here, it is logged to window, may be aborted
solver->updateLightmaps();
// you don't have to delete solver here, but if you do, do it safely, reporter still references solver.
// plain 'delete solver;' would make reporter destructor write to freed memory!
// leave window, set current reporter to nullptr. window passively exists until user closes it
delete reporter;
// here solver is no longer referenced (even if window may still exist)
Reporting messages.
Definition RRDebug.h:69
static RRReporter * createWindowedReporter(class RRSolver *&solver, const char *caption=nullptr, bool closeWhenDone=false)
Creates reporter with its own window to display messages.
void RR_SAFE_DELETE(C *&a)
Definition RRMemory.h:48
Parameters
solverPointer to solver. It may be nullptr or non-nullptr, you are free to change it at any moment, but restrictions exist:
  • The pointer must exist at least as long as the reporter, make sure that you don't pass local pointer that is going out of scope before you delete the reporter.
  • The pointer must be nullptr or point to valid solver, make sure that you nullptr it when you delete the solver.
captionOptional custom window caption, nullptr for default one.
closeWhenDoneCloses window immediately after reporting ends, rather than asking user what to do.

◆ bytesToString()

static const char * rr::RRReporter::bytesToString ( size_t  bytes)
static

Helper, converts number of bytes to human readable string, e.g. 12345678 to "12 MB".