~ubuntu-branches/ubuntu/utopic/travis/utopic

« back to all changes in this revision

Viewing changes to src/xintarray.cpp

  • Committer: Package Import Robot
  • Author(s): Daniel Leidert
  • Date: 2014-01-18 20:07:16 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20140118200716-whsmcg7fa1eyqecq
Tags: 140117-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
2
 
    TRAVIS - Trajectory Analyzer and Visualizer
3
 
    http://www.travis-analyzer.de/
4
 
 
5
 
    Copyright (c) 2009-2013 Martin Brehm
6
 
                  2012-2013 Martin Thomas
7
 
 
8
 
    This file written by Martin Brehm.
9
 
 
10
 
    This program is free software: you can redistribute it and/or modify
11
 
    it under the terms of the GNU General Public License as published by
12
 
    the Free Software Foundation, either version 3 of the License, or
13
 
    (at your option) any later version.
14
 
 
15
 
    This program is distributed in the hope that it will be useful,
16
 
    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 
    GNU General Public License for more details.
19
 
 
20
 
    You should have received a copy of the GNU General Public License
21
 
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 
*****************************************************************************/
23
 
 
24
 
#include "xintarray.h"
25
 
 
26
 
 
27
 
#ifndef DEBUG_ARRAYS
28
 
#define m_sName (NULL)
29
 
#endif
30
 
 
31
 
 
32
 
CxIntArray::CxIntArray()
33
 
{
34
 
        BXIN;
35
 
#ifdef DEBUG_CINTARRAY
36
 
        mprintf("@ CxIntArray::CxIntArray()\n");
37
 
#endif
38
 
        m_pData = NULL;
39
 
        m_iSize = 0;
40
 
        m_iMaxSize = 0;
41
 
        m_iGrow = 16;
42
 
#ifdef DEBUG_ARRAYS
43
 
        m_sName = NULL;
44
 
#endif
45
 
        BXOUT;
46
 
}
47
 
 
48
 
 
49
 
CxIntArray::CxIntArray(const char *name)
50
 
{
51
 
        BXIN;
52
 
#ifdef DEBUG_CINTARRAY
53
 
        mprintf("@ CxIntArray::CxIntArray(const char *)\n");
54
 
#endif
55
 
        m_pData = NULL;
56
 
        m_iSize = 0;
57
 
        m_iMaxSize = 0;
58
 
        m_iGrow = 16;
59
 
#ifdef DEBUG_ARRAYS
60
 
        m_sName = NULL;
61
 
#endif
62
 
        SetName(name);
63
 
        BXOUT;
64
 
}
65
 
 
66
 
        
67
 
CxIntArray::~CxIntArray()
68
 
{
69
 
        BXIN;
70
 
#ifdef DEBUG_CINTARRAY
71
 
        mprintf("@ CxIntArray::~CxIntArray()\n");
72
 
#endif
73
 
        RemoveAll();
74
 
#ifdef DEBUG_ARRAYS
75
 
        if (m_sName != NULL)
76
 
        {
77
 
                delete[] m_sName;
78
 
                m_sName = NULL;
79
 
        }
80
 
#endif
81
 
        BXOUT;
82
 
}
83
 
 
84
 
        
85
 
CxIntArray::CxIntArray(CxIntArray &o) : CxObject()
86
 
{
87
 
        BXIN;
88
 
#ifdef DEBUG_CINTARRAY
89
 
        mprintf("@ CxIntArray::CxIntArray(CxIntArray &)...");
90
 
#endif
91
 
        unsigned int z;
92
 
        m_iSize = o.m_iSize;
93
 
        m_iMaxSize = o.m_iMaxSize;
94
 
        m_iGrow = o.m_iGrow;
95
 
 
96
 
        try { m_pData = new int[m_iMaxSize]; } catch(...) { m_pData = NULL; }
97
 
        if (m_pData == NULL) NewException((double)m_iMaxSize*sizeof(int),__FILE__,__LINE__,__PRETTY_FUNCTION__,m_sName);
98
 
        
99
 
        for (z=0;z<m_iSize;z++)
100
 
                m_pData[z] = o.m_pData[z];
101
 
#ifdef DEBUG_CINTARRAY
102
 
        mprintf("done.\n");
103
 
#endif
104
 
        BXOUT;
105
 
}
106
 
 
107
 
 
108
 
