Module: Essential Tools Module Group: Traditional Collection Classes
Does not inherit
#include <rw/tpvector.h> RWTPtrVector<T> vec;
Class RWTPtrVector<T> is a simple parameterized vector of pointers to objects of type T. It is most useful when you know precisely how many pointers must be held in the collection. If the intention is to "insert" an unknown number of objects into a collection, then class RWTPtrOrderedVector<T,A> may be a better choice. The class T can be of any type.
Isomorphic
\\ \\ tpvector.cpp \\ #include <iostream> #include <rw/tpvector.h> #include <rw/tools/datetime.h> int main () { RWTPtrVector<RWDateTime> week(7); RWDateTime begin(RWDateTime::setCurrentTime); // Today's date for (size_t i = 0; i < 7; ++i) { week[i] = new RWDateTime(begin); begin.incrementDay(1); } for (size_t i = 0; i < 7; ++i) { std::cout << week[i]->asString('x') << std::endl; delete week[i]; } return 0; }
Program output (if run on June 18, 2009):
06/18/09 06/19/09 06/20/09 06/21/09 06/22/09 06/23/09 06/24/09
RWTPtrVector<T>();
Constructs an empty vector of length zero.
RWTPtrVector<T>(size_t n);
Constructs a vector of length n. The initial values of the elements are undefined. Hence, they can (and probably will) be garbage.
RWTPtrVector<T>(size_t n, T* ival);
Constructs a vector of length n, with each element pointing to the item *ival.
RWTPtrVector<T>(const RWTPtrVector& v);
Constructs self as a shallow copy of v. After construction, pointers held by the two vectors point to the same items.
RWTPtrVector<T>& operator=(const RWTPtrVector<T>& v);
Sets self to a shallow copy of v. Afterwards, the two vectors will have the same length, and pointers held by the two vectors will point to the same items.
RWTPtrVector<T>& operator=(T* p);
Sets all elements in self to point to the item *p.
T*& operator()(size_t i); T* operator()(size_t i) const;
Returns the ith value in the vector. The first variant can be used as an l-value, the second cannot. The index i must be between zero and the length of the vector, less one. No bounds checking is performed.
T*& operator[](size_t i); T* operator[](size_t i) const;
Returns the ith value in the vector. The first variant can be used as an lvalue, the second cannot. The index i must be between zero and the length of the vector, less one; or an exception of type RWBoundsErr will be thrown.
T* const * data() const;
Returns a pointer to the raw data of the vector. Should be used with care.
size_t length() const;
Returns the length of the vector.
void reshape(size_t N);
Changes the length of the vector to N. If this results in the vector being lengthened, then the initial value of the additional elements is undefined.
void resize(size_t N);
Changes the length of the vector to N. If this results in the vector being lengthened, then the initial value of the additional elements is set to nil.
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.