FLTK 1.4.0
Fl_Int_Vector Class Reference

An STL-ish vector without templates. More...

#include <Fl_Int_Vector.H>

Public Member Functions

int back () const
 Return the last element in the array. More...
 
bool empty () const
 Checks if array has no elements. More...
 
 Fl_Int_Vector ()
 Create an empty vector of integers.
 
 Fl_Int_Vector (Fl_Int_Vector &o)
 Copy constructor.
 
Fl_Int_Vectoroperator= (Fl_Int_Vector &o)
 Assignment operator. More...
 
int & operator[] (int x)
 Access the specified integer element at index position x as a reference. More...
 
int operator[] (int x) const
 Access the specified integer element at index position x. More...
 
int pop_back ()
 Removes the last element the last element and returns its value. More...
 
void push_back (int val)
 Appends val to the array, enlarging the array by one.
 
unsigned int size () const
 Return the number of integer elements in the array.
 
void size (unsigned int count)
 Set the size of the array to count. More...
 
 ~Fl_Int_Vector ()
 Destructor - frees the internal array and destroys the class.
 

Detailed Description

An STL-ish vector without templates.

Handles dynamic memory management of an integer array, and allows array elements to be accessed with zero based indexing: v[0], v[1]..

Common use:

#include <stdio.h>
int main() {
// Create an array of values 11,22,33:
v.push_back(11); // add first element
v.push_back(22); // add second element
v.push_back(33); // add third element
// Assignment by subscript
v[1] = 222; // changes 2nd element from 22 to 222
// Loop through printing the values
for ( unsigned int i=0; i<v.size(); i++ )
printf("%d ", v[i]); // access the elements
printf("\n");
// Clear the array
v.size(0);
}
An STL-ish vector implemented without templates.
An STL-ish vector without templates.
Definition: Fl_Int_Vector.H:63
Todo:
  • Add other std::vector methods like erase(), etc.
  • Make memory blocking size flexible, and add related methods like capacity(), reserve(), shrink_to_fit(), etc.
  • Add non-std methods that are nevertheless needed, e.g. insert(index,val), delete(index), delete(start, end), swap(a_idx,b_idx)

Member Function Documentation

◆ back()

int Fl_Int_Vector::back ( ) const
inline

Return the last element in the array.

Warning
You must not call back() if the array is empty, i.e. if (size() == 0).
Todo:
Internals should maybe assert(size_ != 0)

◆ empty()

bool Fl_Int_Vector::empty ( ) const
inline

Checks if array has no elements.

Same as a test for (size() == 0).

◆ operator=()

Fl_Int_Vector& Fl_Int_Vector::operator= ( Fl_Int_Vector o)
inline

Assignment operator.

Similar to the copy constructor, creates a separate copy of the source array, freeing any previous contents in the current integer array.

◆ operator[]() [1/2]

int& Fl_Int_Vector::operator[] ( int  x)
inline

Access the specified integer element at index position x as a reference.

This allows assignment by index through the returned reference, e.g. arr[1] = 222; where arr[1] ends up being a reference to ptr[1], and then 222 is assigned to that ref.

Warning
No range checking is done on x, which must be less than size().

◆ operator[]() [2/2]

int Fl_Int_Vector::operator[] ( int  x) const
inline

Access the specified integer element at index position x.

Warning
No range checking is done on x, which must be less than size().

◆ pop_back()

int Fl_Int_Vector::pop_back ( )
inline

Removes the last element the last element and returns its value.

Warning
You must not call pop_back() if the array is empty, i.e. if (size() == 0).
Todo:
Internals should maybe assert(size_ != 0)

◆ size()

void Fl_Int_Vector::size ( unsigned int  count)

Set the size of the array to count.

Setting size to zero clears the array and frees any memory it used.

Shrinking truncates the array and frees memory of truncated elements. Enlarging creates new elements that are zero in value.


The documentation for this class was generated from the following files: