Adds the specified item to the collection. The item. The pointer to the allocated item in the storage.
| 241 | /// <param name="item">The item.</param> |
| 242 | /// <returns>The pointer to the allocated item in the storage.</returns> |
| 243 | T* Add(const T& item) |
| 244 | { |
| 245 | // Find first chunk with some space |
| 246 | Chunk* chunk = nullptr; |
| 247 | for (int32 i = 0; i < _chunks.Count(); i++) |
| 248 | { |
| 249 | if (_chunks[i]->Count() < ChunkSize) |
| 250 | { |
| 251 | chunk = _chunks[i]; |
| 252 | break; |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | // Allocate chunk if missing |
| 257 | if (chunk == nullptr) |
| 258 | { |
| 259 | chunk = New<Chunk>(); |
| 260 | chunk->SetCapacity(ChunkSize); |
| 261 | _chunks.Add(chunk); |
| 262 | } |
| 263 | |
| 264 | // Add item |
| 265 | _count++; |
| 266 | chunk->Add(item); |
| 267 | return &chunk->At(chunk->Count() - 1); |
| 268 | } |
| 269 | |
| 270 | /// <summary> |
| 271 | /// Adds the one item to the collection and returns the reference to it. |
no test coverage detected