Remove LogMessageEx definition from logging.inc (
bug 5897, r=kyles).
3 * =============================================================================
5 * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
32 #ifndef _INCLUDE_SOURCEMOD_CELLARRAY_H_
33 #define _INCLUDE_SOURCEMOD_CELLARRAY_H_
38 extern HandleType_t htCellArray;
43 CellArray(size_t blocksize) : m_Data(NULL), m_BlockSize(blocksize), m_AllocSize(0), m_Size(0)
63 cell_t *arr = &m_Data[m_Size * m_BlockSize];
68 cell_t *at(size_t b) const
70 return &m_Data[b * m_BlockSize];
73 size_t blocksize() const
83 bool swap(size_t item1, size_t item2)
85 /* Make sure there is extra space available */
91 cell_t *pri = at(item1);
92 cell_t *alt = at(item2);
94 /* Get our temporary array 1 after the limit */
95 cell_t *temp = &m_Data[m_Size * m_BlockSize];
97 memcpy(temp, pri, sizeof(cell_t) * m_BlockSize);
98 memcpy(pri, alt, sizeof(cell_t) * m_BlockSize);
99 memcpy(alt, temp, sizeof(cell_t) * m_BlockSize);
104 void remove(size_t index)
106 /* If we're at the end, take the easy way out */
107 if (index == m_Size - 1)
113 /* Otherwise, it's time to move stuff! */
114 size_t remaining_indexes = (m_Size - 1) - index;
115 cell_t *src = at(index + 1);
116 cell_t *dest = at(index);
117 memmove(dest, src, sizeof(cell_t) * m_BlockSize * remaining_indexes);
122 cell_t *insert_at(size_t index)
124 /* Make sure it'll fit */
125 if (!GrowIfNeeded(1))
130 /* move everything up */
131 cell_t *src = at(index);
132 cell_t *dst = at(index + 1);
133 memmove(dst, src, sizeof(cell_t) * m_BlockSize * (m_Size-index));
140 bool resize(size_t count)
148 if (!GrowIfNeeded(count - m_Size))
159 CellArray *array = new CellArray(m_BlockSize);
160 array->m_AllocSize = m_AllocSize;
161 array->m_Size = m_Size;
162 array->m_Data = (cell_t *)malloc(sizeof(cell_t) * m_BlockSize * m_AllocSize);
163 memcpy(array->m_Data, m_Data, sizeof(cell_t) * m_BlockSize * m_Size);
174 return m_AllocSize * m_BlockSize * sizeof(cell_t);
178 bool GrowIfNeeded(size_t count)
180 /* Shortcut out if we can store this */
181 if (m_Size + count <= m_AllocSize)
185 /* Set a base allocation size of 8 items */
190 /* If it's not enough, keep doubling */
191 while (m_Size + count > m_AllocSize)
195 /* finally, allocate the new block */
198 m_Data = (cell_t *)realloc(m_Data, sizeof(cell_t) * m_BlockSize * m_AllocSize);
200 m_Data = (cell_t *)malloc(sizeof(cell_t) * m_BlockSize * m_AllocSize);
202 return (m_Data != NULL);
211 #endif /* _INCLUDE_SOURCEMOD_CELLARRAY_H_ */