void CxIntArray::CopyFrom(CxIntArray *o)
109
 
{
110
 
        BXIN;
111
 
#ifdef DEBUG_CINTARRAY
112
 
        mprintf("@ CxIntArray::CopyFrom(CxIntArray*)...");
113
 
#endif
114
 
        m_iSize = o->m_iSize;
115
 
        m_iMaxSize = o->m_iMaxSize;
116
 
        m_iGrow = o->m_iGrow;
117
 
        if (m_pData != NULL)
118
 
                delete[] m_pData;
119
 
 
120
 
        try { m_pData = new int[m_iMaxSize]; } catch(...) { m_pData = NULL; }
121
 
        if (m_pData == NULL) NewException((double)m_iMaxSize*sizeof(int),__FILE__,__LINE__,__PRETTY_FUNCTION__,m_sName);
122
 
        
123
 
        memcpy(m_pData,o->m_pData,m_iSize*sizeof(int));
124
 
#ifdef DEBUG_CINTARRAY
125
 
        mprintf("done.\n");
126
 
#endif
127
 
        BXOUT;
128
 
}
129
 
        
130
 
 
131
 
void CxIntArray::Append(CxIntArray *o)
132
 
{
133
 
        BXIN;
134
 
#ifdef DEBUG_CINTARRAY
135
 
        mprintf("@ CxIntArray::Append(CxIntArray*)...");
136
 
#endif
137
 
//      unsigned int z;
138
 
        if (m_iSize+o->m_iSize > m_iMaxSize)
139
 
                SetMaxSize(m_iSize+o->m_iSize);
140
 
//      for (z=0;z<o->m_iSize;z++)
141
 
//              m_pData[m_iSize+z] = o->m_pData[z];
142
 
        memcpy(&m_pData[m_iSize],o->m_pData,o->m_iSize*sizeof(int));
143
 
        m_iSize += o->m_iSize;
144
 
#ifdef DEBUG_CINTARRAY
145
 
        mprintf("done.\n");
146
 
#endif
147
 
        BXOUT;
148
 
}       
149
 
 
150
 
 
151
 
void CxIntArray::SetAt(unsigned int pos, int f)
152
 
{
153
 
        BXIN;
154
 
//      unsigned int z;
155
 
#ifdef DEBUG_CINTARRAY
156
 
        bool s = false;
157
 
        mprintf("@ CxIntArray::Add(long)...");
158
 
#endif
159
 
        if (pos >= m_iMaxSize)
160
 
        {
161
 
#ifdef DEBUG_CINTARRAY
162
 
                s = true;
163
 
                mprintf("\n");
164
 
#endif
165
 
                SetMaxSize(pos+1);
166
 
        }
167
 
        m_pData[pos] = f;
168
 
        if (pos >= m_iSize)
169
 
//      {
170
 
//              for (z=m_iSize;z<pos;z++)
171
 
//                      m_pData[z] = 0;
172
 
                m_iSize = pos+1;
173
 
//      }
174
 
#ifdef DEBUG_CINTARRAY
175
 
        if (s)
176
 
                mprintf("@ done.\n");
177
 
        else mprintf("done.\n");
178
 
#endif
179
 
        BXOUT;
180
 
}
181
 
 
182
 
        
183
 
void CxIntArray::Add(int f)
184
 
{
185
 
        BXIN;
186
 
#ifdef DEBUG_CINTARRAY
187
 
        bool s = false;
188
 
        mprintf("@ CxIntArray::Add(long)...");
189
 
#endif
190
 
        if (m_iSize+1 > m_iMaxSize)
191
 
        {
192
 
#ifdef DEBUG_CINTARRAY
193
 
                s = true;
194
 
                mprintf("\n");
195
 
#endif
196
 
//              SetMaxSize(m_iMaxSize + m_iGrow);
197
 
                if (m_iMaxSize == 0)
198
 
                        SetMaxSize(m_iMaxSize + m_iGrow);
199
 
                                else SetMaxSize(m_iMaxSize*2);
200
 
        }
201
 
        m_pData[m_iSize] = f;
202
 
        m_iSize++;
203
 
#ifdef DEBUG_CINTARRAY
204
 
        if (s)
205
 
                mprintf("@ done.\n");
206
 
                        else mprintf("done.\n");
207
 
#endif
208
 
        BXOUT;
209
 
}
210
 
 
211
 
        
212
 
