Klang C++ 0.7.15
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 ()
 
Console & operator= (const char *in)
 
Console & operator= (const Console &in)
 
Console & operator+= (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 4209 of file klang.h.

Member Function Documentation

◆ c_str()

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

Definition at line 1089 of file klang.h.

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

◆ capacity()

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

Definition at line 1083 of file klang.h.

1083{ return SIZE; }

◆ clear()

void klang::Console::clear ( )
inline

Definition at line 4214 of file klang.h.

4214 {
4215 length = 0;
4216 string[0] = 0;
4217 }

◆ from()

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

Definition at line 1092 of file klang.h.

1092 {
1093 Text text;
1094 text = in;
1095 return text;
1096 }

◆ getText()

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

Definition at line 4250 of file klang.h.

4250 {
4251 //if (!length) return 0;
4252 std::lock_guard<std::mutex> lock(_lock);
4253 const int _length = length;
4254 memcpy(buffer, string, length);
4255 buffer[length] = 0; // null terminator
4256 clear();
4257 return _length;
4258 }
klang::interleaved::buffer< 2 > buffer
Definition klang.h:5999
void clear()
Definition klang.h:4214
static std::mutex _lock
Definition klang.h:4210

◆ hasText()

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

Definition at line 4246 of file klang.h.

4246 {
4247 return length != 0;
4248 }

◆ operator const char *()

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

Definition at line 1086 of file klang.h.

1086{ return string; }

◆ operator!=()

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

Definition at line 1110 of file klang.h.

1110 {
1111 return !operator==(in);
1112 }
bool operator==(const char *in) const
Definition klang.h:1105

◆ operator+=()

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

Definition at line 4235 of file klang.h.

4235 {
4236 std::lock_guard<std::mutex> lock(_lock);
4237 const int len = std::max(0, std::min(capacity() - length, (int)strlen(in)));
4238 memcpy(&string[length], in, len);
4239 length += len;
4240 string[length] = 0;
4241 memcpy(&last, in, len);
4242 last.string[len] = 0;
4243 return *this;
4244 }
static THREAD_LOCAL Text< 16384 > last
Definition klang.h:4211
int capacity() const
Definition klang.h:1083

◆ operator=() [1/2]

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

Definition at line 4219 of file klang.h.

4219 {
4220 std::lock_guard<std::mutex> lock(_lock);
4221 length = std::min(capacity(), (int)strlen(in));
4222 memcpy(string, in, length);
4223 string[length] = 0;
4224 return *this;
4225 }

◆ operator=() [2/2]

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

Definition at line 4227 of file klang.h.

4227 {
4228 std::lock_guard<std::mutex> lock(_lock);
4229 length = std::min(capacity(), in.length);
4230 memcpy(string, in.string, length);
4231 string[length] = 0;
4232 return *this;
4233 }

◆ operator==()

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

Definition at line 1105 of file klang.h.

1105 {
1106 return strcmp(string, in) == 0;
1107 }

Member Data Documentation

◆ _lock

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

Definition at line 4210 of file klang.h.

◆ last

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

Definition at line 4211 of file klang.h.

◆ length

int klang::Console::length = 0

Definition at line 4212 of file klang.h.

◆ string

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

Definition at line 1080 of file klang.h.

1080{ 0 };