Public Member Functions | Protected Attributes | Private Member Functions | List of all members
QGStringBuffer Class Reference
Inheritance diagram for QGStringBuffer:
QIODevice

Public Member Functions

 QGStringBuffer (QGString *str)
 
 ~QGStringBuffer ()
 
bool open (int m)
 
void close ()
 
void flush ()
 
uint size () const
 
int at () const
 
bool at (int pos)
 
int readBlock (char *, uint)
 
int writeBlock (const char *p, uint len)
 
int getch ()
 
int putch (int ch)
 
int ungetch (int)
 
- Public Member Functions inherited from QIODevice
 QIODevice ()
 
virtual ~QIODevice ()
 
int flags () const
 
int mode () const
 
int state () const
 
bool isDirectAccess () const
 
bool isSequentialAccess () const
 
bool isCombinedAccess () const
 
bool isBuffered () const
 
bool isRaw () const
 
bool isSynchronous () const
 
bool isAsynchronous () const
 
bool isTranslated () const
 
bool isReadable () const
 
bool isWritable () const
 
bool isReadWrite () const
 
bool isInactive () const
 
bool isOpen () const
 
int status () const
 
void resetStatus ()
 
virtual bool atEnd () const
 
bool reset ()
 
virtual int readLine (char *data, uint maxlen)
 
int writeBlock (const QByteArray &data)
 
QByteArray readAll ()
 

Protected Attributes

QGStringm_str
 
- Protected Attributes inherited from QIODevice
int ioIndex
 

Private Member Functions

 QGStringBuffer (const QGStringBuffer &)
 
QGStringBufferoperator= (const QGStringBuffer &)
 

Additional Inherited Members

- Protected Member Functions inherited from QIODevice
void setFlags (int f)
 
void setType (int)
 
void setMode (int)
 
void setState (int)
 
void setStatus (int)
 

Detailed Description

Definition at line 6 of file ftextstream.cpp.

Constructor & Destructor Documentation

QGStringBuffer::QGStringBuffer ( QGString str)

Definition at line 31 of file ftextstream.cpp.

31  : m_str(str)
32 {
33  //printf("QGStringBuffer::QGStringBuffer(%p)\n",str);
34 }
QGString * m_str
Definition: ftextstream.cpp:24
QGStringBuffer::~QGStringBuffer ( )

Definition at line 36 of file ftextstream.cpp.

37 {
38 }
QGStringBuffer::QGStringBuffer ( const QGStringBuffer )
private

Member Function Documentation

int QGStringBuffer::at ( ) const
virtual

Virtual function that returns the current I/O device index.

This index is the data read/write head of the I/O device.

See also
size()

Reimplemented from QIODevice.

Definition at line 92 of file ftextstream.cpp.

93 {
94  return ioIndex;
95 }
int ioIndex
Definition: qiodevice.h:141
bool QGStringBuffer::at ( int  pos)
virtual

Virtual function that sets the I/O device index to pos.

See also
size()

Reimplemented from QIODevice.

Definition at line 97 of file ftextstream.cpp.

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 }
uint length() const
Definition: qgstring.h:40
const bool FALSE
Definition: qglobal.h:370
void qWarning(const char *msg,...)
Definition: qglobal.cpp:409
QGString * m_str
Definition: ftextstream.cpp:24
bool isOpen() const
Definition: qiodevice.h:110
unsigned uint
Definition: qglobal.h:351
const bool TRUE
Definition: qglobal.h:371
int ioIndex
Definition: qiodevice.h:141
void QGStringBuffer::close ( )
virtual

Closes the I/O device.

This virtual function must be reimplemented by all subclasses.

See also
open()

Implements QIODevice.

Definition at line 74 of file ftextstream.cpp.

75 {
76  if ( isOpen() )
77  {
79  ioIndex = 0;
80  }
81 }
void setFlags(int f)
Definition: qiodevice.h:136
#define IO_Direct
Definition: qiodevice.h:49
bool isOpen() const
Definition: qiodevice.h:110
int ioIndex
Definition: qiodevice.h:141
void QGStringBuffer::flush ( )
virtual

Flushes an open I/O device.

This virtual function must be reimplemented by all subclasses.

Implements QIODevice.

Definition at line 83 of file ftextstream.cpp.

84 {
85 }
int QGStringBuffer::getch ( )
inlinevirtual

Reads a single byte/character from the I/O device.

Returns the byte/character read, or -1 if the end of the I/O device has been reached.

This virtual function must be reimplemented by all subclasses.

See also
putch(), ungetch()

Implements QIODevice.