void CxIntArray::SetSize(unsigned int i)
213
 
{
214
 
        BXIN;
215
 
#ifdef DEBUG_CINTARRAY
216
 
        mprintf("@ CxIntArray::SetSize(int): %d...",i);
217
 
#endif
218
 
        if (m_iSize == i)
219
 
                return;
220
 
        int *temp;
221
 
 
222
 
        try { temp = new int[i]; } catch(...) { temp = NULL; }
223
 
        if (temp == NULL) NewException((double)i*sizeof(int),__FILE__,__LINE__,__PRETTY_FUNCTION__,m_sName);
224
 
        
225
 
        if (m_iSize > i)
226
 
                memcpy(temp,m_pData,i*sizeof(int));
227
 
                        else memcpy(temp,m_pData,m_iSize*sizeof(int));
228
 
        if (m_pData != NULL)
229
 
                delete[] m_pData;
230
 
        m_pData = temp;
231
 
        m_iMaxSize = i;
232
 
        m_iSize = i;
233
 
#ifdef DEBUG_CINTARRAY
234
 
        mprintf("done.\n");
235
 
#endif
236
 
        BXOUT;
237
 
}
238
 
 
239
 
 
240
 
void CxIntArray::SetMaxSize(unsigned int i)
241
 
{
242
 
        BXIN;
243
 
#ifdef DEBUG_CINTARRAY
244
 
        mprintf("@ CxIntArray::SetMaxSize(int): %d...",i);
245
 
#endif
246
 
        int *temp;
247
 
 
248
 
        try { temp = new int[i]; } catch(...) { temp = NULL; }
249
 
        if (temp == NULL) NewException((double)i*sizeof(int),__FILE__,__LINE__,__PRETTY_FUNCTION__,m_sName);
250
 
        
251
 
        memcpy(temp,m_pData,m_iSize*sizeof(int));
252
 
        if (m_pData != NULL)
253
 
                delete[] m_pData;
254
 
        m_pData = temp;
255
 
        m_iMaxSize = i;
256
 
#ifdef DEBUG_CINTARRAY
257
 
        mprintf("done.\n");
258
 
#endif
259
 
        BXOUT;
260
 
}
261
 
 
262
 
        
263
 
void CxIntArray::SetGrow(unsigned int i)
264
 
{
265
 
        BXIN;
266
 
#ifdef DEBUG_CINTARRAY
267
 
        mprintf("@ CxIntArray::SetGrow(int): %d\n",i);
268
 
#endif
269
 
        m_iGrow = i;
270
 
        BXOUT;
271
 
}
272
 
                
273
 
        
274
 
void CxIntArray::RemoveAll()
275
 
{
276
 
        BXIN;
277
 
#ifdef DEBUG_CINTARRAY
278
 
        mprintf("@ CxIntArray::RemoveAll():...");
279
 
#endif
280
 
        if (m_pData != NULL)
281
 
                delete[] m_pData;
282
 
        m_pData = NULL;
283
 
        m_iSize = 0;
284
 
        m_iMaxSize = 0;
285
 
#ifdef DEBUG_CINTARRAY
286
 
        mprintf("done.\n");
287
 
#endif
288
 
        BXOUT;
289
 
}
290
 
 
291
 
 
292
 
void CxIntArray::RemoveAll_KeepSize()
293
 
{
294
 
        BXIN;
295
 
#ifdef DEBUG_CINTARRAY
296
 
        mprintf("@ CxIntArray::RemoveAll_KeepSize():...");
297
 
#endif
298
 
        m_iSize = 0;
299
 
#ifdef DEBUG_CINTARRAY
300
 
        mprintf("done.\n");
301
 
#endif
302
 
        BXOUT;
303
 
}
304
 
 
305
 
        
306
 
void CxIntArray::RemoveAt(unsigned int pos, unsigned int count)
307
 
