The Q3PtrVector class is a template collection class that provides a vector (array). 更多...
| 头: | #include <Q3PtrVector> |
| 继承: | Q3PtrCollection |
| Q3PtrVector () | |
| Q3PtrVector (uint size ) | |
| Q3PtrVector (const Q3PtrVector<type> & v ) | |
| ~Q3PtrVector () | |
| type * | at (uint i ) const |
| int | bsearch (const type * d ) const |
| uint | contains (const type * d ) const |
| uint | containsRef (const type * d ) const |
| type ** | data () const |
| bool | fill (const type * d , int size = -1) |
| int | find (const type * d , uint i = 0) const |
| int | findRef (const type * d , uint i = 0) const |
| bool | insert (uint i , const type * d ) |
| bool | isEmpty () const |
| bool | isNull () const |
| bool | remove (uint i ) |
| bool | resize (uint size ) |
| uint | size () const |
| void | sort () |
| type * | take (uint i ) |
| Q3PtrVector<type> & | operator= (const Q3PtrVector<type> & v ) |
| bool | operator== (const Q3PtrVector<type> & v ) const |
| type * | operator[] (int i ) const |
| virtual void | clear () |
| virtual uint | count () const |
| virtual int | compareItems (Q3PtrCollection::Item d1 , Q3PtrCollection::Item d2 ) |
| virtual QDataStream & | read (QDataStream & s , Q3PtrCollection::Item & item ) |
| virtual QDataStream & | write (QDataStream & s , Q3PtrCollection::Item item ) const |
The Q3PtrVector class is a template collection class that provides a vector (array).
Q3ValueVector is an STL-compatible alternative to this class.
Q3PtrVector is implemented as a template class. Defines a template instance Q3PtrVector <X> to create a vector that contains pointers to X (X*).
A vector is the same as an array. The main difference between Q3PtrVector and Q3MemArray is that Q3PtrVector stores pointers to the elements, whereas Q3MemArray stores the elements themselves (i.e. Q3MemArray is value-based and Q3PtrVector is pointer-based).
Items are added to the vector using insert () 或 fill (). Items are removed with remove (). You can get a pointer to an item at a particular index position using at ().
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; see setAutoDelete (). This behavior can be changed in a subclass by reimplementing the virtual function deleteItem ().
Functions that compare items ( find () 和 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 () 或 containsRef ().
另请参阅 Q3MemArray .
Constructs a null vector.
另请参阅 isNull ().
Constructs an vector with room for size items. Makes a null vector if size == 0.
所有 size positions in the vector are initialized to 0.
另请参阅 size (), resize (),和 isNull ().
构造副本为 v . Only the pointers are copied (i.e. shallow copy).
Removes all items from the vector, and destroys the vector itself.
另请参阅 clear ().
Returns the item at position i , or 0 if there is no item at that position. i must be less than size ().
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.
Returns the position of d ,或 -1 若 d could not be found. d must not be 0.
Compares items using the virtual function compareItems ().
[虚拟]
void
Q3PtrVector::
clear
()
重实现自 Q3PtrCollection::clear ().
Removes all items from the vector, and destroys the vector itself.
The vector becomes a null vector.
另请参阅 isNull ().
[virtual protected]
int
Q3PtrVector::
compareItems
(
Q3PtrCollection::Item
d1
,
Q3PtrCollection::Item
d2
)
This virtual function compares two list items.
返回:
此函数返回 int 而不是 bool so that reimplementations can return one of three values and use it to sort by:
The sort () 和 bsearch () functions require compareItems() to be implemented as described here.
This function should not modify the vector because some const functions call compareItems().
Returns the number of occurrences of item d in the vector.
Compares items using the virtual function compareItems ().
另请参阅 containsRef ().
Returns the number of occurrences of the item pointer d in the vector.
此函数做 not 使用 compareItems () to compare items.
另请参阅 findRef ().
[虚拟]
uint
Q3PtrVector::
count
() const
重实现自 Q3PtrCollection::count ().
Returns the number of items in the vector. The vector is empty if count() == 0.
另请参阅 isEmpty (), size (),和 isNull ().
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).
另请参阅 isNull ().
Inserts item d in all positions in the vector. Any existing items are removed. If d is 0, the vector becomes empty.
若 size >= 0, the vector is first resized to size 。默认情况下, size 为 -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.
另请参阅 resize (), insert (),和 isEmpty ().
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 ,或 -1 若 d could not be found.
Compares items using the virtual function compareItems ().
Use the much faster bsearch () to search a sorted vector.
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 ,或 -1 若 d could not be found.
此函数做 not 使用 compareItems () to compare items.
Use the much faster bsearch () to search a sorted vector.
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.
返回 true 若 i is within range; otherwise returns false.
另请参阅 at ().
Returns true if the vector is empty; otherwise returns false.
另请参阅 count ().
Returns true if the vector is null; otherwise returns false.
A null vector has size () == 0 and data () == 0.
另请参阅 size ().
[virtual protected]
QDataStream
& Q3PtrVector::
read
(
QDataStream
&
s
,
Q3PtrCollection::Item
&
item
)
Reads a vector item, item , from the stream s 并返回流引用。
The default implementation sets item 为 0。
另请参阅 write ().
Removes the item at position i in the vector, if there is one. i must be less than size ().
返回 true 若 i is within range; otherwise returns false.
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.
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.
另请参阅 isNull (), resize (),和 count ().
Sorts the items in ascending order. Any empty positions will be put last.
Compares items using the virtual function compareItems ().
另请参阅 bsearch ().
Returns the item at position i in the vector, and removes that item from the vector. i must be less than size (). If there is no item at position i , 0 is returned.
不像 remove (), this function does not call deleteItem () for the removed item.
[virtual protected]
QDataStream
& Q3PtrVector::
write
(
QDataStream
&
s
,
Q3PtrCollection::Item
item
) const
Writes a vector item, item , to the stream s 并返回流引用。
默认实现什么都不做。
另请参阅 read ().
赋值 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).
另请参阅 clear ().
Returns true if this vector and v 相等;否则返回 false。
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 ).
另请参阅 at ().