Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

basetemp.h

Go to the documentation of this file.
00001 
00006 //     $Id: basetemp.h,v 1.9 2007-04-13 16:15:53 mbickel Exp $
00007 //
00008 //     $Log: basetemp.h,v $
00009 //     Revision 1.9  2007-04-13 16:15:53  mbickel
00010 //      Merged ASC2 branch
00011 //
00012 //     Revision 1.7.2.1  2006/02/11 21:46:17  mbickel
00013 //      Move cleanup
00014 //
00015 //     Revision 1.7  2004/05/16 15:40:31  mbickel
00016 //      Fixed compilation problems with gcc
00017 //      Included SDLmm library
00018 //
00019 //     Revision 1.6  2001/02/18 15:37:02  mbickel
00020 //      Some cleanup and documentation
00021 //      Restructured: vehicle and building classes into separate files
00022 //         GameMap, tfield and helper classes into separate file (gamemap.h)
00023 //      basestrm : stream mode now specified by enum instead of int
00024 //
00025 //     Revision 1.5  2001/01/28 14:04:04  mbickel
00026 //      Some restructuring, documentation and cleanup
00027 //      The resource network functions are now it their own files, the dashboard
00028 //       as well
00029 //      Updated the TODO list
00030 //
00031 //     Revision 1.4  2000/12/21 11:00:45  mbickel
00032 //      Added some code documentation
00033 //
00034 //     Revision 1.3  1999/12/27 12:59:41  mbickel
00035 //      new vehicle function: each weapon can now be set to not attack certain
00036 //                            vehicles
00037 //
00038 //     Revision 1.2  1999/11/16 03:41:09  tmwilson
00039 //      Added CVS keywords to most of the files.
00040 //      Started porting the code to Linux (ifdef'ing the DOS specific stuff)
00041 //      Wrote replacement routines for kbhit/getch for Linux
00042 //      Cleaned up parts of the code that gcc barfed on (char vs unsigned char)
00043 //      Added autoconf/automake capabilities
00044 //      Added files used by 'automake --gnu'
00045 //
00046 //
00047 /*
00048     This file is part of Advanced Strategic Command; http://www.asc-hq.de
00049     Copyright (C) 1994-1999  Martin Bickel  and  Marc Schellenberger
00050 
00051     This program is free software; you can redistribute it and/or modify
00052     it under the terms of the GNU General Public License as published by
00053     the Free Software Foundation; either version 2 of the License, or
00054     (at your option) any later version.
00055 
00056     This program is distributed in the hope that it will be useful,
00057     but WITHOUT ANY WARRANTY; without even the implied warranty of
00058     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00059     GNU General Public License for more details.
00060 
00061     You should have received a copy of the GNU General Public License
00062     along with this program; see the file COPYING. If not, write to the 
00063     Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
00064     Boston, MA  02111-1307  USA
00065 */
00066 
00067 #include <stdio.h> 
00068 
00069 /*
00070 template<class T> dynamic_queue<T> :: dynamic_queue ( void )
00071 {
00072    first = 0;
00073    last = 0;
00074    blksize = 10;
00075    size = blksize;
00076    buf = new T[size];
00077 }
00078 
00079 template<class T> void dynamic_queue<T> :: putval ( T a )
00080 {
00081    if ( first >= size ) {
00082       int newsize = ((first+1) / blksize + 1) * blksize;
00083       T* temp = new T [ newsize ];
00084       for ( int i = 0; i < size; i++ )
00085          temp[i] = buf[i];
00086 
00087       size=newsize;
00088       delete[] buf;
00089       buf = temp;
00090    }
00091    buf[first] = a;
00092    first++;
00093 } 
00094 
00095 template<class T> int dynamic_queue<T> :: valavail ( void )
00096 {
00097    if ( first > last )
00098       return 1;
00099    else 
00100       return 0;
00101 } 
00102 
00103 template<class T> T dynamic_queue<T> :: getval ( void )
00104 {
00105    T b = buf[last];
00106    last++;
00107    if ( last >= first ) {
00108       first = 0;
00109       last = 0;
00110    }
00111    return b;
00112 } 
00113 
00114 
00115 template<class T> dynamic_queue<T> :: ~dynamic_queue()
00116 {
00117    delete[] buf;
00118 }
00119 */
00120 
00121 
00122 
00123 
00124 template<class T> dynamic_array<T> :: dynamic_array ( void )
00125 {
00126    maxaccessed = -1;
00127    blksize = 10;
00128    size = 0;
00129    buf = NULL;
00130 //   resize ( blksize );
00131 }
00132 template<class T> dynamic_array<T> :: dynamic_array ( int sze )
00133 {
00134    maxaccessed = -1;
00135    blksize = 10;
00136    size = 0;
00137    buf = NULL;
00138 //   resize ( sze );
00139 }
00140 
00141 template<class T> void dynamic_array<T> :: reset ( void )
00142 {
00143    maxaccessed = -1;
00144 }
00145 
00146 
00147 template<class T> void dynamic_array<T> :: resize ( int newsize )
00148 {
00149    T* temp = new T [ newsize ];
00150    if ( buf ) {
00151       for ( int i = 0; i < size; i++ )
00152          temp[i] = buf[i];
00153     /*
00154       for ( int j = size; j < newsize; j++ )
00155          temp[j] = 0;
00156      */
00157       delete[] buf;
00158    }
00159 
00160    size=newsize;
00161    buf = temp;
00162 }
00163 
00164 
00165 template<class T> T& dynamic_array<T> :: operator[]( int a )
00166 {
00167    if ( a > maxaccessed )
00168       maxaccessed = a;
00169 
00170    if ( a >= size ) {
00171       int newsize = ((a+1) / blksize + 1) * blksize;
00172       resize ( newsize );
00173    }
00174    return buf[a];
00175 } 
00176 
00177 template<class T> dynamic_array<T> :: ~dynamic_array()
00178 {
00179    delete[] buf;
00180 }
00181 
00182 
00183 template<class T> int dynamic_array<T> :: getlength( void )
00184 {
00185    return maxaccessed;
00186 } 
00187 
00188 
00189 
00190 template<class T> void dynamic_initialized_array<T> :: resize ( int newsize )
00191 {
00192    int oldsize = T::size;
00193    dynamic_array<int> :: resize ( newsize );
00194    for ( int i = oldsize; i < newsize; i++ )
00195       T::buf[i] = initval;
00196 }
00197 
00198 template<class T> dynamic_initialized_array<T> :: dynamic_initialized_array ( T ival )
00199 {
00200    initval = ival;
00201 }
00202 
00203 template<class T> dynamic_initialized_array<T> :: dynamic_initialized_array ( T ival, int sze )
00204                                              : dynamic_array<T> ( sze )
00205 {
00206    initval = ival;
00207 }

Generated on Tue Jun 24 01:27:36 2008 for Advanced Strategic Command by  doxygen 1.4.2