Definition at line 19 of file ftextstream.cpp.

19 { return -1; }
bool QGStringBuffer::open ( int  mode)
virtual

Opens the I/O device using the specified mode. Returns TRUE if successful, or FALSE if the device could not be opened.

The mode parameter m must be a combination of the following flags.

  • IO_Raw specified raw (unbuffered) file access.
  • IO_ReadOnly opens a file in read-only mode.
  • IO_WriteOnly opens a file in write-only mode.
  • IO_ReadWrite opens a file in read/write mode.
  • IO_Append sets the file index to the end of the file.
  • IO_Truncate truncates the file.
  • IO_Translate enables carriage returns and linefeed translation for text files under MS-DOS, Window, OS/2 and Macintosh. On Unix systems this flag has no effect. Use with caution as it will also transform every linefeed written to the file into a CRLF pair. This is likely to corrupt your file when writing binary data to it. Cannot be combined with IO_Raw.

This virtual function must be reimplemented by all subclasses.

See also
close()

Implements QIODevice.

Definition at line 40 of file ftextstream.cpp.

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 }
uint length() const
Definition: qgstring.h:40
const bool FALSE
Definition: qglobal.h:370
void qWarning(const char *msg,...)
Definition: qglobal.cpp:409
void setMode(int)
Definition: qiodevice.cpp:378
void setStatus(int)
Definition: qiodevice.cpp:408
bool truncate(uint pos)
Definition: qgstring.h:43
#define IO_Truncate
Definition: qiodevice.h:65
#define IO_Append
Definition: qiodevice.h:64
QGString * m_str
Definition: ftextstream.cpp:24
void setState(int)
Definition: qiodevice.cpp:393
bool isOpen() const
Definition: qiodevice.h:110
#define IO_Open
Definition: qiodevice.h:71
const bool TRUE
Definition: qglobal.h:371
int ioIndex
Definition: qiodevice.h:141
QGStringBuffer& QGStringBuffer::operator= ( const QGStringBuffer )
private
int QGStringBuffer::putch ( int  ch)
virtual

Writes the character ch to the I/O device.

Returns ch, or -1 if some error occurred.

This virtual function must be reimplemented by all subclasses.

See also
getch(), ungetch()

Implements QIODevice.

Definition at line 130 of file ftextstream.cpp.

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 }
char * data() const
Definition: qgstring.h:42
QGString * m_str
Definition: ftextstream.cpp:24
void setLen(uint newlen)
Definition: qgstring.cpp:156
bool enlarge(uint newlen)
Definition: qgstring.cpp:127
int ioIndex
Definition: qiodevice.h:141
int QGStringBuffer::readBlock ( char *  data,
uint  maxlen 
)
inlinevirtual

Reads at most maxlen bytes from the I/O device into data and returns the number of bytes actually read.

This virtual function must be reimplemented by all subclasses.

See also
writeBlock()

Implements QIODevice.

Definition at line 17 of file ftextstream.cpp.

17 { return -1; }
uint QGStringBuffer::size ( ) const
virtual

Virtual function that returns the size of the I/O device.

See also
at()

Implements QIODevice.

Definition at line 87 of file ftextstream.cpp.

88 {
89  return m_str ? m_str->length() : 0;
90 }
uint length() const
Definition: qgstring.h:40
QGString * m_str
Definition: ftextstream.cpp:24
int QGStringBuffer::ungetch ( int  ch)
inlinevirtual

Puts the character ch back into the I/O device and decrements the index if it is not zero.

This function is normally called to "undo" a getch() operation.

Returns ch, or -1 if some error occurred.

This virtual function must be reimplemented by all subclasses.

See also
getch(), putch()

Implements QIODevice.

Definition at line 21 of file ftextstream.cpp.

21 { return -1; }
int QGStringBuffer::writeBlock ( const char *  data,
uint  len 
)
virtual

Writes len bytes from p to the I/O device and returns the number of bytes actually written.

This virtual function must be reimplemented by all subclasses.

See also
readBlock()

Implements QIODevice.

Definition at line 118 of file ftextstream.cpp.

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 }
char * data() const
Definition: qgstring.h:42
p
Definition: test.py:223
QGString * m_str
Definition: ftextstream.cpp:24
void setLen(uint newlen)
Definition: qgstring.cpp:156
bool enlarge(uint newlen)
Definition: qgstring.cpp:127
int ioIndex
Definition: qiodevice.h:141

Member Data Documentation

QGString* QGStringBuffer::m_str
protected

Definition at line 24 of file ftextstream.cpp.


The documentation for this class was generated from the following file: