Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

RWGOrderedVector(val)

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

Synopsis

#include <rw/gordvec.h>
declare(RWGVector,val)
declare(RWGOrderedVector,val)
implement(RWGVector,val)
implement(RWGOrderedVector,val)

RWGOrderedVector(val) v;// Ordered vector of objects of val val.

Description

Class RWGOrderedVector(val) represents an ordered collection of objects of val val. Objects are ordered by the order of insertion and are accessible by index. Duplicates are allowed. RWGOrderedVector(val) is implemented as a vector, using macros defined in the standard C++ header file <generic.h>.

Note that it is a value-based collection: items are copied in and out of the collection.

The class val must have:

To use this class you must declare and implement its base class as well as the class itself. For example, here is how you declare and implement an ordered collection of doubles:

declare(RWGVector,double)                     // Declare base class
declare(RWGOrderedVector,double)  // Declare ordered vector

// In one and only one .cpp file you must put the following:
implement(RWGVector,double)            // Implement base class
implement(RWGOrderedVector,double)     // Implement ordered vector

For each val of RWGOrderedVector you must include one (and only one) call to the macro implement somewhere in your code for both the RWGOrderedVector itself and for its base class RWGVector.

Persistence

None

Example

Here's an example that uses an ordered vector of RWCStrings.

#include <rw/gordvec.h>
#include <rw/cstring.h>
#include <rw/rstream.h>

declare(RWGVector,RWCString)
declare(RWGOrderedVector,RWCString)
implement(RWGVector,RWCString)
implement(RWGOrderedVector,RWCString)

main()  {
  RWGOrderedVector(RWCString) vec;

  RWCString one("First");
  vec.insert(one);

  vec.insert("Second");   // Automatic val conversion occurs
  vec.insert("Last");     // Automatic val conversion occurs

  for(size_t i=0; i<vec.entries(); i++)  cout << vec[i] << endl;

  return 0;
}

Program output:

First
Second
Last

Public Constructors

RWGOrderedVector(val)(size_t capac=RWDEFAULT_CAPACITY);

Public Member Functions

val
operator()(size_t i) const;
val&
operator()(size_t i);
val
operator[](size_t i) const;
val&
operator[](size_t i);
void
clear();
const val*
data() const;
size_t
entries() const;
size_t
index(val item) const;
void
insert(val item);
void
insertAt(size_t indx, val item);
RWBoolean
isEmpty() const;
void
size_t
length() const;
val
pop();
void
push(val);
removeAt(size_t indx);
void
resize(size_t newCapacity);


Previous fileTop of documentContentsIndexNext file
©Copyright 1999, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.