{
308
 
        BXIN;
309
 
        int *temp;
310
 
                
311
 
#ifdef DEBUG_CINTARRAY
312
 
        mprintf("@ CxIntArray::RemoveAt(int, int): %d, %d...",pos,count);
313
 
#endif
314
 
 
315
 
        try { temp = new int[m_iSize-count]; } catch(...) { temp = NULL; }
316
 
        if (temp == NULL) NewException((double)(m_iSize-count)*sizeof(int),__FILE__,__LINE__,__PRETTY_FUNCTION__,m_sName);
317
 
        
318
 
        memcpy(temp,m_pData,pos*sizeof(int));
319
 
        memcpy(&temp[pos],&m_pData[pos+count],(m_iSize-pos-count)*sizeof(int));
320
 
        delete[] m_pData;
321
 
        m_pData = temp;
322
 
        m_iSize-=count;
323
 
        m_iMaxSize = m_iSize;
324
 
#ifdef DEBUG_CINTARRAY
325
 
        mprintf("done.\n");
326
 
#endif
327
 
        BXOUT;
328
 
}
329
 
 
330
 
 
331
 
void CxIntArray::RemoveAt_KeepSize(unsigned int pos, unsigned int count)
332
 
{
333
 
        BXIN;
334
 
        int *temp;
335
 
                
336
 
#ifdef DEBUG_CINTARRAY
337
 
        mprintf("@ CxIntArray::RemoveAt_KeepSize(int, int): %d, %d...",pos,count);
338
 
#endif
339
 
 
340
 
        try { temp = new int[m_iMaxSize]; } catch(...) { temp = NULL; }
341
 
        if (temp == NULL) NewException((double)m_iMaxSize*sizeof(int),__FILE__,__LINE__,__PRETTY_FUNCTION__,m_sName);
342
 
        
343
 
        memcpy(temp,m_pData,pos*sizeof(int));
344
 
        memcpy(&temp[pos],&m_pData[pos+count],(m_iSize-pos-count)*sizeof(int));
345
 
        delete[] m_pData;
346
 
        m_pData = temp;
347
 
        m_iSize-=count;
348
 
#ifdef DEBUG_CINTARRAY
349
 
        mprintf("done.\n");
350
 
#endif
351
 
        BXOUT;
352
 
}
353
 
 
354
 
        
355
 
void CxIntArray::InsertAt(int f, unsigned int pos)
356
 
{
357
 
        BXIN;
358
 
        int *temp;
359
 
                
360
 
#ifdef DEBUG_CINTARRAY
361
 
        mprintf("@ CxIntArray::InsertAt(long, int): %d...");
362
 
#endif
363
 
 
364
 
        try { temp = new int[m_iSize+1]; } catch(...) { temp = NULL; }
365
 
        if (temp == NULL) NewException((double)(m_iSize+1)*sizeof(int),__FILE__,__LINE__,__PRETTY_FUNCTION__,m_sName);
366
 
        
367
 
        memcpy(temp,m_pData,pos*sizeof(int));
368
 
        temp[pos] = f;
369
 
        memcpy(&temp[pos+1],&m_pData[pos],(m_iSize-pos)*sizeof(int));
370
 
        delete[] m_pData;
371
 
        m_pData = temp;
372
 
        m_iSize++;
373
 
        m_iMaxSize = m_iSize;
374
 
#ifdef DEBUG_CINTARRAY
375
 
        mprintf("done.\n");
376
 
#endif
377
 
        BXOUT;
378
 
}
379
 
 
380
 
 
381
 
void CxIntArray::SetName(const char *name)
382
 
{
383
 
        (void)name;
384
 
#ifdef DEBUG_ARRAYS
385
 
        BXIN;
386
 
#ifdef DEBUG_CINTARRAY
387
 
        mprintf("@ CxIntArray::SetName(const char *): \"%s\"...",name);
388
 
#endif
389
 
        if (m_sName != NULL)
390
 
                delete[] m_sName;
391
 
        try { m_sName = new char[strlen(name)+1]; } catch(...) { m_sName = NULL; }
392
 
        if (m_sName == NULL) NewException((double)(strlen(name)+1)*sizeof(char),__FILE__,__LINE__,__PRETTY_FUNCTION__);
393
 
        strcpy(m_sName,name);
394
 
#ifdef DEBUG_CINTARRAY
395
 
        mprintf("done.\n");
396
 
#endif
397
 
        BXOUT;
398
 
#endif
399
 
}
 
1
/*****************************************************************************
 
2
    TRAVIS - Trajectory Analyzer and Visualizer
 
3
    http://www.travis-analyzer.de/
 
4
 
 
5
    Copyright (c) 2009-2014 Martin Brehm
 
6
                  2012-2014 Martin Thomas
 
7
 
 
8
    This file written by Martin Brehm.
 
9
 
 
10
    This program is free software: you can redistribute it and/or modify
 
11
    it under the terms of the GNU General Public License as published by
 
12
    the Free Software Foundation, either version 3 of the License, or
 
13
    (at your option) any later version.
 
14
 
 
15
    This program is distributed in the hope that it will be useful,
 
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
    GNU General Public License for more details.
 
19
 
 
20
    You should have received a copy of the GNU General Public License
 
21
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
22
*****************************************************************************/
 
23
 
 
24
#include "xintarray.h"
 
25
 
 
26
 
 
27
#ifndef DEBUG_ARRAYS
 
28
#define m_sName (NULL)
 
29
#endif
 
30
 
 
31
 
 
32
CxIntArray::CxIntArray()
 
33
{
 
34
        BXIN;
 
35
#ifdef DEBUG_CINTARRAY
 
36
        mprintf("@ CxIntArray::CxIntArray()\n");
 
37
#endif
 
38
        m_pData = NULL;
 
39
        m_iSize = 0;
 
40
        m_iMaxSize = 0;
 
41
        m_iGrow = 16;
 
42
#ifdef DEBUG_ARRAYS
 
43
        m_sName = NULL;
 
44
#endif
 
45
        BXOUT;
 
46
}
 
47
 
 
48
 
 
49
CxIntArray::CxIntArray(const char *name)
 
50
{
 
51
        BXIN;
 
52
#ifdef DEBUG_CINTARRAY
 
53
        mprintf("@ CxIntArray::CxIntArray(const char *)\n");
 
54
#endif
 
55
        m_pData = NULL;
 
56
        m_iSize = 0;
 
57
        m_iMaxSize = 0;
 
58
        m_iGrow = 16;
 
59
#ifdef DEBUG_ARRAYS
 
60
        m_sName = NULL;
 
61
#endif
 
62
        SetName(name);
 
63
        BXOUT;
 
64
}
 
65
 
 
66
        
 
67
CxIntArray::~CxIntArray()
 
68
{
 
69
        BXIN;
 
70
#ifdef DEBUG_CINTARRAY
 
71
        mprintf("@ CxIntArray::~CxIntArray()\n");
 
72
#endif
 
73
        RemoveAll();
 
74
#ifdef DEBUG_ARRAYS
 
75
        if (m_sName != NULL)
 
76
        {
 
77
                delete[] m_sName;
 
78
                m_sName = NULL;
 
79
        }
 
80
#endif
 
81
        BXOUT;
 
82
}
 
83
 
 
84
        
 
85
CxIntArray::CxIntArray(CxIntArray &o) : CxObject()
 
86
{
 
87
        BXIN;
 
88
#ifdef DEBUG_CINTARRAY
 
89
        mprintf("@ CxIntArray::CxIntArray(CxIntArray &)...");
 
90
#endif
 
91
        unsigned int z;
 
92
        m_iSize = o.m_iSize;
 
93
        m_iMaxSize = o.m_iMaxSize;
 
94
        m_iGrow = o.m_iGrow;
 
95
 
 
96
        try { m_pData = new int[m_iMaxSize]; } catch(...) { m_pData = NULL; }
 
97
        if (m_pData == NULL) NewException((double)m_iMaxSize*sizeof(int),__FILE__,__LINE__,__PRETTY_FUNCTION__,m_sName);
 
98
        
 
99
        for (z=0;z<m_iSize;z++)
 
100
                m_pData[z] = o.m_pData[z];
 
101
#ifdef DEBUG_CINTARRAY
 
102
        mprintf("done.\n");
 
103
#endif
 
104
        BXOUT;
 
105
}
 
