QPtrVector(3qt)
QPtrVector π QPtrVector(3qt)
okay bestie, welcome to the 3qt manual page for QPtrVector, and honestly? she's a whole vibe. let's get into it π
β¨ NAME β¨
QPtrVector β a template collection class that provides a vector (array) π¦
β¨ SYNOPSIS β¨
#include <qptrvector.h>
Inherits QPtrCollection.
Public Members π
QPtrVector ()
QPtrVector ( uint size )
QPtrVector ( const QPtrVector<type> & v )
~QPtrVector ()
QPtrVector<type> & operator= ( const QPtrVector<type> & v )
bool operator== ( const QPtrVector<type> & v ) const
type ** data () const
uint size () const
virtual uint count () const
bool isEmpty () const
bool isNull () const
bool resize ( uint size )
bool insert ( uint i, const type * d )
bool remove ( uint i )
type * take ( uint i )
virtual void clear ()
bool fill ( const type * d, int size = -1 )
void sort ()
int bsearch ( const type * d ) const
int findRef ( const type * d, uint i = 0 ) const
int find ( const type * d, uint i = 0 ) const
uint containsRef ( const type * d ) const
uint contains ( const type * d ) const
type * operator[] ( int i ) const
type * at ( uint i ) const
Important Inherited Members π
bool autoDelete () const
void setAutoDelete ( bool enable )
Protected Members π«Ά
virtual int compareItems ( QPtrCollection::Item d1, QPtrCollection::Item
d2 )
virtual QDataStream & read ( QDataStream & s, QPtrCollection::Item &
item )
virtual QDataStream & write ( QDataStream & s, QPtrCollection::Item item
) const
β¨ DESCRIPTION β¨
so the QPtrVector class is a template collection class that provides a vector (array). that's the whole pitch, periodt. π
QValueVector is an STL-compatible alternative to this class. (noted, bestie π)
QPtrVector is implemented as a template class. Define a template instance QPtrVector<X> to create a vector that contains pointers to X (X*). πΈ
a vector is the same as an array, lowkey. 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. it's giving pointer energy, no cap. β¨
items 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(). easy. π
important bestie!! unless 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; seesetAutoDelete(). this behaviour can be changed in a subclass by reimplementing the virtual functiondeleteItem(). π«Ά
functions 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(). β
see also QMemArray and Non-GUI Classes. π
β¨ MEMBER FUNCTION DOCUMENTATION β¨ π
QPtrVector::QPtrVector ()
constructs a null vector. π«§
see also isNull().
QPtrVector::QPtrVector ( uint size )
constructs an vector with room for size items. makes a null vector if size == 0. π
all size positions in the vector are initialized to 0. β¨
see also size(), resize(), and isNull().
QPtrVector::QPtrVector ( const QPtrVector<type> & v )
constructs a copy of v. only the pointers are copied (i.e. shallow copy). it's giving surface-level, not deep π
QPtrVector::~QPtrVector ()
removes all items from the vector, and destroys the vector itself. π bye bestie
see also clear().
type * QPtrVector::at ( uint i ) const
returns the item at position i, or 0 if there is no item at that position. i must be less than size(). π
bool QPtrCollection::autoDelete () const
returns the setting of the auto-delete option. the default is FALSE. π«
see also setAutoDelete().
int QPtrVector::bsearch ( const type * d ) const
in a sorted array, finds the first occurrence of d using a binary search. for a sorted array, this is generally much faster than find(), which performs a linear search. speed, slay π₯
returns the position of d, or -1 if d could not be found. d must not be 0. π¨
compares items using the virtual function compareItems().
see also sort() and find().
void QPtrVector::clear () [virtual]
removes all items from the vector, and destroys the vector itself. π
the vector becomes a null vector.
see also isNull().
reimplemented from QPtrCollection.
int QPtrVector::compareItems ( QPtrCollection::Item d1, QPtrCollection::Item d2 ) [virtual protected]
this virtual function compares two list items. π
returns:
- zero if
d1 == d2 - nonzero if
d1 != d2
this function returns int rather than bool so that reimplementations can return one of three values and use it to sort by:
0ifd1 == d2> 0(positive integer) ifd1 > d2< 0(negative integer) ifd1 < d2
the sort() and bsearch() functions require compareItems() to be implemented as described here. no shortcuts, bestie π«Ά
heads up!! this function should not modify the vector because some const functions call compareItems(). do not touch, fr fr π
uint QPtrVector::contains ( const type * d ) const
returns the number of occurrences of item d in the vector. π’
compares items using the virtual function compareItems().
see also containsRef().
uint QPtrVector::containsRef ( const type * d ) const
returns the number of occurrences of the item pointer d in the vector.
this function does not use compareItems() to compare items. nope, we're going raw pointer here π
see also findRef().
uint QPtrVector::count () const [virtual]
returns the number of items in the vector. the vector is empty if count() == 0. π
see also isEmpty(), size(), and isNull().
reimplemented from QPtrCollection.
type ** QPtrVector::data () const
returns a pointer to the actual vector data, which is an array of type*. β¨
the vector is a null vector if data() == 0 (null pointer).
see also isNull().
bool QPtrVector::fill ( const type * d, int size = -1 )
inserts item d in all positions in the vector. any existing items are removed. if d is 0, the vector becomes empty. π¨
if size >= 0, the vector is first resized to size. by default, size is -1.
returns TRUE if successful, i.e. size is the same as the current size, or size is larger and the memory has successfully been allocated; otherwise returns FALSE. π
see also resize(), insert(), and isEmpty().
int QPtrVector::find ( const type * d, uint i = 0 ) const
finds the first occurrence of item d in the vector using a linear search. the search starts at position i, which must be less than size(). i is by default 0; i.e. the search starts at the start of the vector. π
returns the position of d, or -1 if d could not be found.
compares items using the virtual function compareItems().
use the much faster bsearch() to search a sorted vector. β‘
see also findRef() and bsearch().
int QPtrVector::findRef ( const type * d, uint i = 0 ) const
finds the first occurrence of the item pointer d in the vector using a linear search. the search starts at position i, which must be less than size(). i is by default 0; i.e. the search starts at the start of the vector. π
returns the position of d, or -1 if d could not be found.
this function does not use compareItems() to compare items.
use the much faster bsearch() to search a sorted vector. β‘
see also find() and bsearch().
bool QPtrVector::insert ( uint i, const type * d )
sets position i in the vector to contain the item d. i must be less than size(). any previous element in position i is removed. out with the old π
see also at().
bool QPtrVector::isEmpty () const
returns TRUE if the vector is empty; otherwise returns FALSE. π³οΈ
see also count().
bool QPtrVector::isNull () const
returns TRUE if the vector is null; otherwise returns FALSE.
a null vector has size() == 0 and data() == 0. π«§
see also size().
QPtrVector<type> & QPtrVector::operator= ( const QPtrVector<type> & v )
assigns v to this vector and returns a reference to this vector. π
this vector is first cleared and then all the items from v are copied into the vector. only the pointers are copied (i.e. shallow copy). again: shallow, bestie π«Ά
see also clear().
bool QPtrVector::operator== ( const QPtrVector<type> & v ) const
returns TRUE if this vector and v are equal; otherwise returns FALSE. β
type * QPtrVector::operator[] ( int i ) const
returns the item at position i, or 0 if there is no item at that position. i must be less than size(). π
equivalent to at( i ).
see also at().
QDataStream & QPtrVector::read ( QDataStream & s, QPtrCollection::Item & item ) [virtual protected]
reads a vector item, item, from the stream s and returns a reference to the stream. π
the default implementation sets item to 0.
see also write().
bool QPtrVector::remove ( uint i )
removes the item at position i in the vector, if there is one. i must be less than size(). ποΈ
returns TRUE if i is within range; otherwise returns FALSE.
see also take() and at().
bool QPtrVector::resize ( uint size )
resizes (expands or shrinks) the vector to size elements. the vector becomes a null vector if size == 0. π
any items at position size or beyond in the vector are removed. new positions are initialized to 0.
returns TRUE if successful, i.e. if the memory was successfully allocated; otherwise returns FALSE. π
see also size() and isNull().
void QPtrCollection::setAutoDelete ( bool enable )
sets the collection to auto-delete its contents if enable is TRUE and to never delete them if enable is FALSE. π
if 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. π
the 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. πβ οΈ
double delete alert!! fr fr be careful out here.
note 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.
see also autoDelete().
examples:
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. π’
the vector is a null vector if size() == 0.
see also isNull(), resize(), and count().
void QPtrVector::sort ()
sorts the items in ascending order. any empty positions will be put last. πβ¨
compares items using the virtual function compareItems().
see also bsearch().
okay that's part 1 bestie, don't go anywhere β more coming π
type * QPtrVector::take ( uint i )
Okay so take() is like at() but make it dramatic π
β it hands you the item sitting at position i, and then it snatches that item right out of the vector. Gone. Poof. β¨
i must be less than size(), bestie, no skipping that rule. And if there's genuinely no item at position i? You get 0 back. That's it, that's the whole vibe. π«Ά
Also important: unlikeremove(), this function does not calldeleteItem()for the removed item. So the item is yours now β nobody's cleaning up after it but you. π
See also remove() and at().
QDataStream & QPtrVector::write ( QDataStream & s, QPtrCollection::Item item ) const [virtual protected]
Writes a vector item, item, to the stream s, and returns a reference to that stream. Very demure, very streamy. π
The default implementation does literally nothing. Not a single thing. Iconic behaviour, honestly. π
See also read().
π SEE ALSO π
π COPYRIGHT π
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the license file included in the distribution for a complete license statement. πβ¨
π AUTHOR π
Generated automatically from the source code. Yes, the robots did this one, no cap. π€π
π BUGS π
If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports help us to help you. Thank you! π«Ά (fr fr, good reports are the whole love language here)
The definitive Qt documentation is provided in HTML format; it is located at $QTDIR/doc/html and can be read using Qt Assistant or with a web browser. This man page is provided as a convenience for those users who prefer man pages, although this format is not officially supported by Trolltech. π
If you find errors in this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qptrvector.3qt) and the Qt version (3.3.8). Bestie, don't forget those two, they need them to actually fix stuff. π
And that's a wrap on QPtrVector(3qt), babes! π
This lil' page came from Trolltech AS, dated 2 February 2007, and it documents Qt version 3.3.8. Go forth and manage your pointer vectors responsibly, you absolute icon. πΈβ¨
π¦ where this page comes from
- fedora 43: qt3-devel-docs 3.3.8b-102.fc43 Β· QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- fedora 44: qt3-devel-docs 3.3.8b-103.fc44 Β· QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- Copyright 1992-2007 Trolltech ASA. All rights reserved. See the
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms