• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kviewshell

ArrayBase Class Reference

Dynamic array base class. More...

#include <Arrays.h>

Inheritance diagram for ArrayBase:

Inheritance graph
[legend]

List of all members.


Public Member Functions

virtual ~ArrayBase (void)

Protected Member Functions

 ArrayBase (void)

Arrays.h

Files #"Arrays.h"# and #"Arrays.cpp"# implement three array template classes.

Class {TArray} implements an array of objects of trivial types such as char#, int#, float#, etc. It is faster than general implementation for any type done in {DArray} because it does not cope with element's constructors, destructors and copy operators. Although implemented as a template, which makes it possible to incorrectly use {TArray} with non-trivial classes, it should not be done.

A lot of things is shared by these three arrays. That is why there are more base classes: {itemize} {ArrayBase} defines functions independent of the elements type {ArrayBaseT} template class defining functions shared by {DArray} and {TArray} {itemize}

The main difference between {GArray} (now obsolete) and these ones is the copy-on-demand strategy, which allows you to copy array objects without copying the real data. It's the same thing, which has been implemented in {GString} long ago: as long as you don't try to modify the underlying data, it may be shared between several copies of array objects. As soon as you attempt to make any changes, a private copy is created automatically and transparently for you - the procedure, that we call "copy-on-demand".

Also, please note that now there is no separate class, which does fast sorting. Both {TArray} (dynamic array for trivial types) and {DArray} (dynamic array for arbitrary types) can sort their elements.

{ Historical comments} --- Leon chose to implement his own arrays because the STL classes were not universally available and the compilers were rarely able to deal with such a template galore. Later it became clear that there is no really good reason why arrays should be derived from containers. It was also suggested to create separate arrays implementation for simple classes and do the copy-on-demand strategy, which would allow to assign array objects without immediate copying of their elements.

At this point {DArray} and {TArray} should only be used when it is critical to have the copy-on-demand feature. The {GArray} implementation is a lot more efficient.

Template array classes.

Author:
Andrei Erofeev <eaf@geocities.com> -- Copy-on-demand implementation.
Version:
$Id: Arrays.h,v 1.10 2004/05/13 15:16:34 leonb Exp $#


void check (void)
void detach (void)
void del (int n, unsigned int howmany=1)
void empty ()
int hbound () const
int lbound () const
void resize (int lobound, int hibound)
void resize (int hibound)
void shift (int disp)
int size () const
void touch (int n)

Detailed Description

Dynamic array base class.

This is an auxiliary base class for {DArray} and {TArray} implementing some shared functions independent of the type of array elements. It's not supposed to be constructed by hands. Use {DArray} and {TArray} instead.

Definition at line 305 of file Arrays.h.


Constructor & Destructor Documentation

ArrayBase::ArrayBase ( void   )  [inline, protected]

Definition at line 311 of file Arrays.h.

virtual ArrayBase::~ArrayBase ( void   )  [inline, virtual]

Definition at line 364 of file Arrays.h.


Member Function Documentation

void ArrayBase::check ( void   )  [inline, protected]

Definition at line 375 of file Arrays.h.

void ArrayBase::del ( int  n,
unsigned int  howmany = 1 
) [inline]

Deletes array elements.

The array elements corresponding to subscripts n#...n+howmany-1# are destroyed. All array elements previously located at subscripts greater or equal to n+howmany# are moved to subscripts starting with n#. The new subscript upper bound is reduced in order to account for this shift.

Parameters:
n subscript of the first element to delete.
howmany number of elements to delete.

Definition at line 433 of file Arrays.h.

void ArrayBase::detach ( void   )  [inline, protected]

Definition at line 368 of file Arrays.h.

void ArrayBase::empty (  )  [inline]

Erases the array contents.

All elements in the array are destroyed. The valid subscript range is set to the empty range.

Definition at line 399 of file Arrays.h.

int ArrayBase::hbound (  )  const [inline]

Returns the upper bound of the valid subscript range.

Definition at line 393 of file Arrays.h.

int ArrayBase::lbound (  )  const [inline]

Returns the lower bound of the valid subscript range.

Definition at line 387 of file Arrays.h.

void ArrayBase::resize ( int  lobound,
int  hibound 
) [inline]

Resets the valid subscript range to lobound#---hibound#.

This function may destroy some array elements and may construct new array elements with the null constructor. Setting lobound# to #0# and hibound# to #-1# resets the valid subscript range to the empty range.

Parameters:
lobound lower bound of the new subscript range.
hibound upper bound of the new subscript range.

Definition at line 406 of file Arrays.h.

void ArrayBase::resize ( int  hibound  )  [inline]

Resets the valid subscript range to #0#---hibound#.

This function may destroy some array elements and may construct new array elements with the null constructor. Setting hibound# to #-1# resets the valid subscript range to the empty range.

Parameters:
hibound upper bound of the new subscript range.

Definition at line 413 of file Arrays.h.

void ArrayBase::shift ( int  disp  )  [inline]

Shifts the valid subscript range.

Argument disp# is added to both bounds of the valid subscript range. Array elements previously located at subscript x# will now be located at subscript x+disp#.

Definition at line 426 of file Arrays.h.

int ArrayBase::size (  )  const [inline]

Returns the number of elements in the array.

Definition at line 381 of file Arrays.h.

void ArrayBase::touch ( int  n  )  [inline]

Extends the subscript range so that is contains n#.

This function does nothing if n# is already int the valid subscript range. If the valid range was empty, both the lower bound and the upper bound are set to n#. Otherwise the valid subscript range is extended to encompass n#. This function is very handy when called before setting an array element: {verbatim} int lineno=1; DArray<GString> a; while (! end_of_file()) { a.touch[lineno]; a[lineno++] = read_a_line(); } {verbatim}

Definition at line 419 of file Arrays.h.


The documentation for this class was generated from the following file:
  • Arrays.h

kviewshell

Skip menu "kviewshell"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • kviewshell
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal