~ubuntu-branches/ubuntu/trusty/travis/trusty-proposed

« back to all changes in this revision

Viewing changes to src/xwordarray.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 "xwordarray.h"
25
 
 
26
 
 
27
 
#ifndef DEBUG_ARRAYS
28
 
#define m_sName (NULL)
29
 
#endif
30
 
 
31
 
 
32
 
CxWordArray::CxWordArray()
33
 
{
34
 
        BXIN;
35
 
#ifdef DEBUG_CWORDARRAY
36
 
        mprintf("@ CxWordArray::CxWordArray()\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
 
CxWordArray::CxWordArray(const char *name)
50
 
{
51
 
        BXIN;
52
 
#ifdef DEBUG_CWORDARRAY
53
 
        mprintf("@ CxWordArray::CxWordArray(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
 
CxWordArray::~CxWordArray()
68
 
{
69
 
        BXIN;
70
 
#ifdef DEBUG_CWORDARRAY
71
 
        mprintf("@ CxWordArray::~CxWordArray()\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
 
CxWordArray::CxWordArray(CxWordArray &o) : CxObject()
86
 
{
87
 
        BXIN;
88
 
#ifdef DEBUG_CWORDARRAY
89
 
        mprintf("@ CxWordArray::CxWordArray(CxWordArray &)...");
90
 
#endif
91
 
        unsigned long 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 unsigned short[m_iMaxSize]; } catch(...) { m_pData = NULL; }
97
 
        if (m_pData == NULL) NewException((double)m_iMaxSize*sizeof(unsigned short),__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_CWORDARRAY
102
 
        mprintf("done.\n");
103
 
#endif
104
 
        BXOUT;
105
 
}
106
 
 
107
 
 
108
 
void CxWordArray::CopyFrom(CxWordArray *o)
109
 
{
110
 
        BXIN;
111
 
#ifdef DEBUG_CWORDARRAY
112
 
        mprintf("@ CxWordArray::CopyFrom(CxWordArray*)...");
113
 
#endif
114
 
        if (m_iMaxSize != o->m_iMaxSize)
115
 
        {
116
 
                m_iMaxSize = o->m_iMaxSize;
117
 
                if (m_pData != NULL)
118
 
                        delete[] m_pData;
119
 
 
120
 
                try { m_pData = new unsigned short[m_iMaxSize]; } catch(...) { m_pData = NULL; }
121
 
                if (m_pData == NULL) NewException((double)m_iMaxSize*sizeof(unsigned short),__FILE__,__LINE__,__PRETTY_FUNCTION__,m_sName);
122
 
        }
123
 
        m_iSize = o->m_iSize;
124
 
        m_iGrow = o->m_iGrow;
125
 
        memcpy(m_pData,o->m_pData,m_iSize*sizeof(unsigned short));
126
 
#ifdef DEBUG_CWORDARRAY
127
 
        mprintf("done.\n");
128
 
#endif
129
 
        BXOUT;
130
 
}       
131
 
 
132
 
 
133
 
void CxWordArray::Append(CxWordArray *o)
134
 
{
135
 
        BXIN;
136
 
#ifdef DEBUG_CWORDARRAY
137
 
        mprintf("@ CxWordArray::Append(CxWordArray*)...");
138
 
#endif
139
 
//      unsigned long z;
140
 
        if (m_iSize+o->m_iSize > m_iMaxSize)
141
 
                SetMaxSize(m_iSize+o->m_iSize);
142
 
//      for (z=0;z<o->m_iSize;z++)
143
 
//              m_pData[m_iSize+z] = o->m_pData[z];
144
 
        memcpy(&m_pData[m_iSize],o->m_pData,o->m_iSize*sizeof(unsigned short));
145
 
        m_iSize += o->m_iSize;
146
 
#ifdef DEBUG_CWORDARRAY
147
 
        mprintf("done.\n");
148
 
#endif
149
 
        BXOUT;
150
 
}
151
 
        
152
 
 
153
 
void CxWordArray::SetAt(unsigned long pos, unsigned short f)
154
 
{
155
 
        BXIN;
156
 
//      unsigned long z;
157
 
#ifdef DEBUG_CWORDARRAY
158
 
        bool s = false;
159
 
        mprintf("@ CxWordArray::Add(unsigned short)...");
160
 
#endif
161
 
        if (pos >= m_iMaxSize)
162
 
        {
163
 
#ifdef DEBUG_CWORDARRAY
164
 
                s = true;
165
 
                mprintf("\n");
166
 
#endif
167
 
                SetMaxSize(pos+1);
168
 
        }
169
 
        m_pData[pos] = f;
170
 
        if (pos >= m_iSize)
171
 
//      {
172
 
//              for (z=m_iSize;z<pos;z++)
173
 
//                      m_pData[z] = 0;
174
 
                m_iSize = pos+1;
175
 
//      }
176
 
#ifdef DEBUG_CWORDARRAY
177
 
        if (s)
178
 
                mprintf("@ done.\n");
179
 
        else mprintf("done.\n");
180
 
#endif
181
 
        BXOUT;
182
 
}
183
 
 
184
 
        
185
 
void CxWordArray::Add(unsigned short f)
186
 
{
187
 
        BXIN;
188
 
#ifdef DEBUG_CWORDARRAY
189
 
        bool s = false;
190
 
        mprintf("@ CxWordArray::Add(unsigned short)...");
191
 
#endif
192
 
        if (m_iSize+1 > m_iMaxSize)
193
 
        {
194
 
#ifdef DEBUG_CWORDARRAY
195
 
                s = true;
196
 
                mprintf("\n");
197
 
#endif
198
 
//              SetMaxSize(m_iMaxSize + m_iGrow);
199
 
                if (m_iMaxSize == 0)
200
 
                        SetMaxSize(m_iMaxSize + m_iGrow);
201
 
                                else SetMaxSize(m_iMaxSize*2);
202
 
        }
203
 
        m_pData[m_iSize] = f;
204
 
        m_iSize++;
205
 
#ifdef DEBUG_CWORDARRAY
206
 
        if (s)
207
 
                mprintf("@ done.\n");
208
 
                        else mprintf("done.\n");
209
 
#endif
210
 
        BXOUT;
211
 
}
212
 
 
213
 
        
214
 
void CxWordArray::SetSize(unsigned long i)
215
 
{
216
 
        BXIN;
217
 
#ifdef DEBUG_CWORDARRAY
218
 
        mprintf("@ CxWordArray::SetSize(int): %d...",i);
219
 
#endif
220
 
        if (m_iSize == i)
221
 
                return;
222
 
        unsigned short *temp;
223
 
 
224
 
        try { temp = new unsigned short[i]; } catch(...) { temp = NULL; }
225
 
        if (temp == NULL) NewException((double)i*sizeof(unsigned short),__FILE__,__LINE__,__PRETTY_FUNCTION__,m_sName);
226
 
        
227
 
        if (m_iSize > i)
228
 
                memcpy(temp,m_pData,i*sizeof(unsigned short));
229
 
                        else memcpy(temp,m_pData,m_iSize*sizeof(unsigned short));
230
 
        if (m_pData != NULL)
231
 
                delete[] m_pData;
232
 
        m_pData = temp;
233
 
        m_iMaxSize = i;
234
 
        m_iSize = i;
235
 
#ifdef DEBUG_CWORDARRAY
236
 
        mprintf("done.\n");
237
 
#endif
238
 
        BXOUT;
239
 
}
240
 
 
241
 
 
242
 
void CxWordArray::GrowBy(unsigned long i)
243
 
{
244
 
        BXIN;
245
 
#ifdef DEBUG_CWORDARRAY
246
 
        mprintf("@ CxWordArray::GrowBy(unsigned long): %d...",i);
247
 
#endif
248
 
        if (i == 0)
249
 
                return;
250
 
        unsigned short *temp;
251
 
 
252
 
        try { temp = new unsigned short[m_iSize+i]; } catch(...) { temp = NULL; }
253
 
        if (temp == NULL) NewException((double)(m_iSize+i)*sizeof(unsigned short),__FILE__,__LINE__,__PRETTY_FUNCTION__,m_sName);
254
 
        
255
 
        memcpy(temp,m_pData,m_iSize*sizeof(unsigned short));
256
 
        if (m_pData != NULL)
257
 
                delete[] m_pData;
258
 
        m_pData = temp;
259
 
        m_iMaxSize = i;
260
 
        m_iSize = i;
261
 
#ifdef DEBUG_CWORDARRAY
262
 
        mprintf("done.\n");
263
 
#endif
264
 
        BXOUT;
265
 
}
266
 
 
267
 
 
268
 
void CxWordArray::SetMaxSize(unsigned long i)
269
 
{
270
 
        BXIN;
271
 
#ifdef DEBUG_CWORDARRAY
272
 
        mprintf("@ CxWordArray::SetMaxSize(int): %d...",i);
273
 
#endif
274
 
        unsigned short *temp;
275
 
 
276
 
        try { temp = new unsigned short[i]; } catch(...) { temp = NULL; }
277
 
        if (temp == NULL) NewException((double)i*sizeof(unsigned short),__FILE__,__LINE__,__PRETTY_FUNCTION__,m_sName);
278
 
        
279
 
        memcpy(temp,m_pData,m_iSize*sizeof(unsigned short));
280
 
        if (m_pData != NULL)
281
 
                delete[] m_pData;
282
 
        m_pData = temp;
283
 
        m_iMaxSize = i;
284
 
#ifdef DEBUG_CWORDARRAY
285
 
        mprintf("done.\n");
286
 
#endif
287
 
        BXOUT;
288
 
}
289
 
 
290
 
        
291
 
void CxWordArray::SetGrow(unsigned long i)
292
 
{
293
 
        BXIN;
294
 
#ifdef DEBUG_CWORDARRAY
295
 
        mprintf("@ CxWordArray::SetGrow(int): %d\n",i);
296
 
#endif
297
 
        m_iGrow = i;
298
 
        BXOUT;
299
 
}
300
 
                
301
 
        
302
 
void CxWordArray::RemoveAll()
303
 
{
304
 
        BXIN;
305
 
#ifdef DEBUG_CWORDARRAY
306
 
        mprintf("@ CxWordArray::RemoveAll():...");
307
 
#endif
308
 
        if (m_pData != NULL)
309
 
                delete[] m_pData;
310
 
        m_pData = NULL;
311
 
        m_iSize = 0;
312
 
        m_iMaxSize = 0;
313
 
#ifdef DEBUG_CWORDARRAY
314
 
        mprintf("done.\n");
315
 
#endif
316
 
        BXOUT;
317
 
}
318
 
 
319
 
 
320
 
void CxWordArray::RemoveAll_KeepSize()
321
 
{
322
 
        BXIN;
323
 
#ifdef DEBUG_CWORDARRAY
324
 
        mprintf("@ CxWordArray::RemoveAll_KeepSize():...");
325
 
#endif
326
 
        m_iSize = 0;
327
 
#ifdef DEBUG_CWORDARRAY
328
 
        mprintf("done.\n");
329
 
#endif
330
 
        BXOUT;
331
 
}
332
 
 
333
 
        
334
 
void CxWordArray::RemoveAt(unsigned long pos, unsigned long count)
335
 
{
336
 
        BXIN;
337
 
        unsigned short *temp;
338
 
                
339
 
#ifdef DEBUG_CWORDARRAY
340
 
        mprintf("@ CxWordArray::RemoveAt(int, int): %d, %d...",pos,count);
341
 
#endif
342
 
 
343
 
        try { temp = new unsigned short[m_iSize-count]; } catch(...) { temp = NULL; }
344
 
        if (temp == NULL) NewException((double)(m_iSize-count)*sizeof(unsigned short),__FILE__,__LINE__,__PRETTY_FUNCTION__,m_sName);
345
 
        
346
 
        memcpy(temp,m_pData,pos*sizeof(unsigned short));
347
 
        memcpy(&temp[pos],&m_pData[pos+count],(m_iSize-pos-count)*sizeof(unsigned short));
348
 
        delete[] m_pData;
349
 
        m_pData = temp;
350
 
        m_iSize-=count;
351
 
        m_iMaxSize = m_iSize;
352
 
#ifdef DEBUG_CWORDARRAY
353
 
        mprintf("done.\n");
354
 
#endif
355
 
        BXOUT;
356
 
}
357
 
 
358
 
 
359
 
void CxWordArray::RemoveAt_KeepSize(unsigned long pos, unsigned long count)
360
 
{
361
 
        BXIN;
362
 
        unsigned short *temp;
363
 
                
364
 
#ifdef DEBUG_CWORDARRAY
365
 
        mprintf("@ CxWordArray::RemoveAt_KeepSize(int, int): %d, %d...",pos,count);
366
 
#endif
367
 
 
368
 
        try { temp = new unsigned short[m_iMaxSize]; } catch(...) { temp = NULL; }
369
 
        if (temp == NULL) NewException((double)m_iMaxSize*sizeof(unsigned short),__FILE__,__LINE__,__PRETTY_FUNCTION__,m_sName);
370
 
        
371
 
        memcpy(temp,m_pData,pos*sizeof(unsigned short));
372
 
        memcpy(&temp[pos],&m_pData[pos+count],(m_iSize-pos-count)*sizeof(unsigned short));
373
 
        delete[] m_pData;
374
 
        m_pData = temp;
375
 
        m_iSize-=count;
376
 
#ifdef DEBUG_CWORDARRAY
377
 
        mprintf("done.\n");
378
 
#endif
379
 
        BXOUT;
380
 
}
381
 
 
382
 
        
383
 
void CxWordArray::InsertAt(unsigned short f, unsigned long pos)
384
 
{
385
 
        BXIN;
386
 
        unsigned short *temp;
387
 
                
388
 
#ifdef DEBUG_CWORDARRAY
389
 
        mprintf("@ CxWordArray::InsertAt(unsigned short, int): %d...");
390
 
#endif
391
 
 
392
 
        try { temp = new unsigned short[m_iSize+1]; } catch(...) { temp = NULL; }
393
 
        if (temp == NULL) NewException((double)(m_iSize+1)*sizeof(unsigned short),__FILE__,__LINE__,__PRETTY_FUNCTION__,m_sName);
394
 
        
395
 
        memcpy(temp,m_pData,pos*sizeof(unsigned short));
396
 
        temp[pos] = f;
397
 
        memcpy(&temp[pos+1],&m_pData[pos],(m_iSize-pos)*sizeof(unsigned short));
398
 
        delete[] m_pData;
399
 
        m_pData = temp;
400
 
        m_iSize++;
401
 
        m_iMaxSize = m_iSize;
402
 
#ifdef DEBUG_CWORDARRAY
403
 
        mprintf("done.\n");
404
 
#endif
405
 
        BXOUT;
406
 
}
407
 
 
408
 
 
409
 
void CxWordArray::SetName(const char *name)
410
 
{
411
 
        (void)name;
412
 
#ifdef DEBUG_ARRAYS
413
 
        BXIN;
414
 
#ifdef DEBUG_CWORDARRAY
415
 
        mprintf("@ CxWordArray::SetName(const char *): \"%s\"...",name);
416
 
#endif
417
 
        if (m_sName != NULL)
418
 
                delete[] m_sName;
419
 
        try { m_sName = new char[strlen(name)+1]; } catch(...) { m_sName = NULL; }
420
 
        if (m_sName == NULL) NewException((double)(strlen(name)+1)*sizeof(char),__FILE__,__LINE__,__PRETTY_FUNCTION__);
421
 
        strcpy(m_sName,name);
422
 
#ifdef DEBUG_CWORDARRAY
423
 
        mprintf("done.\n");
424
 
#endif
425
 
        BXOUT;
426
 
#endif
427
 
}
428
 
 
429
 
 
 
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 "xwordarray.h"
 
25
 
 
26
 
 
27
#ifndef DEBUG_ARRAYS
 
28
#define m_sName (NULL)
 
29
#endif
 
30
 
 
31
 
 
32
CxWordArray::CxWordArray()
 
33
{
 
34
        BXIN;
 
35
#ifdef DEBUG_CWORDARRAY
 
36
        mprintf("@ CxWordArray::CxWordArray()\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
CxWordArray::CxWordArray(const char *name)
 
50
{
 
51
        BXIN;
 
52
#ifdef DEBUG_CWORDARRAY
 
53
        mprintf("@ CxWordArray::CxWordArray(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
CxWordArray::~CxWordArray()
 
68
{
 
69
        BXIN;
 
70
#ifdef DEBUG_CWORDARRAY
 
71
        mprintf("@ CxWordArray::~CxWordArray()\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
CxWordArray::CxWordArray(CxWordArray &o) : CxObject()
 
86
{
 
87
        BXIN;
 
88
#ifdef DEBUG_CWORDARRAY
 
89
        mprintf("@ CxWordArray::CxWordArray(CxWordArray &)...");
 
90
#endif
 
91
        unsigned long 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 unsigned short[m_iMaxSize]; } catch(...) { m_pData = NULL; }
 
97
        if (m_pData == NULL) NewException((double)m_iMaxSize*sizeof(unsigned short),__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_CWORDARRAY
 
102
        mprintf("done.\n");
 
103
#endif
 
104
        BXOUT;
 
105
}
 
106
 
 
107
 
 
108
void CxWordArray::CopyFrom(CxWordArray *o)
 
109
{
 
110
        BXIN;
 
111
#ifdef DEBUG_CWORDARRAY
 
112
        mprintf("@ CxWordArray::CopyFrom(CxWordArray*)...");
 
113
#endif
 
114
        if (m_iMaxSize != o->m_iMaxSize)
 
115
        {
 
116
                m_iMaxSize = o->m_iMaxSize;
 
117
                if (m_pData != NULL)
 
118
                        delete[] m_pData;
 
119
 
 
120
                try { m_pData = new unsigned short[m_iMaxSize]; } catch(...) { m_pData = NULL; }
 
121
                if (m_pData == NULL) NewException((double)m_iMaxSize*sizeof(unsigned short),__FILE__,__LINE__,__PRETTY_FUNCTION__,m_sName);
 
122
        }
 
123
        m_iSize = o->m_iSize;
 
124
        m_iGrow = o->m_iGrow;
 
125
        memcpy(m_pData,o->m_pData,m_iSize*sizeof(unsigned short));
 
126
#ifdef DEBUG_CWORDARRAY
 
127
        mprintf("done.\n");
 
128
#endif
 
129
        BXOUT;
 
130
}       
 
131
 
 
132
 
 
133
void CxWordArray::Append(CxWordArray *o)
 
134
{
 
135
        BXIN;
 
136
#ifdef DEBUG_CWORDARRAY
 
137
        mprintf("@ CxWordArray::Append(CxWordArray*)...");
 
138
#endif
 
139
//      unsigned long z;
 
140
        if (m_iSize+o->m_iSize > m_iMaxSize)
 
141
                SetMaxSize(m_iSize+o->m_iSize);
 
142
//      for (z=0;z<o->m_iSize;z++)
 
143
//              m_pData[m_iSize+z] = o->m_pData[z];
 
144
        memcpy(&m_pData[m_iSize],o->m_pData,o->m_iSize*sizeof(unsigned short));
 
145
        m_iSize += o->m_iSize;
 
146
#ifdef DEBUG_CWORDARRAY
 
147
        mprintf("done.\n");
 
148
#endif
 
149
        BXOUT;
 
150
}
 
151
        
 
152
 
 
153
void CxWordArray::SetAt(unsigned long pos, unsigned short f)
 
154
{
 
155
        BXIN;
 
156
//      unsigned long z;
 
157
#ifdef DEBUG_CWORDARRAY
 
158
        bool s = false;
 
159
        mprintf("@ CxWordArray::Add(unsigned short)...");
 
160
#endif
 
161
        if (pos >= m_iMaxSize)
 
162
        {
 
163
#ifdef DEBUG_CWORDARRAY
 
164
                s = true;
 
165
                mprintf("\n");
 
166
#endif
 
167
                SetMaxSize(pos+1);
 
168
        }
 
169
        m_pData[pos] = f;
 
170
        if (pos >= m_iSize)
 
171
//      {
 
172
//              for (z=m_iSize;z<pos;z++)
 
173
//                      m_pData[z] = 0;
 
174
                m_iSize = pos+1;
 
175
//      }
 
176
#ifdef DEBUG_CWORDARRAY
 
177
        if (s)
 
178
                mprintf("@ done.\n");
 
179
        else mprintf("done.\n");
 
180
#endif
 
181
        BXOUT;
 
182
}
 
183
 
 
184
        
 
185
void CxWordArray::Add(unsigned short f)
 
186
{
 
187
        BXIN;
 
188
#ifdef DEBUG_CWORDARRAY
 
189
        bool s = false;
 
190
        mprintf("@ CxWordArray::Add(unsigned short)...");
 
191
#endif
 
192
        if (m_iSize+1 > m_iMaxSize)
 
193
        {
 
194
#ifdef DEBUG_CWORDARRAY
 
195
                s = true;
 
196
                mprintf("\n");
 
197
#endif
 
198
//              SetMaxSize(m_iMaxSize + m_iGrow);
 
199
                if (m_iMaxSize == 0)
 
200
                        SetMaxSize(m_iMaxSize + m_iGrow);
 
201
                                else SetMaxSize(m_iMaxSize*2);
 
202
        }
 
203
        m_pData[m_iSize] = f;
 
204
        m_iSize++;
 
205
#ifdef DEBUG_CWORDARRAY
 
206
        if (s)
 
207
                mprintf("@ done.\n");
 
208
                        else mprintf("done.\n");
 
209
#endif
 
210
        BXOUT;
 
211
}
 
212
 
 
213
        
 
214
void CxWordArray::SetSize(unsigned long i)
 
215
{
 
216
        BXIN;
 
217
#ifdef DEBUG_CWORDARRAY
 
218
        mprintf("@ CxWordArray::SetSize(int): %d...",i);
 
219
#endif
 
220
        if (m_iSize == i)
 
221
                return;
 
222
        unsigned short *temp;
 
223
 
 
224
        try { temp = new unsigned short[i]; } catch(...) { temp = NULL; }
 
225
        if (temp == NULL) NewException((double)i*sizeof(unsigned short),__FILE__,__LINE__,__PRETTY_FUNCTION__,m_sName);
 
226
        
 
227
        if (m_iSize > i)
 
228
                memcpy(temp,m_pData,i*sizeof(unsigned short));
 
229
                        else memcpy(temp,m_pData,m_iSize*sizeof(unsigned short));
 
230
        if (m_pData != NULL)
 
231
                delete[] m_pData;
 
232
        m_pData = temp;
 
233
        m_iMaxSize = i;
 
234
        m_iSize = i;
 
235
#ifdef DEBUG_CWORDARRAY
 
236
        mprintf("done.\n");
 
237
#endif
 
238
        BXOUT;
 
239
}
 
240
 
 
241
 
 
242
void CxWordArray::GrowBy(unsigned long i)
 
243
{
 
244
        BXIN;
 
245
#ifdef DEBUG_CWORDARRAY
 
246
        mprintf("@ CxWordArray::GrowBy(unsigned long): %d...",i);
 
247
#endif
 
248
        if (i == 0)
 
249
                return;
 
250
        unsigned short *temp;
 
251
 
 
252
        try { temp = new unsigned short[m_iSize+i]; } catch(...) { temp = NULL; }
 
253
        if (temp == NULL) NewException((double)(m_iSize+i)*sizeof(unsigned short),__FILE__,__LINE__,__PRETTY_FUNCTION__,m_sName);
 
254
        
 
255
        memcpy(temp,m_pData,m_iSize*sizeof(unsigned short));
 
256
        if (m_pData != NULL)
 
257
                delete[] m_pData;
 
258
        m_pData = temp;
 
259
        m_iMaxSize = i;
 
260
        m_iSize = i;
 
261
#ifdef DEBUG_CWORDARRAY
 
262
        mprintf("done.\n");
 
263
#endif
 
264
        BXOUT;
 
265
}
 
266
 
 
267
 
 
268
void CxWordArray::SetMaxSize(unsigned long i)
 
269
{
 
270
        BXIN;
 
271
#ifdef DEBUG_CWORDARRAY
 
272
        mprintf("@ CxWordArray::SetMaxSize(int): %d...",i);
 
273
#endif
 
274
        unsigned short *temp;
 
275
 
 
276
        try { temp = new unsigned short[i]; } catch(...) { temp = NULL; }
 
277
        if (temp == NULL) NewException((double)i*sizeof(unsigned short),__FILE__,__LINE__,__PRETTY_FUNCTION__,m_sName);
 
278
        
 
279
        memcpy(temp,m_pData,m_iSize*sizeof(unsigned short));
 
280
        if (m_pData != NULL)
 
281
                delete[] m_pData;
 
282
        m_pData = temp;
 
283
        m_iMaxSize = i;
 
284
#ifdef DEBUG_CWORDARRAY
 
285
        mprintf("done.\n");
 
286
#endif
 
287
        BXOUT;
 
288
}
 
289
 
 
290
        
 
291
void CxWordArray::SetGrow(unsigned long i)
 
292
{
 
293
        BXIN;
 
294
#ifdef DEBUG_CWORDARRAY
 
295
        mprintf("@ CxWordArray::SetGrow(int): %d\n",i);
 
296
#endif
 
297
        m_iGrow = i;
 
298
        BXOUT;
 
299
}
 
300
                
 
301
        
 
302
void CxWordArray::RemoveAll()
 
303
{
 
304
        BXIN;
 
305
#ifdef DEBUG_CWORDARRAY
 
306
        mprintf("@ CxWordArray::RemoveAll():...");
 
307
#endif
 
308
        if (m_pData != NULL)
 
309
                delete[] m_pData;
 
310
        m_pData = NULL;
 
311
        m_iSize = 0;
 
312
        m_iMaxSize = 0;
 
313
#ifdef DEBUG_CWORDARRAY
 
314
        mprintf("done.\n");
 
315
#endif
 
316
        BXOUT;
 
317
}
 
318
 
 
319
 
 
320
void CxWordArray::RemoveAll_KeepSize()
 
321
{
 
322
        BXIN;
 
323
#ifdef DEBUG_CWORDARRAY
 
324
        mprintf("@ CxWordArray::RemoveAll_KeepSize():...");
 
325
#endif
 
326
        m_iSize = 0;
 
327
#ifdef DEBUG_CWORDARRAY
 
328
        mprintf("done.\n");
 
329
#endif
 
330
        BXOUT;
 
331
}
 
332
 
 
333
        
 
334
void CxWordArray::RemoveAt(unsigned long pos, unsigned long count)
 
335
{
 
336
        BXIN;
 
337
        unsigned short *temp;
 
338
                
 
339
#ifdef DEBUG_CWORDARRAY
 
340
        mprintf("@ CxWordArray::RemoveAt(int, int): %d, %d...",pos,count);
 
341
#endif
 
342
 
 
343
        try { temp = new unsigned short[m_iSize-count]; } catch(...) { temp = NULL; }
 
344
        if (temp == NULL) NewException((double)(m_iSize-count)*sizeof(unsigned short),__FILE__,__LINE__,__PRETTY_FUNCTION__,m_sName);
 
345
        
 
346
        memcpy(temp,m_pData,pos*sizeof(unsigned short));
 
347
        memcpy(&temp[pos],&m_pData[pos+count],(m_iSize-pos-count)*sizeof(unsigned short));
 
348
        delete[] m_pData;
 
349
        m_pData = temp;
 
350
        m_iSize-=count;
 
351
        m_iMaxSize = m_iSize;
 
352
#ifdef DEBUG_CWORDARRAY
 
353
        mprintf("done.\n");
 
354
#endif
 
355
        BXOUT;
 
356
}
 
357
 
 
358
 
 
359
void CxWordArray::RemoveAt_KeepSize(unsigned long pos, unsigned long count)
 
360
{
 
361
        BXIN;
 
362
        unsigned short *temp;
 
363
                
 
364
#ifdef DEBUG_CWORDARRAY
 
365
        mprintf("@ CxWordArray::RemoveAt_KeepSize(int, int): %d, %d...",pos,count);
 
366
#endif
 
367
 
 
368
        try { temp = new unsigned short[m_iMaxSize]; } catch(...) { temp = NULL; }
 
369
        if (temp == NULL) NewException((double)m_iMaxSize*sizeof(unsigned short),__FILE__,__LINE__,__PRETTY_FUNCTION__,m_sName);
 
370
        
 
371
        memcpy(temp,m_pData,pos*sizeof(unsigned short));
 
372
        memcpy(&temp[pos],&m_pData[pos+count],(m_iSize-pos-count)*sizeof(unsigned short));
 
373
        delete[] m_pData;
 
374
        m_pData = temp;
 
375
        m_iSize-=count;
 
376
#ifdef DEBUG_CWORDARRAY
 
377
        mprintf("done.\n");
 
378
#endif
 
379
        BXOUT;
 
380
}
 
381
 
 
382
        
 
383
void CxWordArray::InsertAt(unsigned short f, unsigned long pos)
 
384
{
 
385
        BXIN;
 
386
        unsigned short *temp;
 
387
                
 
388
#ifdef DEBUG_CWORDARRAY
 
389
        mprintf("@ CxWordArray::InsertAt(unsigned short, int): %d...");
 
390
#endif
 
391
 
 
392
        try { temp = new unsigned short[m_iSize+1]; } catch(...) { temp = NULL; }
 
393
        if (temp == NULL) NewException((double)(m_iSize+1)*sizeof(unsigned short),__FILE__,__LINE__,__PRETTY_FUNCTION__,m_sName);
 
394
        
 
395
        memcpy(temp,m_pData,pos*sizeof(unsigned short));
 
396
        temp[pos] = f;
 
397
        memcpy(&temp[pos+1],&m_pData[pos],(m_iSize-pos)*sizeof(unsigned short));
 
398
        delete[] m_pData;
 
399
        m_pData = temp;
 
400
        m_iSize++;
 
401
        m_iMaxSize = m_iSize;
 
402
#ifdef DEBUG_CWORDARRAY
 
403
        mprintf("done.\n");
 
404
#endif
 
405
        BXOUT;
 
406
}
 
407
 
 
408
 
 
409
void CxWordArray::SetName(const char *name)
 
410
{
 
411
        (void)name;
 
412
#ifdef DEBUG_ARRAYS
 
413
        BXIN;
 
414
#ifdef DEBUG_CWORDARRAY
 
415
        mprintf("@ CxWordArray::SetName(const char *): \"%s\"...",name);
 
416
#endif
 
417
        if (m_sName != NULL)
 
418
                delete[] m_sName;
 
419
        try { m_sName = new char[strlen(name)+1]; } catch(...) { m_sName = NULL; }
 
420
        if (m_sName == NULL) NewException((double)(strlen(name)+1)*sizeof(char),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
421
        strcpy(m_sName,name);
 
422
#ifdef DEBUG_CWORDARRAY
 
423
        mprintf("done.\n");
 
424
#endif
 
425
        BXOUT;
 
426
#endif
 
427
}
 
428
 
 
429