File: basetemp.h

package info (click to toggle)
asc 2.6.1.0-9
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 81,740 kB
  • sloc: cpp: 158,704; sh: 11,544; ansic: 6,736; makefile: 604; perl: 138
file content (187 lines) | stat: -rw-r--r-- 4,704 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*! \file basetemp.h
   Some really ugly templates, which were written before I started using the
   STL. Should be scrapped and replaced by STL functions.
*/

//     $Id: basetemp.h,v 1.10 2009-01-17 21:54:42 mbickel Exp $
//
//     $Log: not supported by cvs2svn $
//     Revision 1.9  2007/04/13 16:15:53  mbickel
//      Merged ASC2 branch
//
//     Revision 1.7.2.1  2006/02/11 21:46:17  mbickel
//      Move cleanup
//
//     Revision 1.7  2004/05/16 15:40:31  mbickel
//      Fixed compilation problems with gcc
//      Included SDLmm library
//
//     Revision 1.6  2001/02/18 15:37:02  mbickel
//      Some cleanup and documentation
//      Restructured: vehicle and building classes into separate files
//         GameMap, tfield and helper classes into separate file (gamemap.h)
//      basestrm : stream mode now specified by enum instead of int
//
//     Revision 1.5  2001/01/28 14:04:04  mbickel
//      Some restructuring, documentation and cleanup
//      The resource network functions are now it their own files, the dashboard
//       as well
//      Updated the TODO list
//
//     Revision 1.4  2000/12/21 11:00:45  mbickel
//      Added some code documentation
//
//     Revision 1.3  1999/12/27 12:59:41  mbickel
//      new vehicle function: each weapon can now be set to not attack certain
//                            vehicles
//
//     Revision 1.2  1999/11/16 03:41:09  tmwilson
//     	Added CVS keywords to most of the files.
//     	Started porting the code to Linux (ifdef'ing the DOS specific stuff)
//     	Wrote replacement routines for kbhit/getch for Linux
//     	Cleaned up parts of the code that gcc barfed on (char vs unsigned char)
//     	Added autoconf/automake capabilities
//     	Added files used by 'automake --gnu'
//
//
/*
    This file is part of Advanced Strategic Command; http://www.asc-hq.de
    Copyright (C) 1994-2010  Martin Bickel  and  Marc Schellenberger

    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; see the file COPYING. If not, write to the 
    Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
    Boston, MA  02111-1307  USA
*/

#include <stdio.h> 

/*
template<class T> dynamic_queue<T> :: dynamic_queue ( void )
{
   first = 0;
   last = 0;
   blksize = 10;
   size = blksize;
   buf = new T[size];
}

template<class T> void dynamic_queue<T> :: putval ( T a )
{
   if ( first >= size ) {
      int newsize = ((first+1) / blksize + 1) * blksize;
      T* temp = new T [ newsize ];
      for ( int i = 0; i < size; i++ )
         temp[i] = buf[i];

      size=newsize;
      delete[] buf;
      buf = temp;
   }
   buf[first] = a;
   first++;
} 

template<class T> int dynamic_queue<T> :: valavail ( void )
{
   if ( first > last )
      return 1;
   else 
      return 0;
} 

template<class T> T dynamic_queue<T> :: getval ( void )
{
   T b = buf[last];
   last++;
   if ( last >= first ) {
      first = 0;
      last = 0;
   }
   return b;
} 


template<class T> dynamic_queue<T> :: ~dynamic_queue()
{
   delete[] buf;
}
*/




template<class T> dynamic_array<T> :: dynamic_array ( void )
{
   maxaccessed = -1;
   blksize = 10;
   size = 0;
   buf = NULL;
//   resize ( blksize );
}
template<class T> dynamic_array<T> :: dynamic_array ( int sze )
{
   maxaccessed = -1;
   blksize = 10;
   size = 0;
   buf = NULL;
//   resize ( sze );
}

template<class T> void dynamic_array<T> :: reset ( void )
{
   maxaccessed = -1;
}


template<class T> void dynamic_array<T> :: resize ( int newsize )
{
   T* temp = new T [ newsize ];
   if ( buf ) {
      for ( int i = 0; i < size; i++ )
         temp[i] = buf[i];
    /*
      for ( int j = size; j < newsize; j++ )
         temp[j] = 0;
     */
      delete[] buf;
   }

   size=newsize;
   buf = temp;
}


template<class T> T& dynamic_array<T> :: operator[]( int a )
{
   if ( a > maxaccessed )
      maxaccessed = a;

   if ( a >= size ) {
      int newsize = ((a+1) / blksize + 1) * blksize;
      resize ( newsize );
   }
   return buf[a];
} 

template<class T> dynamic_array<T> :: ~dynamic_array()
{
   delete[] buf;
}


template<class T> int dynamic_array<T> :: getlength( void )
{
   return maxaccessed;
}