MythTV  0.27pre
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
mmembuf.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
4 **
5 ** This file is part of the Qt3Support module of the Qt Toolkit.
6 **
7 ** This file may be used under the terms of the GNU General Public
8 ** License versions 2.0 or 3.0 as published by the Free Software
9 ** Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3
10 ** included in the packaging of this file. Alternatively you may (at
11 ** your option) use any later version of the GNU General Public
12 ** License if such license has been publicly approved by Trolltech ASA
13 ** (or its successors, if any) and the KDE Free Qt Foundation. In
14 ** addition, as a special exception, Trolltech gives you certain
15 ** additional rights. These rights are described in the Trolltech GPL
16 ** Exception version 1.2, which can be found at
17 ** http://www.trolltech.com/products/qt/gplexception/ and in the file
18 ** GPL_EXCEPTION.txt in this package.
19 **
20 ** Please review the following information to ensure GNU General
21 ** Public Licensing requirements will be met:
22 ** http://trolltech.com/products/qt/licenses/licensing/opensource/. If
23 ** you are unsure which license is appropriate for your use, please
24 ** review the following information:
25 ** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
26 ** or contact the sales department at sales@trolltech.com.
27 **
28 ** In addition, as a special exception, Trolltech, as the sole
29 ** copyright holder for Qt Designer, grants users of the Qt/Eclipse
30 ** Integration plug-in the right for the Qt/Eclipse Integration to
31 ** link to functionality provided by Qt Designer and its related
32 ** libraries.
33 **
34 ** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
35 ** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
36 ** A PARTICULAR PURPOSE. Trolltech reserves all rights not expressly
37 ** granted herein.
38 **
39 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
40 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
41 **
42 ****************************************************************************/
43 
44 #ifndef MMEMBUF_P_H
45 #define MMEMBUF_P_H
46 
47 //
48 // W A R N I N G
49 // -------------
50 //
51 // This file is not part of the Qt API. It exists for the convenience
52 // of a number of Qt sources files. This header file may change from
53 // version to version without notice, or even be removed.
54 //
55 // We mean it.
56 //
57 
58 #include <QByteArray>
59 #include <QList>
60 
61 class MMembuf
62 {
63 public:
64  MMembuf();
65  ~MMembuf();
66 
67  void append(QByteArray *ba);
68  void clear();
69 
70  bool consumeBytes(quint64 nbytes, char *sink);
71  QByteArray readAll();
72  bool scanNewline(QByteArray *store);
73  bool canReadLine() const;
74 
75  int ungetch(int ch);
76 
77  qint64 size() const;
78 
79 private:
80 
81  QList<QByteArray *> buf;
82  qint64 _size;
83  qint64 _index;
84 };
85 
86 inline void MMembuf::append(QByteArray *ba)
87 { buf.append(ba); _size += ba->size(); }
88 
89 inline void MMembuf::clear()
90 { qDeleteAll(buf); buf.clear(); _size=0; _index=0; }
91 
92 inline QByteArray MMembuf::readAll()
93 { QByteArray ba; ba.resize(_size); consumeBytes(_size,ba.data()); return ba; }
94 
95 inline bool MMembuf::canReadLine() const
96 { return const_cast<MMembuf*>(this)->scanNewline(0); }
97 
98 inline qint64 MMembuf::size() const
99 { return _size; }
100 
101 #endif // MMEMBUF_P_H