Recovered from microbel
This commit is contained in:
82
common/lib/utils/doublearray.C
Normal file
82
common/lib/utils/doublearray.C
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* PVVMUD a 3D MUD
|
||||
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
#include "pvvmud.H"
|
||||
#include <stdlib.h>
|
||||
#include <iostream.h>
|
||||
#include "doublearray.H"
|
||||
|
||||
CDoubleArray::CDoubleArray(){
|
||||
m_size = 0;
|
||||
m_num = 0;
|
||||
m_array = NULL;
|
||||
}
|
||||
|
||||
CDoubleArray::~CDoubleArray(){
|
||||
if (m_array != NULL) free(m_array);
|
||||
}
|
||||
|
||||
int CDoubleArray::add( double num ){
|
||||
if (m_num >= m_size){
|
||||
if (m_array == NULL){
|
||||
m_array = (double*)malloc(sizeof(double)*4);
|
||||
m_size = 4;
|
||||
} else {
|
||||
m_array = (double*)realloc(m_array,sizeof(double)*m_size*2);
|
||||
m_size *=2;
|
||||
}
|
||||
}
|
||||
m_array[m_num] = num;
|
||||
return m_num++;
|
||||
}
|
||||
|
||||
int CDoubleArray::add( CDoubleArray * doubleArray ){
|
||||
int ii,tmp;
|
||||
int num = doubleArray->getNumElements();
|
||||
for (ii = 0; ii < num; ii ++){
|
||||
tmp = add(doubleArray->get(ii));
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
int CDoubleArray::insert( double num ){
|
||||
cdebug << "WARNING: CDoubleArray::insert NOT IMPLEMENTED!\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
double CDoubleArray::get( int index ) const{
|
||||
return m_array[index];
|
||||
}
|
||||
|
||||
int CDoubleArray::getNumElements() const{
|
||||
return m_num;
|
||||
}
|
||||
|
||||
void CDoubleArray::deleteAll(){
|
||||
m_num = 0;
|
||||
}
|
||||
|
||||
ostream& operator<<(ostream&s,const CDoubleArray& d) {
|
||||
int index;
|
||||
s << "[ ";
|
||||
for (index = 0; index < d.getNumElements(); index ++)
|
||||
s << d.get(index) << " ";
|
||||
return s << "]";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user