⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qmemarray.3qt

📁 linux下GUI编程工具qt的在线连接帮助手册
💻 3QT
📖 第 1 页 / 共 2 页
字号:
'\" t.TH QMemArray 3qt "11 October 2001" "Trolltech AS" \" -*- nroff -*-.\" Copyright 1992-2001 Trolltech AS.  All rights reserved.  See the.\" license file included in the distribution for a complete license.\" statement..\".ad l.nh.SH NAMEQMemArray \- Template class that provides arrays of simple types.PP\fC#include <qmemarray.h>\fR.PPInherited by QByteArray and QPointArray..PP.SS "Public Members".in +1c.ti -1c.BI "typedef type * \fBIterator\fR".br.ti -1c.BI "typedef const type * \fBConstIterator\fR".br.ti -1c.BI "\fBQMemArray\fR ()".br.ti -1c.BI "\fBQMemArray\fR ( int size )".br.ti -1c.BI "\fBQMemArray\fR ( const QMemArray<type> & a )".br.ti -1c.BI "\fB~QMemArray\fR ()".br.ti -1c.BI "QMemArray<type> & \fBoperator=\fR ( const QMemArray<type> & a )".br.ti -1c.BI "type * \fBdata\fR () const".br.ti -1c.BI "uint \fBnrefs\fR () const".br.ti -1c.BI "uint \fBsize\fR () const".br.ti -1c.BI "uint \fBcount\fR () const".br.ti -1c.BI "bool \fBisEmpty\fR () const".br.ti -1c.BI "bool \fBisNull\fR () const".br.ti -1c.BI "bool \fBresize\fR ( uint size )".br.ti -1c.BI "bool \fBtruncate\fR ( uint pos )".br.ti -1c.BI "bool \fBfill\fR ( const type & v, int size = -1 )".br.ti -1c.BI "virtual void \fBdetach\fR ()".br.ti -1c.BI "QMemArray<type> \fBcopy\fR () const".br.ti -1c.BI "QMemArray<type> & \fBassign\fR ( const QMemArray<type> & a )".br.ti -1c.BI "QMemArray<type> & \fBassign\fR ( const type * data, uint size )".br.ti -1c.BI "QMemArray<type> & \fBduplicate\fR ( const QMemArray<type> & a )".br.ti -1c.BI "QMemArray<type> & \fBduplicate\fR ( const type * data, uint size )".br.ti -1c.BI "QMemArray<type> & \fBsetRawData\fR ( const type * data, uint size )".br.ti -1c.BI "void \fBresetRawData\fR ( const type * data, uint size )".br.ti -1c.BI "int \fBfind\fR ( const type & v, uint index = 0 ) const".br.ti -1c.BI "int \fBcontains\fR ( const type & v ) const".br.ti -1c.BI "void \fBsort\fR ()".br.ti -1c.BI "int \fBbsearch\fR ( const type & v ) const".br.ti -1c.BI "type & \fBoperator[]\fR ( int index ) const".br.ti -1c.BI "type & \fBat\fR ( uint index ) const".br.ti -1c.BI "\fBoperator const type *\fR () const".br.ti -1c.BI "bool \fBoperator==\fR ( const QMemArray<type> & a ) const".br.ti -1c.BI "bool \fBoperator!=\fR ( const QMemArray<type> & a ) const".br.ti -1c.BI "Iterator \fBbegin\fR ()".br.ti -1c.BI "Iterator \fBend\fR ()".br.ti -1c.BI "ConstIterator \fBbegin\fR () const".br.ti -1c.BI "ConstIterator \fBend\fR () const".br.in -1c.SS "Protected Members".in +1c.ti -1c.BI "\fBQMemArray\fR ( int, int )".br.in -1c.SH RELATED FUNCTION DOCUMENTATION.in +1c.ti -1c.BI "Q_UINT16 \fBqChecksum\fR ( const char * data, uint len )".br.ti -1c.BI "QDataStream & \fBoperator<<\fR ( QDataStream & s, const QByteArray & a )".br.ti -1c.BI "QDataStream & \fBoperator>>\fR ( QDataStream & s, QByteArray & a )".br.in -1c.SH DESCRIPTIONThe QMemArray class is a template class that provides arrays of simple types..PPQMemArray is implemented as a template class. Define a template instance QMemArray<X> to create an array that contains X items..PPQMemArray stores the array elements directly in the array. It can deal only with simple types (i.e. C++ types, structs, and classes that have no constructors, destructors, or virtual functions). QMemArray uses bitwise operations to copy and compare array elements..PPThe QPtrVector collection class is also a kind of array. Like most collection classes, it has pointers to the contained items..PPQMemArray uses explicit sharing with a reference count. If more than one array share common data and one array is modified, all arrays will be modified..PPThe benefit of sharing is that a program does not need to duplicate data when it is not required, which results in less memory usage and less copying of data..PPExample:.PP.nf.br    #include <qmemarray.h>.br    #include <stdio.h>.br.br    QMemArray<int> fib( int num ) // returns fibonacci array.br    {.br        Q_ASSERT( num > 2 );.br        QMemArray<int> f( num ); // array of ints.br.br        f[0] = f[1] = 1;.br        for ( int i = 2; i < num; i++ ).br            f[i] = f[i-1] + f[i-2];.br.br        return f;.br    }.br.br    int main().br    {.br        QMemArray<int> a = fib( 6 ); // get 6 first fibonaccis.br        for ( int i = 0; i < a.size(); i++ ).br            qDebug( "%d: %d", i, a[i] );.br.br        qDebug( "1 is found %d times", a.contains(1) );.br        qDebug( "5 is found at index %d", a.find(5) );.br.br        return 0;.br    }.br.fi.PPProgram output:.PP.nf.br    0: 1.br    1: 1.br    2: 2.br    3: 3.br    4: 5.br    5: 8.br    1 is found 2 times.br    5 is found at index 4.br.fi.PPNote about using QMemArray for manipulating structs or classes: Compilers will often pad the size of structs of odd sizes up to the nearest word boundary. This will then be the size QMemArray will use for its bitwise element comparisons. Because the remaining bytes will typically be uninitialized, this can cause find() etc. to fail to find the element. Example:.PP.nf.br    // MyStruct may be padded to 4 or 8 bytes.br    struct MyStruct.br    {.br        short i; // 2 bytes.br        char c;  // 1 byte.br    };.br.br    QMemArray<MyStruct> a(1);.br    a[0].i = 5;.br    a[0].c = 't';.br.br    MyStruct x;.br    x.i = '5';.br    x.c = 't';.br    int i = a.find( x ); // may return -1 if the pad bytes differ.br.fi.PPTo work around this, make sure that you use a struct where sizeof() returns the same as the sum of the sizes of the members either by changing the types of the struct members or by adding dummy members..PPQMemArray data can be traversed by iterators (see begin() and end()). The number of items is returned by count(). The array can be resized with resize() and filled using fill()..PPYou can make a shallow copy of the array with assign() (or operator=()) and a deep copy with duplicate()..PPSearch for values in the array with find() and contains(). For sorted arrays (see sort()) you can search using bsearch()..PP

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -