|
| 1 | +/** |
| 2 | + * vim: set ts=4 : |
| 3 | + * ============================================================================= |
| 4 | + * SourceMod |
| 5 | + * Copyright (C) 2016 AlliedModders LLC. All rights reserved. |
| 6 | + * ============================================================================= |
| 7 | + * |
| 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. |
| 11 | + * |
| 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 |
| 15 | + * details. |
| 16 | + * |
| 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/>. |
| 19 | + * |
| 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>. |
| 28 | + * |
| 29 | + * Version: $Id$ |
| 30 | + */ |
| 31 | + |
| 32 | +#ifndef _INCLUDE_SOURCEMOD_INTERFACE_CELLARRAY_H_ |
| 33 | +#define _INCLUDE_SOURCEMOD_INTERFACE_CELLARRAY_H_ |
| 34 | + |
| 35 | +/** |
| 36 | + * @file ICellArray.h |
| 37 | + * @brief Contains functions for dynamic arrays in plugins. The wrappers |
| 38 | + * for creating these are contained in ISourceMod.h |
| 39 | + */ |
| 40 | + |
| 41 | +namespace SourceMod |
| 42 | +{ |
| 43 | + /** |
| 44 | + * @brief Specifies a dynamic array data structure used in plugins. |
| 45 | + */ |
| 46 | + class ICellArray |
| 47 | + { |
| 48 | + public: |
| 49 | + /** |
| 50 | + * @brief Retrieve the size of the array. |
| 51 | + * |
| 52 | + * @return The size of the array. |
| 53 | + */ |
| 54 | + virtual size_t size() const = 0; |
| 55 | + |
| 56 | + /** |
| 57 | + * @brief Increases the size of the array by one and returns |
| 58 | + * a pointer to the newly added item at the end of the array. |
| 59 | + * |
| 60 | + * @return A pointer to the new item added at the end |
| 61 | + * or NULL if growing the array failed. |
| 62 | + */ |
| 63 | + virtual cell_t *push() = 0; |
| 64 | + |
| 65 | + /** |
| 66 | + * @brief Retrieve a pointer to the memory at a given index. |
| 67 | + * |
| 68 | + * @return A pointer to the memory for item at given index. |
| 69 | + */ |
| 70 | + virtual cell_t *at(size_t index) const = 0; |
| 71 | + |
| 72 | + /** |
| 73 | + * @brief Retrieve the block size set while creating the CellArray. |
| 74 | + * It determines how many cells each array slot has. |
| 75 | + * |
| 76 | + * @return The block size of the array. |
| 77 | + */ |
| 78 | + virtual size_t blocksize() const = 0; |
| 79 | + |
| 80 | + /** |
| 81 | + * @brief Clears an array of all entries. |
| 82 | + * This is the same as Resize(0). |
| 83 | + */ |
| 84 | + virtual void clear() = 0; |
| 85 | + |
| 86 | + /** |
| 87 | + * @brief Swaps two items in the array. |
| 88 | + * |
| 89 | + * @param item1 First index. |
| 90 | + * @param item2 Second index. |
| 91 | + * @return True if items were swapped, false otherwise. |
| 92 | + */ |
| 93 | + virtual bool swap(size_t item1, size_t item2) = 0; |
| 94 | + |
| 95 | + /** |
| 96 | + * @brief Removes an array index, shifting the entire array down from that position |
| 97 | + * on. For example, if item 8 of 10 is removed, the last 3 items will then be |
| 98 | + * (6,7,8) instead of (7,8,9), and all indexes before 8 will remain unchanged. |
| 99 | + * |
| 100 | + * @param index Index in the array to remove at. |
| 101 | + */ |
| 102 | + virtual void remove(size_t index) = 0; |
| 103 | + |
| 104 | + /** |
| 105 | + * @brief Shifts items at the given index and following up by one |
| 106 | + * to make space for a new item at the index. |
| 107 | + * |
| 108 | + * @param index Index in the array to insert at. |
| 109 | + * @return Pointer to item space at the given index or NULL if shifting failed. |
| 110 | + */ |
| 111 | + virtual cell_t *insert_at(size_t index) = 0; |
| 112 | + |
| 113 | + /** |
| 114 | + * @brief Resizes an array. If the size is smaller than the current size, the |
| 115 | + * array is truncated. |
| 116 | + * |
| 117 | + * @param newsize New size |
| 118 | + * @return True if resized, false otherwise. |
| 119 | + */ |
| 120 | + virtual bool resize(size_t newsize) = 0; |
| 121 | + |
| 122 | + /** |
| 123 | + * @brief Clones an array, returning a new object |
| 124 | + * with the same size and data. |
| 125 | + * |
| 126 | + * @return Pointer to cloned array instance. |
| 127 | + */ |
| 128 | + virtual ICellArray *clone() = 0; |
| 129 | + |
| 130 | + /** |
| 131 | + * @brief Retrieve a pointer to the array base. |
| 132 | + * |
| 133 | + * @return Pointer to the array base. |
| 134 | + */ |
| 135 | + virtual cell_t *base() = 0; |
| 136 | + |
| 137 | + /** |
| 138 | + * @brief Retrieve the amount of memory used by this array in bytes. |
| 139 | + * |
| 140 | + * @return Amount of memory used in bytes. |
| 141 | + */ |
| 142 | + virtual size_t mem_usage() = 0; |
| 143 | + }; |
| 144 | +} |
| 145 | + |
| 146 | +#endif //_INCLUDE_SOURCEMOD_INTERFACE_CELLARRAY_H_ |
0 commit comments