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 "xintarray.h"
28
#define m_sName (NULL)
32
CxIntArray::CxIntArray()
35
#ifdef DEBUG_CINTARRAY
36
mprintf("@ CxIntArray::CxIntArray()\n");
49
CxIntArray::CxIntArray(const char *name)
52
#ifdef DEBUG_CINTARRAY
53
mprintf("@ CxIntArray::CxIntArray(const char *)\n");
67
CxIntArray::~CxIntArray()
70
#ifdef DEBUG_CINTARRAY
71
mprintf("@ CxIntArray::~CxIntArray()\n");
85
CxIntArray::CxIntArray(CxIntArray &o) : CxObject()
88
#ifdef DEBUG_CINTARRAY
89
mprintf("@ CxIntArray::CxIntArray(CxIntArray &)...");
93
m_iMaxSize = o.m_iMaxSize;
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);
99
for (z=0;z<m_iSize;z++)
100
m_pData[z] = o.m_pData[z];
101
#ifdef DEBUG_CINTARRAY
108
void CxIntArray::CopyFrom(CxIntArray *o)
111
#ifdef DEBUG_CINTARRAY
112
mprintf("@ CxIntArray::CopyFrom(CxIntArray*)...");
114
m_iSize = o->m_iSize;
115
m_iMaxSize = o->m_iMaxSize;
116
m_iGrow = o->m_iGrow;
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);
123
memcpy(m_pData,o->m_pData,m_iSize*sizeof(int));
124
#ifdef DEBUG_CINTARRAY
131
void CxIntArray::Append(CxIntArray *o)
134
#ifdef DEBUG_CINTARRAY
135
mprintf("@ CxIntArray::Append(CxIntArray*)...");
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
151
void CxIntArray::SetAt(unsigned int pos, int f)
155
#ifdef DEBUG_CINTARRAY
157
mprintf("@ CxIntArray::Add(long)...");
159
if (pos >= m_iMaxSize)
161
#ifdef DEBUG_CINTARRAY
170
// for (z=m_iSize;z<pos;z++)
174
#ifdef DEBUG_CINTARRAY
176
mprintf("@ done.\n");
177
else mprintf("done.\n");
183
void CxIntArray::Add(int f)
186
#ifdef DEBUG_CINTARRAY
188
mprintf("@ CxIntArray::Add(long)...");
190
if (m_iSize+1 > m_iMaxSize)
192
#ifdef DEBUG_CINTARRAY
196
// SetMaxSize(m_iMaxSize + m_iGrow);
198
SetMaxSize(m_iMaxSize + m_iGrow);
199
else SetMaxSize(m_iMaxSize*2);
201
m_pData[m_iSize] = f;
203
#ifdef DEBUG_CINTARRAY
205
mprintf("@ done.\n");
206
else mprintf("done.\n");
212
void CxIntArray::SetSize(unsigned int i)
215
#ifdef DEBUG_CINTARRAY
216
mprintf("@ CxIntArray::SetSize(int): %d...",i);
222
try { temp = new int[i]; } catch(...) { temp = NULL; }
223
if (temp == NULL) NewException((double)i*sizeof(int),__FILE__,__LINE__,__PRETTY_FUNCTION__,m_sName);
226
memcpy(temp,m_pData,i*sizeof(int));
227
else memcpy(temp,m_pData,m_iSize*sizeof(int));
233
#ifdef DEBUG_CINTARRAY
240
void CxIntArray::SetMaxSize(unsigned int i)
243
#ifdef DEBUG_CINTARRAY
244
mprintf("@ CxIntArray::SetMaxSize(int): %d...",i);
248
try { temp = new int[i]; } catch(...) { temp = NULL; }
249
if (temp == NULL) NewException((double)i*sizeof(int),__FILE__,__LINE__,__PRETTY_FUNCTION__,m_sName);
251
memcpy(temp,m_pData,m_iSize*sizeof(int));
256
#ifdef DEBUG_CINTARRAY
263
void CxIntArray::SetGrow(unsigned int i)
266
#ifdef DEBUG_CINTARRAY
267
mprintf("@ CxIntArray::SetGrow(int): %d\n",i);
274
void CxIntArray::RemoveAll()
277
#ifdef DEBUG_CINTARRAY
278
mprintf("@ CxIntArray::RemoveAll():...");
285
#ifdef DEBUG_CINTARRAY
292
void CxIntArray::RemoveAll_KeepSize()
295
#ifdef DEBUG_CINTARRAY
296
mprintf("@ CxIntArray::RemoveAll_KeepSize():...");
299
#ifdef DEBUG_CINTARRAY
306
void CxIntArray::RemoveAt(unsigned int pos, unsigned int count)
311
#ifdef DEBUG_CINTARRAY
312
mprintf("@ CxIntArray::RemoveAt(int, int): %d, %d...",pos,count);
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);
318
memcpy(temp,m_pData,pos*sizeof(int));
319
memcpy(&temp[pos],&m_pData[pos+count],(m_iSize-pos-count)*sizeof(int));
323
m_iMaxSize = m_iSize;
324
#ifdef DEBUG_CINTARRAY
331
void CxIntArray::RemoveAt_KeepSize(unsigned int pos, unsigned int count)
336
#ifdef DEBUG_CINTARRAY
337
mprintf("@ CxIntArray::RemoveAt_KeepSize(int, int): %d, %d...",pos,count);
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);
343
memcpy(temp,m_pData,pos*sizeof(int));
344
memcpy(&temp[pos],&m_pData[pos+count],(m_iSize-pos-count)*sizeof(int));
348
#ifdef DEBUG_CINTARRAY
355
void CxIntArray::InsertAt(int f, unsigned int pos)
360
#ifdef DEBUG_CINTARRAY
361
mprintf("@ CxIntArray::InsertAt(long, int): %d...");
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);
367
memcpy(temp,m_pData,pos*sizeof(int));
369
memcpy(&temp[pos+1],&m_pData[pos],(m_iSize-pos)*sizeof(int));
373
m_iMaxSize = m_iSize;
374
#ifdef DEBUG_CINTARRAY
381
void CxIntArray::SetName(const char *name)
386
#ifdef DEBUG_CINTARRAY
387
mprintf("@ CxIntArray::SetName(const char *): \"%s\"...",name);
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
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 "xintarray.h"
28
#define m_sName (NULL)
32
CxIntArray::CxIntArray()
35
#ifdef DEBUG_CINTARRAY
36
mprintf("@ CxIntArray::CxIntArray()\n");
49
CxIntArray::CxIntArray(const char *name)
52
#ifdef DEBUG_CINTARRAY
53
mprintf("@ CxIntArray::CxIntArray(const char *)\n");
67
CxIntArray::~CxIntArray()
70
#ifdef DEBUG_CINTARRAY
71
mprintf("@ CxIntArray::~CxIntArray()\n");
85
CxIntArray::CxIntArray(CxIntArray &o) : CxObject()
88
#ifdef DEBUG_CINTARRAY
89
mprintf("@ CxIntArray::CxIntArray(CxIntArray &)...");
93
m_iMaxSize = o.m_iMaxSize;
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);
99
for (z=0;z<m_iSize;z++)
100
m_pData[z] = o.m_pData[z];
101
#ifdef DEBUG_CINTARRAY
108
void CxIntArray::CopyFrom(CxIntArray *o)
111
#ifdef DEBUG_CINTARRAY
112
mprintf("@ CxIntArray::CopyFrom(CxIntArray*)...");
114
m_iSize = o->m_iSize;
115
m_iMaxSize = o->m_iMaxSize;
116
m_iGrow = o->m_iGrow;
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);
123
memcpy(m_pData,o->m_pData,m_iSize*sizeof(int));
124
#ifdef DEBUG_CINTARRAY
131
void CxIntArray::Append(CxIntArray *o)
134
#ifdef DEBUG_CINTARRAY
135
mprintf("@ CxIntArray::Append(CxIntArray*)...");
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
151
void CxIntArray::SetAt(unsigned int pos, int f)
155
#ifdef DEBUG_CINTARRAY
157
mprintf("@ CxIntArray::Add(long)...");
159
if (pos >= m_iMaxSize)
161
#ifdef DEBUG_CINTARRAY
170
// for (z=m_iSize;z<pos;z++)
174
#ifdef DEBUG_CINTARRAY
176
mprintf("@ done.\n");
177
else mprintf("done.\n");
183
void CxIntArray::Add(int f)
186
#ifdef DEBUG_CINTARRAY
188
mprintf("@ CxIntArray::Add(long)...");
190
if (m_iSize+1 > m_iMaxSize)
192
#ifdef DEBUG_CINTARRAY
196
// SetMaxSize(m_iMaxSize + m_iGrow);
198
SetMaxSize(m_iMaxSize + m_iGrow);
199
else SetMaxSize(m_iMaxSize*2);
201
m_pData[m_iSize] = f;
203
#ifdef DEBUG_CINTARRAY
205
mprintf("@ done.\n");
206
else mprintf("done.\n");
212
void CxIntArray::SetSize(unsigned int i)
215
#ifdef DEBUG_CINTARRAY
216
mprintf("@ CxIntArray::SetSize(int): %d...",i);
222
try { temp = new int[i]; } catch(...) { temp = NULL; }
223
if (temp == NULL) NewException((double)i*sizeof(int),__FILE__,__LINE__,__PRETTY_FUNCTION__,m_sName);
226
memcpy(temp,m_pData,i*sizeof(int));
227
else memcpy(temp,m_pData,m_iSize*sizeof(int));
233
#ifdef DEBUG_CINTARRAY
240
void CxIntArray::SetMaxSize(unsigned int i)
243
#ifdef DEBUG_CINTARRAY
244
mprintf("@ CxIntArray::SetMaxSize(int): %d...",i);
248
try { temp = new int[i]; } catch(...) { temp = NULL; }
249
if (temp == NULL) NewException((double)i*sizeof(int),__FILE__,__LINE__,__PRETTY_FUNCTION__,m_sName);
251
memcpy(temp,m_pData,m_iSize*sizeof(int));
256
#ifdef DEBUG_CINTARRAY
263
void CxIntArray::SetGrow(unsigned int i)
266
#ifdef DEBUG_CINTARRAY
267
mprintf("@ CxIntArray::SetGrow(int): %d\n",i);
274
void CxIntArray::RemoveAll()
277
#ifdef DEBUG_CINTARRAY
278
mprintf("@ CxIntArray::RemoveAll():...");
285
#ifdef DEBUG_CINTARRAY
292
void CxIntArray::RemoveAll_KeepSize()
295
#ifdef DEBUG_CINTARRAY
296
mprintf("@ CxIntArray::RemoveAll_KeepSize():...");
299
#ifdef DEBUG_CINTARRAY
306
void CxIntArray::RemoveAt(unsigned int pos, unsigned int count)
311
#ifdef DEBUG_CINTARRAY
312
mprintf("@ CxIntArray::RemoveAt(int, int): %d, %d...",pos,count);
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);
318
memcpy(temp,m_pData,pos*sizeof(int));
319
memcpy(&temp[pos],&m_pData[pos+count],(m_iSize-pos-count)*sizeof(int));
323
m_iMaxSize = m_iSize;
324
#ifdef DEBUG_CINTARRAY
331
void CxIntArray::RemoveAt_KeepSize(unsigned int pos, unsigned int count)
336
#ifdef DEBUG_CINTARRAY
337
mprintf("@ CxIntArray::RemoveAt_KeepSize(int, int): %d, %d...",pos,count);
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);
343
memcpy(temp,m_pData,pos*sizeof(int));
344
memcpy(&temp[pos],&m_pData[pos+count],(m_iSize-pos-count)*sizeof(int));
348
#ifdef DEBUG_CINTARRAY
355
void CxIntArray::InsertAt(int f, unsigned int pos)
360
#ifdef DEBUG_CINTARRAY
361
mprintf("@ CxIntArray::InsertAt(long, int): %d...");
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);
367
memcpy(temp,m_pData,pos*sizeof(int));
369
memcpy(&temp[pos+1],&m_pData[pos],(m_iSize-pos)*sizeof(int));
373
m_iMaxSize = m_iSize;
374
#ifdef DEBUG_CINTARRAY
381
void CxIntArray::SetName(const char *name)
386
#ifdef DEBUG_CINTARRAY
387
mprintf("@ CxIntArray::SetName(const char *): \"%s\"...",name);
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