Advanced Strategic Command
basetemp.h
Go to the documentation of this file.
1 
6 // $Id: basetemp.h,v 1.10 2009-01-17 21:54:42 mbickel Exp $
7 //
8 // $Log: not supported by cvs2svn $
9 // Revision 1.9 2007/04/13 16:15:53 mbickel
10 // Merged ASC2 branch
11 //
12 // Revision 1.7.2.1 2006/02/11 21:46:17 mbickel
13 // Move cleanup
14 //
15 // Revision 1.7 2004/05/16 15:40:31 mbickel
16 // Fixed compilation problems with gcc
17 // Included SDLmm library
18 //
19 // Revision 1.6 2001/02/18 15:37:02 mbickel
20 // Some cleanup and documentation
21 // Restructured: vehicle and building classes into separate files
22 // GameMap, tfield and helper classes into separate file (gamemap.h)
23 // basestrm : stream mode now specified by enum instead of int
24 //
25 // Revision 1.5 2001/01/28 14:04:04 mbickel
26 // Some restructuring, documentation and cleanup
27 // The resource network functions are now it their own files, the dashboard
28 // as well
29 // Updated the TODO list
30 //
31 // Revision 1.4 2000/12/21 11:00:45 mbickel
32 // Added some code documentation
33 //
34 // Revision 1.3 1999/12/27 12:59:41 mbickel
35 // new vehicle function: each weapon can now be set to not attack certain
36 // vehicles
37 //
38 // Revision 1.2 1999/11/16 03:41:09 tmwilson
39 // Added CVS keywords to most of the files.
40 // Started porting the code to Linux (ifdef'ing the DOS specific stuff)
41 // Wrote replacement routines for kbhit/getch for Linux
42 // Cleaned up parts of the code that gcc barfed on (char vs unsigned char)
43 // Added autoconf/automake capabilities
44 // Added files used by 'automake --gnu'
45 //
46 //
47 /*
48  This file is part of Advanced Strategic Command; http://www.asc-hq.de
49  Copyright (C) 1994-2010 Martin Bickel and Marc Schellenberger
50 
51  This program is free software; you can redistribute it and/or modify
52  it under the terms of the GNU General Public License as published by
53  the Free Software Foundation; either version 2 of the License, or
54  (at your option) any later version.
55 
56  This program is distributed in the hope that it will be useful,
57  but WITHOUT ANY WARRANTY; without even the implied warranty of
58  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
59  GNU General Public License for more details.
60 
61  You should have received a copy of the GNU General Public License
62  along with this program; see the file COPYING. If not, write to the
63  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
64  Boston, MA 02111-1307 USA
65 */
66 
67 #include <stdio.h>
68 
69 /*
70 template<class T> dynamic_queue<T> :: dynamic_queue ( void )
71 {
72  first = 0;
73  last = 0;
74  blksize = 10;
75  size = blksize;
76  buf = new T[size];
77 }
78 
79 template<class T> void dynamic_queue<T> :: putval ( T a )
80 {
81  if ( first >= size ) {
82  int newsize = ((first+1) / blksize + 1) * blksize;
83  T* temp = new T [ newsize ];
84  for ( int i = 0; i < size; i++ )
85  temp[i] = buf[i];
86 
87  size=newsize;
88  delete[] buf;
89  buf = temp;
90  }
91  buf[first] = a;
92  first++;
93 }
94 
95 template<class T> int dynamic_queue<T> :: valavail ( void )
96 {
97  if ( first > last )
98  return 1;
99  else
100  return 0;
101 }
102 
103 template<class T> T dynamic_queue<T> :: getval ( void )
104 {
105  T b = buf[last];
106  last++;
107  if ( last >= first ) {
108  first = 0;
109  last = 0;
110  }
111  return b;
112 }
113 
114 
115 template<class T> dynamic_queue<T> :: ~dynamic_queue()
116 {
117  delete[] buf;
118 }
119 */
120 
121 
122 
123 
124 template<class T> dynamic_array<T> :: dynamic_array ( void )
125 {
126  maxaccessed = -1;
127  blksize = 10;
128  size = 0;
129  buf = NULL;
130 // resize ( blksize );
131 }
132 template<class T> dynamic_array<T> :: dynamic_array ( int sze )
133 {
134  maxaccessed = -1;
135  blksize = 10;
136  size = 0;
137  buf = NULL;
138 // resize ( sze );
139 }
140 
141 template<class T> void dynamic_array<T> :: reset ( void )
142 {
143  maxaccessed = -1;
144 }
145 
146 
147 template<class T> void dynamic_array<T> :: resize ( int newsize )
148 {
149  T* temp = new T [ newsize ];
150  if ( buf ) {
151  for ( int i = 0; i < size; i++ )
152  temp[i] = buf[i];
153  /*
154  for ( int j = size; j < newsize; j++ )
155  temp[j] = 0;
156  */
157  delete[] buf;
158  }
159 
160  size=newsize;
161  buf = temp;
162 }
163 
164 
165 template<class T> T& dynamic_array<T> :: operator[]( int a )
166 {
167  if ( a > maxaccessed )
168  maxaccessed = a;
169 
170  if ( a >= size ) {
171  int newsize = ((a+1) / blksize + 1) * blksize;
172  resize ( newsize );
173  }
174  return buf[a];
175 }
176 
178 {
179  delete[] buf;
180 }
181 
182 
183 template<class T> int dynamic_array<T> :: getlength( void )
184 {
185  return maxaccessed;
186 }
187 
dynamic_array(void)
Definition: basetemp.h:124
virtual void resize(int newsize)
Definition: basetemp.h:147
T & operator[](int a)
Definition: basetemp.h:165
int getlength(void)
Definition: basetemp.h:183
virtual ~dynamic_array()
Definition: basetemp.h:177
void reset(void)
Definition: basetemp.h:141