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

Debug text output. More...

#include <klang.h>

+ Inheritance diagram for klang::Console:

Public Member Functions

void clear ()
 
Consoleoperator= (const char *in)
 
Consoleoperator= (const Console &in)
 
Consoleoperator+= (const char *in)
 
bool hasText () const
 
int getText (char *buffer)
 
int capacity () const
 Maximum size of the string.
 
 operator const char * () const
 Automatic cast to constant C-string.
 
const char * c_str () const
 Return constant C-string.
 
bool operator== (const char *in) const
 Returns true if Text matches the given C-string.
 
bool operator!= (const char *in) const
 Returns true if Text does not matches the given C-string.
 

Static Public Member Functions

static Text from (const char *in)
 Create a new Text object from a C-string.
 

Public Attributes

int length = 0
 
char string [SIZE+1]
 The character buffer.
 

Static Public Attributes

static std::mutex _lock
 
static THREAD_LOCAL Text< 16384 > last
 

Detailed Description

Definition at line 2173 of file klang.h.

Member Function Documentation

◆ c_str()

const char * klang::Text< SIZE >::c_str ( ) const
inlineinherited

Definition at line 328 of file klang.h.

328{ return string; }
char string[SIZE+1]
Definition klang.h:319

◆ capacity()

int klang::Text< SIZE >::capacity ( ) const
inlineinherited

Definition at line 322 of file klang.h.

322{ return SIZE; }

◆ clear()

void klang::Console::clear ( )
inline

Definition at line 2178 of file klang.h.

2178 {
2179 length = 0;
2180 string[0] = 0;
2181 }

References length.

Referenced by getText().

◆ from()

static Text klang::Text< SIZE >::from ( const char * in)
inlinestaticinherited

Definition at line 331 of file klang.h.

331 {
332 Text text;
333 text = in;
334 return text;
335 }

◆ getText()

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

Definition at line 2214 of file klang.h.

2214 {
2215 //if (!length) return 0;
2216 std::lock_guard<std::mutex> lock(_lock);
2217 const int _length = length;
2218 memcpy(buffer, string, length);
2219 buffer[length] = 0; // null terminator
2220 clear();
2221 return _length;
2222 }
void clear()
Definition klang.h:2178
static std::mutex _lock
Definition klang.h:2174

References _lock, clear(), and length.

Referenced by klang::Debug::getText().

◆ hasText()

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

Definition at line 2210 of file klang.h.

2210 {
2211 return length != 0;
2212 }

References length.

Referenced by klang::Debug::hasText().

◆ operator const char *()

klang::Text< SIZE >::operator const char * ( ) const
inlineinherited

Definition at line 325 of file klang.h.

325{ return string; }

◆ operator!=()

bool klang::Text< SIZE >::operator!= ( const char * in) const
inlineinherited

Definition at line 349 of file klang.h.

349 {
350 return !operator==(in);
351 }
bool operator==(const char *in) const
Definition klang.h:344

◆ operator+=()

Console & klang::Console::operator+= ( const char * in)
inline

Definition at line 2199 of file klang.h.

2199 {
2200 std::lock_guard<std::mutex> lock(_lock);
2201 const int len = std::max(0, std::min(capacity() - length, (int)strlen(in)));
2202 memcpy(&string[length], in, len);
2203 length += len;
2204 string[length] = 0;
2205 memcpy(&last, in, len);
2206 last.string[len] = 0;
2207 return *this;
2208 }
static THREAD_LOCAL Text< 16384 > last
Definition klang.h:2175
int capacity() const
Definition klang.h:322

References _lock, klang::Text< SIZE >::capacity(), last, and length.

Referenced by klang::Debug::print(), and klang::Debug::printOnce().

◆ operator=() [1/2]

Console & klang::Console::operator= ( const char * in)
inline

Definition at line 2183 of file klang.h.

2183 {
2184 std::lock_guard<std::mutex> lock(_lock);
2185 length = std::min(capacity(), (int)strlen(in));
2186 memcpy(string, in, length);
2187 string[length] = 0;
2188 return *this;
2189 }

References _lock, klang::Text< SIZE >::capacity(), and length.

◆ operator=() [2/2]

Console & klang::Console::operator= ( const Console & in)
inline

Definition at line 2191 of file klang.h.

2191 {
2192 std::lock_guard<std::mutex> lock(_lock);
2193 length = std::min(capacity(), in.length);
2194 memcpy(string, in.string, length);
2195 string[length] = 0;
2196 return *this;
2197 }

References _lock, klang::Text< SIZE >::capacity(), and length.

◆ operator==()

bool klang::Text< SIZE >::operator== ( const char * in) const
inlineinherited

Definition at line 344 of file klang.h.

344 {
345 return strcmp(string, in) == 0;
346 }

Member Data Documentation

◆ _lock

std::mutex klang::Console::_lock
inlinestatic

Definition at line 2174 of file klang.h.

Referenced by getText(), operator+=(), operator=(), and operator=().

◆ last

THREAD_LOCAL Text< 16384 > klang::Console::last
inlinestatic

Definition at line 2175 of file klang.h.

Referenced by operator+=(), and klang::Debug::printOnce().

◆ length

int klang::Console::length = 0

◆ string

char klang::Text< SIZE >::string[SIZE+1]
inherited

Definition at line 319 of file klang.h.

319{ 0 };