Klang C++
Language Reference (draft)
Loading...
Searching...
No Matches
klang::Debug

The Klang debug interface. More...

#include <klang.h>

+ Inheritance diagram for klang::Debug:

Classes

struct  Buffer
 Audio buffer for debug output. More...
 

Public Member Functions

void print (const char *format,...)
 
void printOnce (const char *format,...)
 
bool hasText () const
 
int getText (char *buffer)
 
 operator const signal & () const
 
void input () override
 
virtual const signalinput () const
 
virtual void input (const signal &source)
 
virtual void operator<< (const signal &source)
 

Static Public Member Functions

template<typename Func , typename... Args>
static double profile (Func func, Args... args)
 
template<typename Func , typename... Args>
static double profile (int times, Func func, Args... args)
 

Public Attributes

Console console
 Debug console output.
 
signal in
 

Static Public Attributes

static THREAD_LOCAL Buffer buffer
 

Detailed Description

Definition at line 2230 of file klang.h.

Member Function Documentation

◆ getText()

int klang::Debug::getText ( char * buffer)
inline

Definition at line 2374 of file klang.h.

2374 {
2375 return console.getText(buffer);
2376 }
int getText(char *buffer)
Definition klang.h:2214
Console console
Debug console output.
Definition klang.h:2297
static THREAD_LOCAL Buffer buffer
Definition klang.h:2294

References console, and klang::Console::getText().

◆ hasText()

bool klang::Debug::hasText ( ) const
inline

Definition at line 2370 of file klang.h.

2370 {
2371 return console.hasText();
2372 }
bool hasText() const
Definition klang.h:2210

References console, and klang::Console::hasText().

◆ input() [1/3]

void klang::Debug::input ( )
inlineoverridevirtual

Reimplemented from klang::Generic::Input< signal >.

Definition at line 2383 of file klang.h.

2383 {
2384 buffer += in;
2385 }

References buffer, and klang::Debug::Buffer::operator+=().

◆ input() [2/3]

virtual const signal & klang::Generic::Input< signal >::input ( ) const
inlinevirtualinherited

Reimplemented in klang::Generic::Graph< SIZE >::Series.

Definition at line 1343 of file klang.h.

1343{ return in; }

◆ input() [3/3]

virtual void klang::Generic::Input< signal >::input ( const signal & source)
inlinevirtualinherited

Definition at line 1347 of file klang.h.

1347{ in = source; input(); }
virtual const signal & input() const
Definition klang.h:1343

◆ operator const signal &()

klang::Debug::operator const signal & ( ) const
inline

Definition at line 2378 of file klang.h.

2378 {
2379 return buffer.operator const klang::signal & ();
2380 }
A mono audio signal (equivalent to a float).
Definition klang.h:362

References buffer, and klang::Debug::Buffer::operator const signal &().

◆ operator<<()

virtual void klang::Generic::Input< signal >::operator<< ( const signal & source)
inlinevirtualinherited

Definition at line 1346 of file klang.h.

1346{ in = source; input(); }

◆ print()

void klang::Debug::print ( const char * format,
... )
inline

Definition at line 2344 of file klang.h.

2344 {
2345 if (console.length < 10000) {
2346 THREAD_LOCAL static char string[1024] = { 0 };
2347 string[0] = 0;
2348 va_list args; // Initialize the variadic argument list
2349 va_start(args, format); // Start variadic argument processing
2350 vsnprintf(string, 1024, format, args); // Safely format the string into the buffer
2351 va_end(args); // Clean up the variadic argument list
2352 console += string;
2353 }
2354 }

References console, klang::Console::length, and klang::Console::operator+=().

◆ printOnce()

void klang::Debug::printOnce ( const char * format,
... )
inline

Definition at line 2356 of file klang.h.

2356 {
2357 if (console.length < 1024) {
2358 THREAD_LOCAL static char string[1024] = { 0 };
2359 string[0] = 0;
2360 va_list args; // Initialize the variadic argument list
2361 va_start(args, format); // Start variadic argument processing
2362 vsnprintf(string, 1024, format, args); // Safely format the string into the buffer
2363 va_end(args); // Clean up the variadic argument list
2364
2365 if (console.last != string)
2366 console += string;
2367 }
2368 }
static THREAD_LOCAL Text< 16384 > last
Definition klang.h:2175

References console, klang::Console::last, klang::Console::length, klang::Text< SIZE >::operator!=(), and klang::Console::operator+=().

◆ profile() [1/2]

template<typename Func , typename... Args>
static double klang::Debug::profile ( Func func,
Args... args )
inlinestatic

Definition at line 2300 of file klang.h.

2300 {
2301 using namespace std::chrono;
2302
2303 auto start = high_resolution_clock::now();
2304 func(args...);
2305 auto end = high_resolution_clock::now();
2306
2307 auto duration = duration_cast<nanoseconds>(end - start).count();
2308 return (double)duration;
2309 }

◆ profile() [2/2]

template<typename Func , typename... Args>
static double klang::Debug::profile ( int times,
Func func,
Args... args )
inlinestatic

Definition at line 2312 of file klang.h.

2312 {
2313 double sum = 0;
2314 while (times--) {
2315 sum += profile(func, args...);
2316 }
2317 return sum / 1000000.0;
2318 }
static double profile(Func func, Args... args)
Definition klang.h:2300

Member Data Documentation

◆ buffer

THREAD_LOCAL Debug::Buffer klang::Debug::buffer
inlinestatic

◆ console

Console klang::Debug::console

Definition at line 2297 of file klang.h.

Referenced by getText(), hasText(), print(), and printOnce().

◆ in

Definition at line 1340 of file klang.h.

1340{ 0.f };