📄 qptrvector.3qt
字号:
'\" t.TH QPtrVector 3qt "9 December 2002" "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 NAMEQPtrVector \- Template collection class that provides a vector (array).SH SYNOPSIS\fC#include <qptrvector.h>\fR.PPInherits QPtrCollection..PP.SS "Public Members".in +1c.ti -1c.BI "\fBQPtrVector\fR ()".br.ti -1c.BI "\fBQPtrVector\fR ( uint size )".br.ti -1c.BI "\fBQPtrVector\fR ( const QPtrVector<type> & v )".br.ti -1c.BI "\fB~QPtrVector\fR ()".br.ti -1c.BI "QPtrVector<type> & \fBoperator=\fR ( const QPtrVector<type> & v )".br.ti -1c.BI "bool \fBoperator==\fR ( const QPtrVector<type> & v ) const".br.ti -1c.BI "type ** \fBdata\fR () const".br.ti -1c.BI "uint \fBsize\fR () const".br.ti -1c.BI "virtual 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 \fBinsert\fR ( uint i, const type * d )".br.ti -1c.BI "bool \fBremove\fR ( uint i )".br.ti -1c.BI "type * \fBtake\fR ( uint i )".br.ti -1c.BI "virtual void \fBclear\fR ()".br.ti -1c.BI "bool \fBfill\fR ( const type * d, int size = -1 )".br.ti -1c.BI "void \fBsort\fR ()".br.ti -1c.BI "int \fBbsearch\fR ( const type * d ) const".br.ti -1c.BI "int \fBfindRef\fR ( const type * d, uint i = 0 ) const".br.ti -1c.BI "int \fBfind\fR ( const type * d, uint i = 0 ) const".br.ti -1c.BI "uint \fBcontainsRef\fR ( const type * d ) const".br.ti -1c.BI "uint \fBcontains\fR ( const type * d ) const".br.ti -1c.BI "type * \fBoperator[]\fR ( int i ) const".br.ti -1c.BI "type * \fBat\fR ( uint i ) const".br.in -1c.SS "Important Inherited Members".in +1c.ti -1c.BI "bool \fBautoDelete\fR () const".br.ti -1c.BI "void \fBsetAutoDelete\fR ( bool enable )".br.in -1c.SS "Protected Members".in +1c.ti -1c.BI "virtual int \fBcompareItems\fR ( QPtrCollection::Item d1, QPtrCollection::Item d2 )".br.ti -1c.BI "virtual QDataStream & \fBread\fR ( QDataStream & s, QPtrCollection::Item & item )".br.ti -1c.BI "virtual QDataStream & \fBwrite\fR ( QDataStream & s, QPtrCollection::Item item ) const".br.in -1c.SH DESCRIPTIONThe QPtrVector class is a template collection class that provides a vector (array)..PPQValueVector is an STL-compatible alternative to this class..PPQPtrVector is implemented as a template class. Defines a template instance QPtrVector<X> to create a vector that contains pointers to X (X*)..PPA vector is the same as an array. The main difference between QPtrVector and QMemArray is that QPtrVector stores pointers to the elements, whereas QMemArray stores the elements themselves (i.e. QMemArray is value-based and QPtrVector is pointer-based)..PPItems are added to the vector using insert() or fill(). Items are removed with remove(). You can get a pointer to an item at a particular index position using at()..PPUnless otherwise stated, all functions that remove items from the vector will also delete the element pointed to if auto-deletion is enabled. By default, auto-deletion is disabled; see setAutoDelete(). This behaviour can be changed in a subclass by reimplementing the virtual function deleteItem()..PPFunctions that compare items (find() and sort() for example) will do so using the virtual function compareItems(). The default implementation of this function only compares the pointer values. Reimplement compareItems() in a subclass to get searching and sorting based on the item contents. You can perform a linear search for a pointer in the vector using findRef(), or a binary search (of a sorted vector) using bsearch(). You can count the number of times an item appears in the vector with contains() or containsRef()..PPSee also QMemArray and Non-GUI Classes..SH MEMBER FUNCTION DOCUMENTATION.SH "QPtrVector::QPtrVector ()"Constructs a null vector..PPSee also isNull()..SH "QPtrVector::QPtrVector ( uint size )"Constructs an vector with room for \fIsize\fR items. Makes a null vector if \fIsize\fR == 0..PPAll \fIsize\fR positions in the vector are initialized to 0..PPSee also size(), resize(), and isNull()..SH "QPtrVector::QPtrVector ( const QPtrVector<type> & v )"Constructs a copy of \fIv\fR. Only the pointers are copied (i.e. shallow copy)..SH "QPtrVector::~QPtrVector ()"Removes all items from the vector, and destroys the vector itself..PPSee also clear()..SH "type * QPtrVector::at ( uint i ) const"Returns the item at position \fIi\fR, or 0 if there is no item at that position. \fIi\fR must be less than size()..SH "bool QPtrCollection::autoDelete () const"Returns the setting of the auto-delete option. The default is FALSE..PPSee also setAutoDelete()..SH "int QPtrVector::bsearch ( const type * d ) const"In a sorted array, finds the first occurrence of \fId\fR using a binary search. For a sorted array, this is generally much faster than find(), which performs a linear search..PPReturns the position of \fId\fR, or -1 if \fId\fR could not be found. \fId\fR must not be 0..PPCompares items using the virtual function compareItems()..PPSee also sort() and find()..SH "void QPtrVector::clear ()\fC [virtual]\fR"Removes all items from the vector, and destroys the vector itself..PPThe vector becomes a null vector..PPSee also isNull()..PPReimplemented from QPtrCollection..SH "int QPtrVector::compareItems ( QPtrCollection::Item d1, QPtrCollection::Item d2 )\fC [virtual protected]\fR"This virtual function compares two list items..PPReturns:.TPzero if \fId1\fR == \fId2\fR.TPnonzero if \fId1\fR != \fId2\fR.PPThis function returns \fIint\fR rather than \fIbool\fR so that reimplementations can return one of three values and use it to sort by:.TP0 if \fId1\fR == \fId2\fR.TP> 0 (positive integer) if \fId1\fR > \fId2\fR.TP< 0 (negative integer) if \fId1\fR < \fId2\fR.PPThe sort() and bsearch() functions require compareItems() to be implemented as described here..PPThis function should not modify the vector because some const functions call compareItems()..SH "uint QPtrVector::contains ( const type * d ) const"Returns the number of occurrences of item \fId\fR in the vector..PPCompares items using the virtual function compareItems()..PPSee also containsRef()..SH "uint QPtrVector::containsRef ( const type * d ) const"Returns the number of occurrences of the item pointer \fId\fR in the vector..PPThis function does \fInot\fR use compareItems() to compare items..PPSee also findRef()..SH "uint QPtrVector::count () const\fC [virtual]\fR"Returns the number of items in the vector. The vector is empty if count() == 0..PPSee also isEmpty(), size(), and isNull()..PPReimplemented from QPtrCollection..SH "type ** QPtrVector::data () const"Returns a pointer to the actual vector data, which is an array of type*..PPThe vector is a null vector if data() == 0 (null pointer)..PPSee also isNull()..SH "bool QPtrVector::fill ( const type * d, int size = -1 )"Inserts item \fId\fR in all positions in the vector. Any existing items are removed. If \fId\fR is 0, the vector becomes empty..PPIf \fIsize\fR >= 0, the vector is first resized to \fIsize\fR. By default, \fIsize\fR is -1..PPReturns TRUE if successful, i.e. \fIsize\fR is the same as the current size, or \fIsize\fR is larger and the memory has successfully been allocated; otherwise returns FALSE..PPSee also resize(), insert(), and isEmpty()..SH "int QPtrVector::find ( const type * d, uint i = 0 ) const"Finds the first occurrence of item \fId\fR in the vector using a linear search. The search starts at position \fIi\fR, which must be less than size(). \fIi\fR is by default 0; i.e. the search starts at the start of the vector..PPReturns the position of \fId\fR, or -1 if \fId\fR could not be found..PPCompares items using the virtual function compareItems()..PPUse the much faster bsearch() to search a sorted vector..PPSee also findRef() and bsearch()..SH "int QPtrVector::findRef ( const type * d, uint i = 0 ) const"Finds the first occurrence of the item pointer \fId\fR in the vector using a linear search. The search starts at position \fIi\fR, which must be less than size(). \fIi\fR is by default 0; i.e. the search starts at the start of the vector..PPReturns the position of \fId\fR, or -1 if \fId\fR could not be found..PPThis function does \fInot\fR use compareItems() to compare items..PPUse the much faster bsearch() to search a sorted vector..PPSee also find() and bsearch()..SH "bool QPtrVector::insert ( uint i, const type * d )"Sets position \fIi\fR in the vector to contain the item \fId\fR. \fIi\fR must be less than size(). Any previous element in position \fIi\fR is removed..PPSee also at()..SH "bool QPtrVector::isEmpty () const"Returns TRUE if the vector is empty; otherwise returns FALSE..PPSee also count()..SH "bool QPtrVector::isNull () const"Returns TRUE if the vector is null; otherwise returns FALSE..PPA null vector has size() == 0 and data() == 0..PPSee also size()..SH "QPtrVector<type> & QPtrVector::operator= ( const QPtrVector<type> & v )"Assigns \fIv\fR to this vector and returns a reference to this vector..PPThis vector is first cleared and then all the items from \fIv\fR are copied into the vector. Only the pointers are copied (i.e. shallow copy)..PPSee also clear()..SH "bool QPtrVector::operator== ( const QPtrVector<type> & v ) const"Returns TRUE if this vector and \fIv\fR are equal; otherwise returns FALSE..SH "type * QPtrVector::operator[] ( int i ) const"Returns the item at position \fIi\fR, or 0 if there is no item at that position. \fIi\fR must be less than size()..PPEquivalent to at( \fIi\fR )..PPSee also at()..SH "QDataStream & QPtrVector::read ( QDataStream & s, QPtrCollection::Item & item )\fC [virtual protected]\fR"Reads a vector item, \fIitem\fR, from the stream \fIs\fR and returns a reference to the stream..PPThe default implementation sets \fIitem\fR to 0..PPSee also write()..SH "bool QPtrVector::remove ( uint i )"Removes the item at position \fIi\fR in the vector, if there is one. \fIi\fR must be less than size()..PPReturns TRUE if \fIi\fR is within range; otherwise returns FALSE..PPSee also take() and at()..SH "bool QPtrVector::resize ( uint size )"Resizes (expands or shrinks) the vector to \fIsize\fR elements. The vector becomes a null vector if \fIsize\fR == 0..PPAny items at position \fIsize\fR or beyond in the vector are removed. New positions are initialized to 0..PPReturns TRUE if successful, i.e. if the memory was successfully allocated; otherwise returns FALSE..PPSee also size() and isNull()..SH "void QPtrCollection::setAutoDelete ( bool enable )"Sets the collection to auto-delete its contents if \fIenable\fR is TRUE and to never delete them if \fIenable\fR is FALSE..PPIf auto-deleting is turned on, all the items in a collection are deleted when the collection itself is deleted. This is convenient if the collection has the only pointer to the items..PPThe default setting is FALSE, for safety. If you turn it on, be careful about copying the collection - you might find yourself with two collections deleting the same items..PPNote that the auto-delete setting may also affect other functions in subclasses. For example, a subclass that has a remove() function will remove the item from its data structure, and if auto-delete is enabled, will also delete the item..PPSee also autoDelete()..PPExamples:.)l scribble/scribble.cpp and table/bigtable/main.cpp..SH "uint QPtrVector::size () const"Returns the size of the vector, i.e. the number of vector positions. This is also the maximum number of items the vector can hold..PPThe vector is a null vector if size() == 0..PPSee also isNull(), resize(), and count()..SH "void QPtrVector::sort ()"Sorts the items in ascending order. Any empty positions will be put last..PPCompares items using the virtual function compareItems()..PPSee also bsearch()..SH "type * QPtrVector::take ( uint i )"Returns the item at position \fIi\fR in the vector, and removes that item from the vector. \fIi\fR must be less than size(). If there is no item at position \fIi\fR, 0 is returned..PPUnlike remove(), this function does \fInot\fR call deleteItem() for the removed item..PPSee also remove() and at()..SH "QDataStream & QPtrVector::write ( QDataStream & s, QPtrCollection::Item item ) const\fC [virtual protected]\fR"Writes a vector item, \fIitem\fR, to the stream \fIs\fR and returns a reference to the stream..PPThe default implementation does nothing..PPSee also read()..SH "SEE ALSO".BR http://doc.trolltech.com/qptrvector.html.BR http://www.trolltech.com/faq/tech.html.SH COPYRIGHTCopyright 1992-2001 Trolltech AS, http://www.trolltech.com. See thelicense file included in the distribution for a complete licensestatement..SH AUTHORGenerated automatically from the source code..SH BUGSIf you find a bug in Qt, please report it as described in.BR http://doc.trolltech.com/bughowto.html .Good bug reports help us to help you. Thank you..PThe definitive Qt documentation is provided in HTML format; it islocated at $QTDIR/doc/html and can be read using Qt Assistant or witha web browser. This man page is provided as a convenience for thoseusers who prefer man pages, although this format is not officiallysupported by Trolltech. .PIf you find errors in this manual page, please report them to.BR qt-bugs@trolltech.com .Please include the name of the manual page (qptrvector.3qt) and the Qtversion (3.1.1).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -