Module: Essential Tools Module Group: Generic Classes
Does not inherit
#include <rw/gvector.h> declare(RWGVector,val) implement(RWGVector,val) RWGVector(val) a; // A Vector of val's.
Class RWGVector(val) represents a group of ordered elements, accessible by an index. Duplicates are allowed. This class is implemented as an array. Objects of type RWGVector(val) are declared with macros defined in the standard C++ header file <generic.h>.
NOTE -- RWGVector is deprecated. Please use RWTValVector or RWTPtrVector.
Note that it is a value-based collection: items are copied in and out of the collection.
The class val must have:
a default constructor;
well-defined copy semantics (val::val(const val&) or equivalent);
well-defined assignment semantics (val::operator=(const val&) or equivalent).
For each type of RWGVector, you must include one (and only one) call to the macro implement, somewhere in your code.
None
#include <iostream> #include <rw/gvector.h> #include <rw/tools/datetime.h> declare(RWGVector, RWDateTime) /* Declare a vector of RWDateTime objects */ implement(RWGVector, RWDateTime) /* Implement a vector of RWDateTime objects */ int main () { RWGVector(RWDateTime) oneWeek(7); for (size_t i = 0; i < 7; ++i) { oneWeek (i) = RWDateTime::now () + i*RWDateTime::millisecsInDay; } for (size_t i = 0; i < 7; ++i) { std::cout << oneWeek(i).asString('x') << std::endl; } 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
RWGVector(val)();
Construct an empty vector.
RWGVector(val)(size_t n);
Construct a vector with length n. The initial values of the elements can (and probably will) be garbage.
RWGVector(val)(size_t n, val v);
Construct a vector with length n. Each element is assigned the value v.
RWGVector(val)(RWGVector(val)& s);
Copy constructor. The entire vector is copied, including all embedded values.
RWGVector(val)& operator=(RWGVector(val)& s);
Assignment operator. The entire vector is copied.
RWGVector(val)& operator=(val v);
Sets all elements of self to the value v.
val operator()(size_t i) const; val& operator()(size_t i);
Return the ith element in the vector. The index i must be between zero and the length of the vector less one. No bounds checking is performed. The second variant can be used as an lvalue.
val operator[](size_t i) const; val& operator[](size_t i);
Return the ith element in the vector. The index i must be between zero and the length of the vector less one. Bounds checking is performed.
const val* data() const;
Returns a pointer to the raw data of self. Should be used with care.
size_t length() const;
Returns the length of the vector.
void reshape(size_t n);
Resize the vector. If the vector shrinks, it will be truncated. If the vector grows, then the value of the additional elements will be undefined.
© 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.