Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
doxygen-1.8.11
src
ftextstream.cpp
Go to the documentation of this file.
1
#include "
ftextstream.h
"
2
#include <
qfile.h
>
3
4
//----------------------------------------------------------------------------
5
6
class
QGStringBuffer
:
public
QIODevice
7
{
8
public
:
9
QGStringBuffer
(
QGString
*
str
);
10
~QGStringBuffer
();
11
bool
open
(
int
m
);
12
void
close
();
13
void
flush
();
14
uint
size
()
const
;
15
int
at
()
const
;
16
bool
at
(
int
pos
);
17
int
readBlock
(
char
*,
uint
) {
return
-1; }
18
int
writeBlock
(
const
char
*
p
,
uint
len );
19
int
getch
() {
return
-1; }
20
int
putch
(
int
ch );
21
int
ungetch
(
int
) {
return
-1; }
22
23
protected
:
24
QGString
*
m_str
;
25
26
private
:
// Disabled copy constructor and operator=
27
QGStringBuffer
(
const
QGStringBuffer
& );
28
QGStringBuffer
&
operator=
(
const
QGStringBuffer
& );
29
};
30
31
QGStringBuffer::QGStringBuffer
(
QGString
*
str
) :
m_str
(str)
32
{
33
//printf("QGStringBuffer::QGStringBuffer(%p)\n",str);
34
}
35
36
QGStringBuffer::~QGStringBuffer
()
37
{
38
}
39
40
bool
QGStringBuffer::open
(
int
m
)
41
{
42
if
( !
m_str
)
43
{
44
#if defined(CHECK_STATE)
45
qWarning
(
"QGStringBuffer::open: No string"
);
46
#endif
47
return
FALSE
;
48
}
49
if
(
isOpen
() )
50
{
// buffer already open
51
#if defined(CHECK_STATE)
52
qWarning
(
"QGStringBuffer::open: Buffer already open"
);
53
#endif
54
return
FALSE
;
55
}
56
setMode
( m );
57
if
( m &
IO_Truncate
)
58
{
// truncate buffer
59
m_str
->
truncate
( 0 );
60
}
61
if
( m &
IO_Append
)
62
{
// append to end of buffer
63
ioIndex
=
m_str
->
length
();
64
}
65
else
66
{
67
ioIndex
= 0;
68
}
69
setState
(
IO_Open
);
70
setStatus
( 0 );
71
return
TRUE
;
72
}
73
74
void
QGStringBuffer::close
()
75
{
76
if
(
isOpen
() )
77
{
78
setFlags
(
IO_Direct
);
79
ioIndex
= 0;
80
}
81
}
82
83
void
QGStringBuffer::flush
()
84
{
85
}
86
87
uint
QGStringBuffer::size
()
const
88
{
89
return
m_str
?
m_str
->
length
() : 0;
90
}
91
92
int
QGStringBuffer::at
()
const
93
{
94
return
ioIndex
;
95
}
96
97
bool
QGStringBuffer::at
(
int
pos
)
98
{
99
#if defined(CHECK_STATE)
100
if
( !
isOpen
() )
101
{
102
qWarning
(
"QGStringBuffer::at: Buffer is not open"
);
103
return
FALSE
;
104
}
105
#endif
106
if
( (
uint
)pos >=
m_str
->
length
() )
107
{
108
#if defined(CHECK_RANGE)
109
qWarning
(
"QGStringBuffer::at: Index %d out of range"
, pos );
110
#endif
111
return
FALSE
;
112
}
113
114
ioIndex
=
pos
;
115
return
TRUE
;
116
}
117
118
int
QGStringBuffer::writeBlock
(
const
char
*
p
,
uint
len )
119
{
120
//printf("QGStringBuffer::writeBlock(%p,%d) m_str=%p ioIndex=%d\n",p,len,
121
// m_str,ioIndex);
122
m_str
->
enlarge
(
ioIndex
+len+1);
123
memcpy(
m_str
->
data
()+
ioIndex
,
p
,len);
124
ioIndex
+=len;
125
m_str
->
data
()[
ioIndex
]=
'\0'
;
126
m_str
->
setLen
(ioIndex);
127
return
len;
128
}
129
130
int
QGStringBuffer::putch
(
int
ch )
131
{
132
//printf("QGStringBuffer::putch(%d) m_str=%p ioIndex=%d\n",
133
// ch,m_str,ioIndex);
134
m_str
->
enlarge
(
ioIndex
+2);
135
m_str
->
data
()[
ioIndex
] = (char)ch;
136
ioIndex
++;
137
m_str
->
data
()[
ioIndex
] =
'\0'
;
138
m_str
->
setLen
(
ioIndex
);
139
return
ch;
140
}
141
142
143
//----------------------------------------------------------------------------
144
145
FTextStream::FTextStream
()
146
{
147
m_dev = 0;
148
m_owndev =
FALSE
;
149
}
150
151
FTextStream::FTextStream
(
QIODevice
*dev )
152
{
153
m_dev = dev;
154
m_owndev =
FALSE
;
155
}
156
157
FTextStream::FTextStream
(
QGString
*
s
)
158
{
159
m_dev =
new
QGStringBuffer
(s);
160
((
QGStringBuffer
*)m_dev)->open(
IO_WriteOnly
);
161
m_owndev =
TRUE
;
162
}
163
164
FTextStream::FTextStream
( FILE *fh )
165
{
166
m_dev =
new
QFile
;
167
((
QFile
*)m_dev)->
open
(
IO_WriteOnly
, fh);
168
m_owndev =
TRUE
;
169
}
170
171
FTextStream::~FTextStream
()
172
{
173
if
(m_owndev)
delete
m_dev;
174
m_dev = 0;
175
}
176
177
QIODevice
*
FTextStream::device
()
const
178
{
179
return
m_dev;
180
}
181
182
void
FTextStream::setDevice
(
QIODevice
*dev )
183
{
184
if
(m_owndev)
185
{
186
delete
m_dev;
187
m_owndev =
FALSE
;
188
}
189
m_dev = dev;
190
}
191
192
void
FTextStream::unsetDevice
()
193
{
194
setDevice(0);
195
}
196
197
FTextStream
&
FTextStream::output_int
(
ulong
n
,
bool
neg )
198
{
199
char
buf[20];
200
char
*
p
= &buf[19];
201
*p =
'\0'
;
202
if
( neg )
203
{
204
n = (
ulong
)(-(
long
)
n
);
205
}
206
do
207
{
208
*--p = ((
int
)(n%10)) +
'0'
;
209
n /= 10;
210
}
while
( n );
211
if
( neg ) *--p =
'-'
;
212
return
operator<<
(p);
213
}
214
215
FTextStream
&
FTextStream::operator<<
(
signed
short
i )
216
{
217
return
output_int( i, i < 0 );
218
}
219
220
FTextStream
&
FTextStream::operator<<
(
unsigned
short
i )
221
{
222
return
output_int( i,
FALSE
);
223
}
224
225
FTextStream
&
FTextStream::operator<<
(
signed
int
i )
226
{
227
return
output_int( i, i < 0 );
228
}
229
230
FTextStream
&
FTextStream::operator<<
(
unsigned
int
i )
231
{
232
return
output_int( i,
FALSE
);
233
}
234
235
FTextStream
&
FTextStream::operator<<
(
signed
long
i )
236
{
237
return
output_int( i, i < 0 );
238
}
239
240
FTextStream
&
FTextStream::operator<<
(
unsigned
long
i )
241
{
242
return
output_int( i,
FALSE
);
243
}
244
245
FTextStream
&
FTextStream::operator<<
(
float
f
)
246
{
247
return
*
this
<< (double)f;
248
}
249
250
FTextStream
&
FTextStream::operator<<
(
double
d
)
251
{
252
char
buf[64];
253
sprintf(buf,
"%f"
,d);
254
return
*
this
<< buf;
255
}
256
257
258
259
260
QGStringBuffer::putch
int putch(int ch)
Definition:
ftextstream.cpp:130
QGStringBuffer::flush
void flush()
Definition:
ftextstream.cpp:83
QGString::data
char * data() const
Definition:
qgstring.h:42
keras_to_tensorflow.f
f
Definition:
keras_to_tensorflow.py:162
QGStringBuffer::close
void close()
Definition:
ftextstream.cpp:74
QGStringBuffer::readBlock
int readBlock(char *, uint)
Definition:
ftextstream.cpp:17
QGString::length
uint length() const
Definition:
qgstring.h:40
IO_WriteOnly
#define IO_WriteOnly
Definition:
qiodevice.h:62
QIODevice::setFlags
void setFlags(int f)
Definition:
qiodevice.h:136
QGStringBuffer::~QGStringBuffer
~QGStringBuffer()
Definition:
ftextstream.cpp:36
FTextStream::setDevice
void setDevice(QIODevice *)
Definition:
ftextstream.cpp:182
FALSE
const bool FALSE
Definition:
qglobal.h:370
bump_copyright.d
string d
Definition:
bump_copyright.py:70
qWarning
void qWarning(const char *msg,...)
Definition:
qglobal.cpp:409
QIODevice::setMode
void setMode(int)
Definition:
qiodevice.cpp:378
FTextStream
Simplified and optimized version of QTextStream.
Definition:
ftextstream.h:11
FTextStream::unsetDevice
void unsetDevice()
Definition:
ftextstream.cpp:192
QIODevice::setStatus
void setStatus(int)
Definition:
qiodevice.cpp:408
QGStringBuffer::getch
int getch()
Definition:
ftextstream.cpp:19
IO_Direct
#define IO_Direct
Definition:
qiodevice.h:49
FTextStream::operator<<
FTextStream & operator<<(char)
Definition:
ftextstream.h:49
QGString::truncate
bool truncate(uint pos)
Definition:
qgstring.h:43
QGStringBuffer::open
bool open(int m)
Definition:
ftextstream.cpp:40
cet::n
std::void_t< T > n
Definition:
metaprogramming.h:28
QFile::open
bool open(int)
Definition:
qfile_unix.cpp:134
FTextStream::FTextStream
FTextStream()
Definition:
ftextstream.cpp:145
QGStringBuffer::writeBlock
int writeBlock(const char *p, uint len)
Definition:
ftextstream.cpp:118
IO_Truncate
#define IO_Truncate
Definition:
qiodevice.h:65
ftextstream.h
ulong
unsigned long ulong
Definition:
qglobal.h:352
test.p
p
Definition:
test.py:223
IO_Append
#define IO_Append
Definition:
qiodevice.h:64
art::detail::operator<<
std::ostream & operator<<(std::ostream &os, Analyzer::Table< T > const &t)
Definition:
Analyzer.h:136
FTextStream::device
QIODevice * device() const
Definition:
ftextstream.cpp:177
QGStringBuffer::m_str
QGString * m_str
Definition:
ftextstream.cpp:24
QGStringBuffer::operator=
QGStringBuffer & operator=(const QGStringBuffer &)
keras_to_tensorflow.int
int
Definition:
keras_to_tensorflow.py:69
QGStringBuffer::ungetch
int ungetch(int)
Definition:
ftextstream.cpp:21
QFile
The QFile class is an I/O device that operates on files.
Definition:
qfile.h:50
cache_state.m
m
Definition:
cache_state.py:415
QIODevice::setState
void setState(int)
Definition:
qiodevice.cpp:393
MakeVectorFile.pos
tuple pos
Definition:
MakeVectorFile.py:68
QGStringBuffer::at
int at() const
Definition:
ftextstream.cpp:92
QGString
Definition:
qgstring.h:19
FTextStream::output_int
FTextStream & output_int(ulong n, bool neg)
Definition:
ftextstream.cpp:197
QGStringBuffer::QGStringBuffer
QGStringBuffer(QGString *str)
Definition:
ftextstream.cpp:31
QGString::setLen
void setLen(uint newlen)
Definition:
qgstring.cpp:156
QGString::enlarge
bool enlarge(uint newlen)
Definition:
qgstring.cpp:127
qfile.h
QGStringBuffer
Definition:
ftextstream.cpp:6
FTextStream::~FTextStream
virtual ~FTextStream()
Definition:
ftextstream.cpp:171
QIODevice
The QIODevice class is the base class of I/O devices.
Definition:
qiodevice.h:88
QIODevice::isOpen
bool isOpen() const
Definition:
qiodevice.h:110
uint
unsigned uint
Definition:
qglobal.h:351
IO_Open
#define IO_Open
Definition:
qiodevice.h:71
s
static QCString * s
Definition:
config.cpp:1042
TRUE
const bool TRUE
Definition:
qglobal.h:371
str
static QCString str
Definition:
fortrancode.cpp:27098
QGStringBuffer::size
uint size() const
Definition:
ftextstream.cpp:87
QIODevice::ioIndex
int ioIndex
Definition:
qiodevice.h:141
Generated by
1.8.11