FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
daScript/include/daScript/misc/string_writer.h at master · PushoN/daScript · GitHub
PushoN
/
daScript
Public
forked from
GaijinEntertainment/daScript
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
daScript
/
include
/
daScript
/
misc
/
string_writer.h
Copy path
More file actions
More file actions
Latest commit
History
History
History
156 lines (135 loc) · 5.53 KB
Breadcrumbs
daScript
/
include
/
daScript
/
misc
/
string_writer.h
Copy path
File metadata and controls
156 lines (135 loc) · 5.53 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#
pragma
once
#
include
"
daScript/misc/platform.h
"
namespace
das
{
class
Context
;
struct
LineInfo
;
//
todo: support hex
struct
StringWriterTag
{
StringWriterTag
() =
default
;
StringWriterTag
(
const
StringWriterTag&) =
delete
;
StringWriterTag&
operator
=(
const
StringWriterTag&) =
delete
;
StringWriterTag
(StringWriterTag&&) =
delete
;
StringWriterTag&
operator
=(StringWriterTag&&) =
delete
;
};
DAS_API
extern
StringWriterTag
HEX
;
DAS_API
extern
StringWriterTag
DEC
;
DAS_API
extern
StringWriterTag
FIXEDFP
;
DAS_API
extern
StringWriterTag
SCIENTIFIC
;
class
DAS_API
StringWriter {
public:
virtual
~StringWriter
() {}
virtual
string
str
()
const
= 0;
virtual
uint64_t
tellp
()
const
= 0;
virtual
char
*
allocate
(
int
l) = 0;
virtual
void
append
(
const
char
* s,
int
l) = 0;
virtual
void
output
() = 0;
public:
template
<
typename
TT
> StringWriter &
format
(
const
char
* format,
TT
value);
StringWriter &
writeStr
(
const
char
* st,
size_t
len);
StringWriter &
writeChars
(
char
ch,
size_t
len);
StringWriter &
write
(
const
char
* stst);
StringWriter &
operator
<< (
const
StringWriterTag & v );
StringWriter &
operator
<< (
char
v);
StringWriter &
operator
<< (
unsigned
char
v);
StringWriter &
operator
<< (
bool
v);
StringWriter &
operator
<< (
int
v);
StringWriter &
operator
<< (
long
v);
StringWriter &
operator
<< (
long
long
v);
StringWriter &
operator
<< (
unsigned
v);
StringWriter &
operator
<< (
unsigned
long
v);
StringWriter &
operator
<< (
unsigned
long
long
v);
StringWriter &
operator
<< (
char
* v);
StringWriter &
operator
<< (
const
char
* v);
StringWriter &
operator
<< (
const
string & v);
StringWriter &
operator
<< (
float
v);
StringWriter &
operator
<< (
double
v);
protected:
bool
hex =
false
;
bool
fixed =
false
;
};
#
ifndef
DAS_SMALL_BUFFER_SIZE
#
define
DAS_SMALL_BUFFER_SIZE
4096
#
endif
class
DAS_API
FixedBufferTextWriter : public StringWriter {
public:
virtual
string
str
()
const
override
;
virtual
uint64_t
tellp
()
const
override
;
virtual
void
append
(
const
char
* s,
int
l)
override
;
virtual
char
*
allocate
(
int
l)
override
;
virtual
void
output
()
override
;
protected:
char
data[
DAS_SMALL_BUFFER_SIZE
];
int32_t
size =
0
;
};
#
ifndef
DAS_STRING_BUILDER_BUFFER_SIZE
#
define
DAS_STRING_BUILDER_BUFFER_SIZE
256
#
endif
class
DAS_API
TextWriter : public StringWriter {
public:
TextWriter
() {}
/*
* Copy and move constructors are not supported
* This helps prevent issues with `largeBuffer` ownership
* and keeps the code cleaner and simpler
*/
TextWriter
(
const
TextWriter&) =
delete
;
TextWriter
(TextWriter&&) =
delete
;
TextWriter&
operator
=(
const
TextWriter&) =
delete
;
TextWriter&
operator
=(TextWriter&&) =
delete
;
virtual
~TextWriter
();
virtual
string
str
()
const
override
;
virtual
uint64_t
tellp
()
const
override
;
bool
empty
()
const
;
char
*
c_str
();
char
*
data
();
void
clear
();
virtual
void
output
()
override
;
protected:
virtual
void
append
(
const
char
* s,
int
l)
override
;
virtual
char
*
allocate
(
int
l)
override
;
protected:
char
fixedBuffer[
DAS_STRING_BUILDER_BUFFER_SIZE
];
char
* largeBuffer = fixedBuffer;
int32_t
size =
0
;
int32_t
capacity =
DAS_STRING_BUILDER_BUFFER_SIZE
;
};
class
DAS_API
TextPrinter : public TextWriter {
public:
TextPrinter
() {}
virtual
void
output
()
override
;
protected:
uint64_t
pos =
0
;
static
mutex pmut;
};
enum
LogLevel {
//
CRITICAL - application can no longer perform its functions, or further execution will cause data corruption.
//
For example: array overrun, os_debug_break, assertion failure inside compiler.
critical =
50000
,
//
ERROR - Error events of considerable importance that will prevent normal program execution,
//
but might still allow the application to continue running.
//
For example: an error when opening a file, wrong settings for texture conversion, assertion failure in the script.
error =
40000
,
//
WARNING - the error is handled locally, something may cause unexpected behavior of the application.
//
For example: not all characters have been extracted from keystroke buffer, MSAA level was too high.
warning =
30000
,
//
INFO - highlight the progress of the application.
//
General system start/stop messages, device configuration information.
info =
20000
,
//
DEBUG - information useful for application developers. (DEBUG is defaut level)
debug =
10000
,
defaultPrint = debug,
//
TRACE - information useful for developers of subsystems, libraries, daslang etc.
//
For example: application activation/deactivation, key pressed, texture loaded from a file, sound file loaded.
trace =
0
,
};
const
char
*
getLogMarker
(
int
level);
class
DAS_API
LOG
: public TextWriter {
public:
LOG
(
int
level = LogLevel::debug ) : logLevel(level) {}
virtual
void
output
()
override
;
protected:
uint64_t
pos =
0
;
int
logLevel = LogLevel::debug;
bool
useMarker =
true
;
};
}
Back
|
FazBrowse Home
|
New Git URL