106
 
 
107
 
 
108
void CxIntArray::CopyFrom(CxIntArray *o)
 
109
{
 
110
        BXIN;
 
111
#ifdef DEBUG_CINTARRAY
 
112
        mprintf("@ CxIntArray::CopyFrom(CxIntArray*)...");
 
113
#endif
 
114
        m_iSize = o->m_iSize;
 
115
        m_iMaxSize = o->m_iMaxSize;
 
116
        m_iGrow = o->m_iGrow;
 
117
        if (m_pData != NULL)
 
118
                delete[] m_pData;
 
119
 
 
120
        try { m_pData = new int[m_iMaxSize]; } catch(...) { m_pData = NULL; }
 
121
        if (m_pData == NULL) NewException((double)m_iMaxSize*sizeof(int),__FILE__,__LINE__,__PRETTY_FUNCTION__,m_sName);
 
122
        
 
123
        memcpy(m_pData,o->m_pData,m_iSize*sizeof(int));
 
124
#ifdef DEBUG_CINTARRAY
 
125
        mprintf("done.\n");
 
126
#endif
 
127
        BXOUT;
 
128
}
 
129
        
 
130
 
 
131
void CxIntArray::Append(CxIntArray *o)
 
132
{
 
133
        BXIN;
 
134
#ifdef DEBUG_CINTARRAY
 
135
        mprintf("@ CxIntArray::Append(CxIntArray*)...");
 
136
#endif
 
137
//      unsigned int z;
 
138
        if (m_iSize+o->m_iSize > m_iMaxSize)
 
139
                SetMaxSize(m_iSize+o->m_iSize);
 
140
//      for (z=0;z<o->m_iSize;z++)
 
141
//              m_pData[m_iSize+z] = o->m_pData[z];
 
142
        memcpy(&m_pData[m_iSize],o->m_pData,o->m_iSize*sizeof(int));
 
143
        m_iSize += o->m_iSize;
 
144
#ifdef DEBUG_CINTARRAY
 
145
        mprintf("done.\n");
 
146
#endif
 
147
        BXOUT;
 
148
}       
 
149
 
 
150
 
 
151
void CxIntArray::SetAt(unsigned int pos, int f)
 
152
{
 
153
        BXIN;
 
154
//      unsigned int z;
 
155
#ifdef DEBUG_CINTARRAY
 
156
        bool s = false;
 
157
        mprintf("@ CxIntArray::Add(long)...");
 
158
#endif
 
159
        if (pos >= m_iMaxSize)
 
160
        {
 
161
#ifdef DEBUG_CINTARRAY
 
162
                s = true;
 
163
                mprintf("\n");
 
164
#endif
 
165
                SetMaxSize(pos+1);
 
166
        }
 
167
        m_pData[pos] = f;
 
168
        if (pos >= m_iSize)
 
169
//      {
 
170
//              for (z=m_iSize;z<pos;z++)
 
171
//                      m_pData[z] = 0;
 
172
                m_iSize = pos+1;
 
173
//      }
 
174
#ifdef DEBUG_CINTARRAY
 
175
        if (s)
 
176
                mprintf("@ done.\n");
 
177
        else mprintf("done.\n");
 
178
#endif
 
179
        BXOUT;
 
180
}
 
181
 
 
182
        
 
183
void CxIntArray::Add(int f)
 
184
{
 
185
        BXIN;
 
186
#ifdef DEBUG_CINTARRAY
 
187
        bool s = false;
 
188
        mprintf("@ CxIntArray::Add(long)...");
 
189
#endif
 
190
        if (m_iSize+1 > m_iMaxSize)
 
191
        {
 
192
#ifdef DEBUG_CINTARRAY
 
193
                s = true;
 
194
                mprintf("\n");
 
195
#endif
 
196
//              SetMaxSize(m_iMaxSize + m_iGrow);
 
197
                if (m_iMaxSize == 0)
 
198
                        SetMaxSize(m_iMaxSize + m_iGrow);
 
199
                                else SetMaxSize(m_iMaxSize*2);
 
200
        }
 
201
        m_pData[m_iSize] = f;
 
202
        m_iSize++;
 
203
#ifdef DEBUG_CINTARRAY
 
204
        if (s)
 
205
                mprintf("@ done.\n");
 
206
                        else mprintf("done.\n");
 
207
#endif
 
208
        BXOUT;
 
209
}
 
210
 
 
211
        
 
212
void CxIntArray::SetSize(unsigned int i)
 
213
{
 
214
        BXIN;
 
215
#ifdef DEBUG_CINTARRAY
 
216
        mprintf("@ CxIntArray::SetSize(int): %d...",i);
 
217
#endif
 
218
        if (m_iSize == i)
 
219
                return;
 
220
        int *temp;
 
221
 
 
222
        try { temp = new int[i]; } catch(...) { temp = NULL; }
 
223
        if (temp == NULL) NewException((double)i*sizeof(int),__FILE__,__LINE__,__PRETTY_FUNCTION__,m_sName);
 
224
        
 
225
        if (m_iSize > i)
 
226
                memcpy(temp,m_pData,i*sizeof(int));
 
227
                        else memcpy(temp,m_pData,m_iSize*sizeof(int));
 
228
        if (m_pData != NULL)
 
229
                delete[] m_pData;
 
230
        m_pData = temp;
 
231
        m_iMaxSize = i;
 
232
        m_iSize = i;
 
233
#ifdef DEBUG_CINTARRAY
 
234
        mprintf("done.\n");
 
235
#endif
 
236
        BXOUT;
 
237
}
 
238
 
 
239
 
 
240
void CxIntArray::SetMaxSize(unsigned int i)
 
241
{
 
242
        BXIN;
 
243
#ifdef DEBUG_CINTARRAY
 
244
        mprintf("@ CxIntArray::SetMaxSize(int): %d...",i);
 
245
#endif
 
246
        int *temp;
 
247
 
 
248
        try { temp = new int[i]; } catch(...) { temp = NULL; }
 
249
        if (temp == NULL) NewException((double)i*sizeof(int),__FILE__,__LINE__,__PRETTY_FUNCTION__,m_sName);
 
250
        
 
251
        memcpy(temp,m_pData,m_iSize*sizeof(int));
 
252
        if (m_pData != NULL)
 
253
                delete[] m_pData;
 
254
        m_pData = temp;
 
255
        m_iMaxSize = i;
 
256
#ifdef DEBUG_CINTARRAY
 
257
        mprintf("done.\n");
 
258
#endif
 
259
        BXOUT;
 
260
}
 
261
 
 
262
        
 
263
void CxIntArray::SetGrow(unsigned int i)
 
264
{
 
265
        BXIN;
 
266
#ifdef DEBUG_CINTARRAY
 
267
        mprintf("@ CxIntArray::SetGrow(int): %d\n",i);
 
268
#endif
 
269
        m_iGrow = i;
 
270
        BXOUT;
 
271
}
 
272
                
 
273
        
 
274
void CxIntArray::RemoveAll()
 
275
{
 
276
        BXIN;
 
277
#ifdef DEBUG_CINTARRAY
 
278
        mprintf("@ CxIntArray::RemoveAll():...");
 
279
#endif
 
280
        if (m_pData != NULL)
 
281
                delete[] m_pData;
 
282
        m_pData = NULL;
 
283
        m_iSize = 0;
 
284
        m_iMaxSize = 0;
 
285
#ifdef DEBUG_CINTARRAY
 
286
        mprintf("done.\n");
 
287
#endif
 
288
        BXOUT;
 
289
}
 
290
 
 
291
 
 
292
void CxIntArray::RemoveAll_KeepSize()
 
293
{
 
294
        BXIN;
 
295
#ifdef DEBUG_CINTARRAY
 
296
        mprintf("@ CxIntArray::RemoveAll_KeepSize():...");
 
297
#endif
 
298
        m_iSize = 0;
 
299
#ifdef DEBUG_CINTARRAY
 
300
        mprintf("done.\n");
 
301
#endif
 
302
        BXOUT;
 
303
}
 
304
 
 
305
        
 
306
void CxIntArray::RemoveAt(unsigned int pos, unsigned int count)
 
