head	1.5;
access;
symbols
	r2_1:1.5
	r2_0:1.5
	r1_1_beta:1.4
	r1_1_alpha:1.3
	r1_0:1.3
	r0_11:1.3
	r0_10:1.3
	r0_9:1.3
	Eglin_alpha_1:1.3;
locks; strict;
comment	@// @;


1.5
date	94.11.10.18.46.59;	author ljr;	state Exp;
branches;
next	1.4;

1.4
date	94.10.14.18.02.43;	author ljr;	state Exp;
branches;
next	1.3;

1.3
date	93.05.26.16.28.19;	author thoth;	state Exp;
branches;
next	1.2;

1.2
date	93.05.19.14.42.16;	author thoth;	state Exp;
branches;
next	1.1;

1.1
date	92.10.27.16.34.42;	author thoth;	state Exp;
branches;
next	;


desc
@generic dynamic array
@


1.5
log
@Added IA_NO_RCS_STATIC_DATA guard.
@
text
@// Emacs: -*- C++ -*-

//
//	Copyright 1993, Center for Computer Vision and Visualization,
//	University of Florida.  All rights reserved.
//

#ifndef IA_NO_RCS_STATIC_DATA
static char rcsid_Array[] = "$Id: Array.c,v 1.4 1994/10/14 18:02:43 ljr Exp ljr $";
#endif

// 
// $Log: Array.c,v $
// Revision 1.4  1994/10/14  18:02:43  ljr
// outdated revisions that did #include "Array.h" conditionally for
// BC++ and SC++; added #include "Array.h"
//
// Revision 1.3  1993/05/26  16:28:19  thoth
// Copyright Notices.
//
// Revision 1.2  93/05/19  14:42:16  thoth
// Renamed to IA_Array.
// new operator() which is const.
// 
// Revision 1.1  92/10/27  16:34:42  thoth
// Initial revision
// 
//

#include "Array.h"

template <class T>
IA_Array<T>::IA_Array(unsigned size_)
{
    data = new T[size = size_];
    length = 0;
}



template <class T>
IA_Array<T>::IA_Array(T* data_, unsigned size_, int giveaway)
{
    length = size = size_;
    if (giveaway) {
	data = data_;
    } else {
	data = new T[size];
	for (unsigned i=0; i<length; i++)
	    data[i] = data_[i];
    }
}

template <class T>
IA_Array<T>::IA_Array(const IA_Array<T> &arr)
{
    length = size = arr.length;
    data = new T[size];
    for (unsigned i=0; i<length; i++)
	data[i] = arr.data[i];
}

template <class T>
IA_Array<T>& IA_Array<T>::operator=(const IA_Array<T> &arr)
{
    if (this == &arr) {
	// a = a;
	return *this;
    }

    delete[] data;
    length = size = arr.length;
    data = new T[size];
    for (unsigned i=0; i<length; i++) {
	data[i] = arr.data[i];
    }

    return *this;
}


template <class T>
T& IA_Array<T>::operator[](unsigned idx)
{
    unsigned	beyond = idx+1;
    if (beyond>size) {
	resize(size*2>beyond? size*2 : beyond*2);
    }
    if (idx>=length)
	length = beyond;
    return data[idx];
}

template <class T>
T IA_Array<T>::operator[](unsigned idx) const
{
    //return (idx>=size)?T():data[idx];
    if (idx>=size) {
	T	rval;
	return rval;
    } else
	return data[idx];
}

template <class T>
T IA_Array<T>::operator()(unsigned idx) const
{
    //return (idx>=size)?T():data[idx];
    if (idx>=size) {
	T	rval;
	return rval;
    } else
	return data[idx];
}

template <class T>
unsigned IA_Array<T>::shorten(unsigned newlen)
{
    unsigned	rval = length;
    if (newlen<length)
	length = newlen;
    return rval;
}

template <class T>
unsigned IA_Array<T>::lengthen(unsigned newlen)
{
    unsigned	rval = length;
    if (newlen>size)
	resize(newlen);
    if (newlen>length)
	length = newlen;
    return rval;
}

template <class T>
unsigned IA_Array<T>::resize(unsigned newsize)
{
    unsigned oldsize=size;
    T	*newdata = new T[newsize];

    // copy the data we already have.
    for (unsigned i=0; i<length && i<newsize; i++)
	newdata[i] = data[i];

    // maybe truncate
    length = i;

    delete[] data;
    size = newsize;
    data = newdata;

    return oldsize;
}
@


1.4
log
@outdated revisions that did #include "Array.h" conditionally for
BC++ and SC++; added #include "Array.h"
@
text
@d8 3
a10 1
static char rcsid_Array[] = "$Id: Array.c,v 1.3 1993/05/26 16:28:19 thoth Exp ljr $";
d14 4
@


1.3
log
@Copyright Notices.
@
text
@d8 1
a8 1
static char rcsid_Array[] = "$Id: Array.c,v 1.2 93/05/19 14:42:16 thoth Exp Locker: thoth $";
d11 4
a14 1
// $Log:	Array.c,v $
d23 2
@


1.2
log
@Renamed to IA_Array.
new operator() which is const.
@
text
@a1 1
static char rcsid_Array[] = "$Id: Array.c,v 1.1 92/10/27 16:34:42 thoth Exp Locker: thoth $";
d3 7
d12 4
@


1.1
log
@Initial revision
@
text
@d2 1
a2 1
static char rcsid_Array[] = "$Id: IntPointSet.c,v 1.11 92/10/25 20:53:24 thoth Exp Locker: thoth $";
d5 4
a8 1
// $Log:	IntPointSet.h,v $
d12 1
a12 1
Array<T>::Array(unsigned size_)
d21 1
a21 1
Array<T>::Array(T* data_, unsigned size_, int giveaway)
d34 1
a34 1
Array<T>::Array(const Array<T> &arr)
d43 1
a43 1
Array<T>& Array<T>::operator=(const Array<T> &arr)
d62 1
a62 1
T& Array<T>::operator[](unsigned idx)
d74 1
a74 1
T Array<T>::operator[](unsigned idx) const
d85 1
a85 1
unsigned Array<T>::shorten(unsigned newlen)
d87 11
d105 1
a105 1
unsigned Array<T>::lengthen(unsigned newlen)
d116 1
a116 1
unsigned Array<T>::resize(unsigned newsize)
@
