1
/*****************************************************************************
2
TRAVIS - Trajectory Analyzer and Visualizer
3
http://www.travis-analyzer.de/
5
Copyright (c) 2009-2013 Martin Brehm
6
2012-2013 Martin Thomas
8
This file written by Martin Brehm.
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.
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.
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
*****************************************************************************/
24
#include "xwordarray.h"
28
#define m_sName (NULL)
32
CxWordArray::CxWordArray()
35
#ifdef DEBUG_CWORDARRAY
36
mprintf("@ CxWordArray::CxWordArray()\n");
49
CxWordArray::CxWordArray(const char *name)
52
#ifdef DEBUG_CWORDARRAY
53
mprintf("@ CxWordArray::CxWordArray(const char *)\n");
67
CxWordArray::~CxWordArray()
70
#ifdef DEBUG_CWORDARRAY
71
mprintf("@ CxWordArray::~CxWordArray()\n");
85
CxWordArray::CxWordArray(CxWordArray &o) : CxObject()
88
#ifdef DEBUG_CWORDARRAY
89
mprintf("@ CxWordArray::CxWordArray(CxWordArray &)...");
93
m_iMaxSize = o.m_iMaxSize;
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);
99
for (z=0;z<m_iSize;z++)
100
m_pData[z] = o.m_pData[z];
101
#ifdef DEBUG_CWORDARRAY
108
void CxWordArray::CopyFrom(CxWordArray *o)
111
#ifdef DEBUG_CWORDARRAY
112
mprintf("@ CxWordArray::CopyFrom(CxWordArray*)...");
114
if (m_iMaxSize != o->m_iMaxSize)
116
m_iMaxSize = o->m_iMaxSize;
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);
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
133
void CxWordArray::Append(CxWordArray *o)
136
#ifdef DEBUG_CWORDARRAY
137
mprintf("@ CxWordArray::Append(CxWordArray*)...");
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
153
void CxWordArray::SetAt(unsigned long pos, unsigned short f)
157
#ifdef DEBUG_CWORDARRAY
159
mprintf("@ CxWordArray::Add(unsigned short)...");
161
if (pos >= m_iMaxSize)
163
#ifdef DEBUG_CWORDARRAY
172
// for (z=m_iSize;z<pos;z++)
176
#ifdef DEBUG_CWORDARRAY
178
mprintf("@ done.\n");
179
else mprintf("done.\n");
185
void CxWordArray::Add(unsigned short f)
188
#ifdef DEBUG_CWORDARRAY
190
mprintf("@ CxWordArray::Add(unsigned short)...");
192
if (m_iSize+1 > m_iMaxSize)
194
#ifdef DEBUG_CWORDARRAY
198
// SetMaxSize(m_iMaxSize + m_iGrow);
200
SetMaxSize(m_iMaxSize + m_iGrow);
201
else SetMaxSize(m_iMaxSize*2);
203
m_pData[m_iSize] = f;
205
#ifdef DEBUG_CWORDARRAY
207
mprintf("@ done.\n");
208
else mprintf("done.\n");
214
void CxWordArray::SetSize(unsigned long i)
217
#ifdef DEBUG_CWORDARRAY
218
mprintf("@ CxWordArray::SetSize(int): %d...",i);
222
unsigned short *temp;
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);
228
memcpy(temp,m_pData,i*sizeof(unsigned short));
229
else memcpy(temp,m_pData,m_iSize*sizeof(unsigned short));
235
#ifdef DEBUG_CWORDARRAY
242
void CxWordArray::GrowBy(unsigned long i)
245
#ifdef DEBUG_CWORDARRAY
246
mprintf("@ CxWordArray::GrowBy(unsigned long): %d...",i);
250
unsigned short *temp;
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);
255
memcpy(temp,m_pData,m_iSize*sizeof(unsigned short));
261
#ifdef DEBUG_CWORDARRAY
268
void CxWordArray::SetMaxSize(unsigned long i)
271
#ifdef DEBUG_CWORDARRAY
272
mprintf("@ CxWordArray::SetMaxSize(int): %d...",i);
274
unsigned short *temp;
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);
279
memcpy(temp,m_pData,m_iSize*sizeof(unsigned short));
284
#ifdef DEBUG_CWORDARRAY
291
void CxWordArray::SetGrow(unsigned long i)
294
#ifdef DEBUG_CWORDARRAY
295
mprintf("@ CxWordArray::SetGrow(int): %d\n",i);
302
void CxWordArray::RemoveAll()
305
#ifdef DEBUG_CWORDARRAY
306
mprintf("@ CxWordArray::RemoveAll():...");
313
#ifdef DEBUG_CWORDARRAY
320
void CxWordArray::RemoveAll_KeepSize()
323
#ifdef DEBUG_CWORDARRAY
324
mprintf("@ CxWordArray::RemoveAll_KeepSize():...");
327
#ifdef DEBUG_CWORDARRAY
334
void CxWordArray::RemoveAt(unsigned long pos, unsigned long count)
337
unsigned short *temp;
339
#ifdef DEBUG_CWORDARRAY
340
mprintf("@ CxWordArray::RemoveAt(int, int): %d, %d...",pos,count);
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);
346
memcpy(temp,m_pData,pos*sizeof(unsigned short));
347
memcpy(&temp[pos],&m_pData[pos+count],(m_iSize-pos-count)*sizeof(unsigned short));
351
m_iMaxSize = m_iSize;
352
#ifdef DEBUG_CWORDARRAY
359
void CxWordArray::RemoveAt_KeepSize(unsigned long pos, unsigned long count)
362
unsigned short *temp;
364
#ifdef DEBUG_CWORDARRAY
365
mprintf("@ CxWordArray::RemoveAt_KeepSize(int, int): %d, %d...",pos,count);
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);
371
memcpy(temp,m_pData,pos*sizeof(unsigned short));
372
memcpy(&temp[pos],&m_pData[pos+count],(m_iSize-pos-count)*sizeof(unsigned short));
376
#ifdef DEBUG_CWORDARRAY
383
void CxWordArray::InsertAt(unsigned short f, unsigned long pos)
386
unsigned short *temp;
388
#ifdef DEBUG_CWORDARRAY
389
mprintf("@ CxWordArray::InsertAt(unsigned short, int): %d...");
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);
395
memcpy(temp,m_pData,pos*sizeof(unsigned short));
397
memcpy(&temp[pos+1],&m_pData[pos],(m_iSize-pos)*sizeof(unsigned short));
401
m_iMaxSize = m_iSize;
402
#ifdef DEBUG_CWORDARRAY
409
void CxWordArray::SetName(const char *name)
414
#ifdef DEBUG_CWORDARRAY
415
mprintf("@ CxWordArray::SetName(const char *): \"%s\"...",name);
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
1
/*****************************************************************************
2
TRAVIS - Trajectory Analyzer and Visualizer
3
http://www.travis-analyzer.de/
5
Copyright (c) 2009-2014 Martin Brehm
6
2012-2014 Martin Thomas
8
This file written by Martin Brehm.
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.
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.
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
*****************************************************************************/
24
#include "xwordarray.h"
28
#define m_sName (NULL)
32
CxWordArray::CxWordArray()
35
#ifdef DEBUG_CWORDARRAY
36
mprintf("@ CxWordArray::CxWordArray()\n");
49
CxWordArray::CxWordArray(const char *name)
52
#ifdef DEBUG_CWORDARRAY
53
mprintf("@ CxWordArray::CxWordArray(const char *)\n");
67
CxWordArray::~CxWordArray()
70
#ifdef DEBUG_CWORDARRAY
71
mprintf("@ CxWordArray::~CxWordArray()\n");
85
CxWordArray::CxWordArray(CxWordArray &o) : CxObject()
88
#ifdef DEBUG_CWORDARRAY
89
mprintf("@ CxWordArray::CxWordArray(CxWordArray &)...");
93
m_iMaxSize = o.m_iMaxSize;
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);
99
for (z=0;z<m_iSize;z++)
100
m_pData[z] = o.m_pData[z];
101
#ifdef DEBUG_CWORDARRAY
108
void CxWordArray::CopyFrom(CxWordArray *o)
111
#ifdef DEBUG_CWORDARRAY
112
mprintf("@ CxWordArray::CopyFrom(CxWordArray*)...");
114
if (m_iMaxSize != o->m_iMaxSize)
116
m_iMaxSize = o->m_iMaxSize;
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);
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
133
void CxWordArray::Append(CxWordArray *o)
136
#ifdef DEBUG_CWORDARRAY
137
mprintf("@ CxWordArray::Append(CxWordArray*)...");
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
153
void CxWordArray::SetAt(unsigned long pos, unsigned short f)
157
#ifdef DEBUG_CWORDARRAY
159
mprintf("@ CxWordArray::Add(unsigned short)...");
161
if (pos >= m_iMaxSize)
163
#ifdef DEBUG_CWORDARRAY
172
// for (z=m_iSize;z<pos;z++)
176
#ifdef DEBUG_CWORDARRAY
178
mprintf("@ done.\n");
179
else mprintf("done.\n");
185
void CxWordArray::Add(unsigned short f)
188
#ifdef DEBUG_CWORDARRAY
190
mprintf("@ CxWordArray::Add(unsigned short)...");
192
if (m_iSize+1 > m_iMaxSize)
194
#ifdef DEBUG_CWORDARRAY
198
// SetMaxSize(m_iMaxSize + m_iGrow);
200
SetMaxSize(m_iMaxSize + m_iGrow);
201
else SetMaxSize(m_iMaxSize*2);
203
m_pData[m_iSize] = f;
205
#ifdef DEBUG_CWORDARRAY
207
mprintf("@ done.\n");
208
else mprintf("done.\n");
214
void CxWordArray::SetSize(unsigned long i)
217
#ifdef DEBUG_CWORDARRAY
218
mprintf("@ CxWordArray::SetSize(int): %d...",i);
222
unsigned short *temp;
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);
228
memcpy(temp,m_pData,i*sizeof(unsigned short));
229
else memcpy(temp,m_pData,m_iSize*sizeof(unsigned short));
235
#ifdef DEBUG_CWORDARRAY
242
void CxWordArray::GrowBy(unsigned long i)
245
#ifdef DEBUG_CWORDARRAY
246
mprintf("@ CxWordArray::GrowBy(unsigned long): %d...",i);
250
unsigned short *temp;
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);
255
memcpy(temp,m_pData,m_iSize*sizeof(unsigned short));
261
#ifdef DEBUG_CWORDARRAY
268
void CxWordArray::SetMaxSize(unsigned long i)
271
#ifdef DEBUG_CWORDARRAY
272
mprintf("@ CxWordArray::SetMaxSize(int): %d...",i);
274
unsigned short *temp;
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);
279
memcpy(temp,m_pData,m_iSize*sizeof(unsigned short));
284
#ifdef DEBUG_CWORDARRAY
291
void CxWordArray::SetGrow(unsigned long i)
294
#ifdef DEBUG_CWORDARRAY
295
mprintf("@ CxWordArray::SetGrow(int): %d\n",i);
302
void CxWordArray::RemoveAll()
305
#ifdef DEBUG_CWORDARRAY
306
mprintf("@ CxWordArray::RemoveAll():...");
313
#ifdef DEBUG_CWORDARRAY
320
void CxWordArray::RemoveAll_KeepSize()
323
#ifdef DEBUG_CWORDARRAY
324
mprintf("@ CxWordArray::RemoveAll_KeepSize():...");
327
#ifdef DEBUG_CWORDARRAY
334
void CxWordArray::RemoveAt(unsigned long pos, unsigned long count)
337
unsigned short *temp;
339
#ifdef DEBUG_CWORDARRAY
340
mprintf("@ CxWordArray::RemoveAt(int, int): %d, %d...",pos,count);
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);
346
memcpy(temp,m_pData,pos*sizeof(unsigned short));
347
memcpy(&temp[pos],&m_pData[pos+count],(m_iSize-pos-count)*sizeof(unsigned short));
351
m_iMaxSize = m_iSize;
352
#ifdef DEBUG_CWORDARRAY
359
void CxWordArray::RemoveAt_KeepSize(unsigned long pos, unsigned long count)
362
unsigned short *temp;
364
#ifdef DEBUG_CWORDARRAY
365
mprintf("@ CxWordArray::RemoveAt_KeepSize(int, int): %d, %d...",pos,count);
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);
371
memcpy(temp,m_pData,pos*sizeof(unsigned short));
372
memcpy(&temp[pos],&m_pData[pos+count],(m_iSize-pos-count)*sizeof(unsigned short));
376
#ifdef DEBUG_CWORDARRAY
383
void CxWordArray::InsertAt(unsigned short f, unsigned long pos)
386
unsigned short *temp;
388
#ifdef DEBUG_CWORDARRAY
389
mprintf("@ CxWordArray::InsertAt(unsigned short, int): %d...");
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);
395
memcpy(temp,m_pData,pos*sizeof(unsigned short));
397
memcpy(&temp[pos+1],&m_pData[pos],(m_iSize-pos)*sizeof(unsigned short));
401
m_iMaxSize = m_iSize;
402
#ifdef DEBUG_CWORDARRAY
409
void CxWordArray::SetName(const char *name)
414
#ifdef DEBUG_CWORDARRAY
415
mprintf("@ CxWordArray::SetName(const char *): \"%s\"...",name);
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