307
{
 
308
        BXIN;
 
309
        int *temp;
 
310
                
 
311
#ifdef DEBUG_CINTARRAY
 
312
        mprintf("@ CxIntArray::RemoveAt(int, int): %d, %d...",pos,count);
 
313
#endif
 
314
 
 
315
        try { temp = new int[m_iSize-count]; } catch(...) { temp = NULL; }
 
316
        if (temp == NULL) NewException((double)(m_iSize-count)*sizeof(int),__FILE__,__LINE__,__PRETTY_FUNCTION__,m_sName);
 
317
        
 
318
        memcpy(temp,m_pData,pos*sizeof(int));
 
319
        memcpy(&temp[pos],&m_pData[pos+count],(m_iSize-pos-count)*sizeof(int));
 
320
        delete[] m_pData;
 
321
        m_pData = temp;
 
322
        m_iSize-=count;
 
323
        m_iMaxSize = m_iSize;
 
324
#ifdef DEBUG_CINTARRAY
 
325
        mprintf("done.\n");
 
326
#endif
 
327
        BXOUT;
 
328
}
 
329
 
 
330
 
 
331
void CxIntArray::RemoveAt_KeepSize(unsigned int pos, unsigned int count)
 
332
{
 
333
        BXIN;
 
334
        int *temp;
 
335
                
 
336
#ifdef DEBUG_CINTARRAY
 
337
        mprintf("@ CxIntArray::RemoveAt_KeepSize(int, int): %d, %d...",pos,count);
 
338
#endif
 
339
 
 
340
        try { temp = new int[m_iMaxSize]; } catch(...) { temp = NULL; }
 
341
        if (temp == NULL) NewException((double)m_iMaxSize*sizeof(int),__FILE__,__LINE__,__PRETTY_FUNCTION__,m_sName);
 
342
        
 
343
        memcpy(temp,m_pData,pos*sizeof(int));
 
344
        memcpy(&temp[pos],&m_pData[pos+count],(m_iSize-pos-count)*sizeof(int));
 
345
        delete[] m_pData;
 
346
        m_pData = temp;
 
347
        m_iSize-=count;
 
348
#ifdef DEBUG_CINTARRAY
 
349
        mprintf("done.\n");
 
350
#endif
 
351
        BXOUT;
 
352
}
 
353
 
 
354
        
 
355
void CxIntArray::InsertAt(int f, unsigned int pos)
 
356
{
 
357
        BXIN;
 
358
        int *temp;
 
359
                
 
360
#ifdef DEBUG_CINTARRAY
 
361
        mprintf("@ CxIntArray::InsertAt(long, int): %d...");
 
362
#endif
 
363
 
 
364
        try { temp = new int[m_iSize+1]; } catch(...) { temp = NULL; }
 
365
        if (temp == NULL) NewException((double)(m_iSize+1)*sizeof(int),__FILE__,__LINE__,__PRETTY_FUNCTION__,m_sName);
 
366
        
 
367
        memcpy(temp,m_pData,pos*sizeof(int));
 
368
        temp[pos] = f;
 
369
        memcpy(&temp[pos+1],&m_pData[pos],(m_iSize-pos)*sizeof(int));
 
370
        delete[] m_pData;
 
371
        m_pData = temp;
 
372
        m_iSize++;
 
373
        m_iMaxSize = m_iSize;
 
374
#ifdef DEBUG_CINTARRAY
 
375
        mprintf("done.\n");
 
376
#endif
 
377
        BXOUT;
 
378
}
 
379
 
 
380
 
 
381
void CxIntArray::SetName(const char *name)
 
382
{
 
383
        (void)name;
 
384
#ifdef DEBUG_ARRAYS
 
385
        BXIN;
 
386
#ifdef DEBUG_CINTARRAY
 
387
        mprintf("@ CxIntArray::SetName(const char *): \"%s\"...",name);
 
388
#endif
 
389
        if (m_sName != NULL)
 
390
                delete[] m_sName;
 
391
        try { m_sName = new char[strlen(name)+1]; } catch(...) { m_sName = NULL; }
 
392
        if (m_sName == NULL) NewException((double)(strlen(name)+1)*sizeof(char),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
393
        strcpy(m_sName,name);
 
394
#ifdef DEBUG_CINTARRAY
 
395
        mprintf("done.\n");
 
396
#endif
 
397
        BXOUT;
 
398
#endif
 
399
}