svn-gvsig-desktop / tags / v1_1_1_Build_1021 / libraries / libjni-ecw / include / NCSArray.h @ 37621
History | View | Annotate | Download (3.93 KB)
1 |
/********************************************************
|
---|---|
2 |
** Copyright 1999 Earth Resource Mapping Ltd.
|
3 |
** This document contains proprietary source code of
|
4 |
** Earth Resource Mapping Ltd, and can only be used under
|
5 |
** one of the three licenses as described in the
|
6 |
** license.txt file supplied with this distribution.
|
7 |
** See separate license.txt file for license details
|
8 |
** and conditions.
|
9 |
**
|
10 |
** This software is covered by US patent #6,442,298,
|
11 |
** #6,102,897 and #6,633,688. Rights to use these patents
|
12 |
** is included in the license agreements.
|
13 |
**
|
14 |
** FILE: NCSMalloc.h
|
15 |
** CREATED: Thu Feb 25 09:19:00 WST 1999
|
16 |
** AUTHOR: Simon Cope
|
17 |
** PURPOSE: NCS Memory handling routines.
|
18 |
** EDITS:
|
19 |
*******************************************************/
|
20 |
|
21 |
#ifndef NCSARRAY_H
|
22 |
#define NCSARRAY_H
|
23 |
|
24 |
#ifdef __cplusplus
|
25 |
extern "C" { |
26 |
#endif // __cplusplus |
27 |
|
28 |
#ifndef NCSMALLOC_H
|
29 |
#include "NCSMalloc.h" |
30 |
#endif
|
31 |
|
32 |
/*
|
33 |
** Set to cause arrays to grow/shrink by a granular factor instead of for each element.
|
34 |
*/
|
35 |
#define NCS_ARRAY_GRANULAR
|
36 |
|
37 |
#ifdef NCS_ARRAY_GRANULAR
|
38 |
|
39 |
/*
|
40 |
** Granular array factor (nelements to grow/shrink)
|
41 |
*/
|
42 |
#define NCS_ARRAY_GRANULARITY 16 |
43 |
/*
|
44 |
((void *)pArray) = (void *)NCSRealloc((void *)(pArray), \
|
45 |
((nElements) + NCS_ARRAY_GRANULARITY) * \
|
46 |
sizeof(*(pArray)), \
|
47 |
FALSE); \
|
48 |
*/
|
49 |
|
50 |
#define NCSArrayInsertElement(pArray, nElements, nIndex, pElement) \
|
51 |
if(nElements % NCS_ARRAY_GRANULARITY == 0) { \ |
52 |
void *pData = (void *)NCSRealloc((void *)(pArray), \ |
53 |
((nElements) + NCS_ARRAY_GRANULARITY) * \ |
54 |
sizeof(*(pArray)), \
|
55 |
FALSE); \ |
56 |
pArray = pData; \ |
57 |
} \ |
58 |
if((nIndex) < (nElements)) { \
|
59 |
memmove(&((pArray)[(nIndex) + 1]), \
|
60 |
&((pArray)[(nIndex)]), \ |
61 |
((nElements) - (nIndex)) * sizeof(*(pArray))); \
|
62 |
} \ |
63 |
if(pElement) { \
|
64 |
(pArray)[(nIndex)] = *(pElement); \ |
65 |
} else { \
|
66 |
memset(&((pArray)[(nIndex)]), 0, sizeof(*pArray)); \ |
67 |
} \ |
68 |
(nElements) += 1
|
69 |
|
70 |
#define NCSArrayAppendElement(pArray, nElements, pElement) \
|
71 |
NCSArrayInsertElement(pArray, nElements, nElements, pElement) |
72 |
|
73 |
#define NCSArrayRemoveElement(pArray, nElements, nIndex) \
|
74 |
if((nIndex) < (nElements) - 1) { \ |
75 |
memmove(&((pArray)[(nIndex)]), \ |
76 |
&((pArray)[(nIndex) + 1]), \
|
77 |
((nElements) - (nIndex) - 1) * sizeof(*(pArray))); \ |
78 |
} \ |
79 |
(nElements) -= 1; \
|
80 |
if(nElements % NCS_ARRAY_GRANULARITY == 0) { \ |
81 |
if((nElements) > 0) { \ |
82 |
void *pData = (void *)NCSRealloc((pArray), \ |
83 |
(nElements) * sizeof(*(pArray)), \
|
84 |
FALSE); \ |
85 |
pArray = pData; \ |
86 |
} else { \
|
87 |
NCSFree((pArray)); \ |
88 |
pArray = (void*)NULL; \ |
89 |
} \ |
90 |
} |
91 |
|
92 |
#else /* NCS_ARRAY_GRANULAR */ |
93 |
|
94 |
#define NCSArrayInsertElement(pArray, nElements, nIndex, pElement) \
|
95 |
(pArray) = NCSRealloc((pArray), \ |
96 |
(nElements + 1) * sizeof(*(pArray)), \ |
97 |
TRUE); \ |
98 |
if((nIndex) < (nElements)) { \
|
99 |
memmove(&((pArray)[(nIndex) + 1]), \
|
100 |
&((pArray)[(nIndex)]), \ |
101 |
((nElements) - (nIndex)) * sizeof(*(pArray))); \
|
102 |
} \ |
103 |
if(pElement) { \
|
104 |
(pArray)[(nIndex)] = *(pElement); \ |
105 |
} \ |
106 |
(nElements) += 1
|
107 |
|
108 |
#define NCSArrayAppendElement(pArray, nElements, pElement) \
|
109 |
NCSArrayInsertElement(pArray, nElements, nElements, pElement) |
110 |
|
111 |
#define NCSArrayRemoveElement(pArray, nElements, nIndex) \
|
112 |
if((nIndex) < (nElements) - 1) { \ |
113 |
memmove(&((pArray)[(nIndex)]), \ |
114 |
&((pArray)[(nIndex) + 1]), \
|
115 |
((nElements) - (nIndex) - 1) * sizeof(*(pArray))); \ |
116 |
} \ |
117 |
(nElements) -= 1; \
|
118 |
if((nElements) > 0) { \ |
119 |
(pArray) = NCSRealloc((pArray), \ |
120 |
(nElements) * sizeof(*(pArray)), \
|
121 |
FALSE); \ |
122 |
} else { \
|
123 |
NCSFree((pArray)); \ |
124 |
(pArray) = (void*)NULL; \ |
125 |
} |
126 |
|
127 |
#endif /* NCS_ARRAY_GRANULAR */ |
128 |
|
129 |
#ifdef __cplusplus
|
130 |
} |
131 |
#endif
|
132 |
|
133 |
#endif /* NCSARRAY_H */ |