Logo Search packages:      
Sourcecode: djvulibre version File versions

DArray< TYPE > Class Template Reference

#include <Arrays.h>

Inheritance diagram for DArray< TYPE >:

ArrayBaseT< TYPE > ArrayBase

List of all members.


Detailed Description

template<class TYPE>
class DArray< TYPE >

Dynamic array for general types. Template class DArray<TYPE># implements an array of elements of type TYPE#. Each element is identified by an integer subscript. The valid subscripts range is defined by dynamically adjustable lower- and upper-bounds. Besides accessing and setting elements, member functions are provided to insert or delete elements at specified positions.

This template class must be able to access {itemize} a null constructor TYPE::TYPE()#, a copy constructor TYPE::TYPE(const TYPE &)#, and a copy operator TYPE & operator=(const TYPE &)#. {itemize}

The class offers "copy-on-demand" policy, which means that when you copy the array object, array elements will stay intact as long as you don't try to modify them. As soon as you make an attempt to change array contents, the copying is done automatically and transparently for you - the procedure that we call "copy-on-demand". This is the main difference between this class and {GArray} (now obsolete)

Please note that most of the methods are implemented in the base classes {ArrayBase} and {ArrayBaseT}.

Definition at line 758 of file Arrays.h.


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
#

 DArray (const int lobound, const int hibound)
 DArray (const int hibound)
 DArray (void)
void del (int n, unsigned int howmany=1)
void empty ()
int hbound () const
void ins (int n, const TYPE &val, unsigned int howmany=1)
int lbound () const
 operator const TYPE * ()
 operator const TYPE * () const
 operator TYPE * ()
const TYPE & operator[] (int n) const
TYPE & operator[] (int n)
void resize (int lobound, int hibound)
void resize (int hibound)
void shift (int disp)
int size () const
 Returns the number of elements in the array.
void sort (int lo, int hi)
void sort ()
void touch (int n)
static void copy (void *dst, int dst_lo, int dst_hi, const void *src, int src_lo, int src_hi)
static void destroy (void *data, int lo, int hi)
static void init1 (void *data, int lo, int hi)
static void init2 (void *data, int lo, int hi, const void *src, int src_lo, int src_hi)
static void insert (void *data, int els, int where, const void *what, int howmany)
void check (void)
void detach (void)

Protected Member Functions

_ArrayBase & assign (_ArrayRep *ar)
_ArrayRep * get (void) const
bool operator== (const _ArrayBase &ab)

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

Generated by  Doxygen 1.6.0   Back to index