|
@@ -2,25 +2,25 @@
|
|
|
* This file is part of OpenTTD.
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
*/
|
|
|
|
|
|
/** @file array.hpp Array without an explicit maximum size. */
|
|
|
|
|
|
#ifndef ARRAY_HPP
|
|
|
#define ARRAY_HPP
|
|
|
|
|
|
#include "fixedsizearray.hpp"
|
|
|
#include "str.hpp"
|
|
|
#include "../string_func.h"
|
|
|
|
|
|
/**
|
|
|
* Flexible array with size limit. Implemented as fixed size
|
|
|
* array of fixed size arrays
|
|
|
*/
|
|
|
template <class T, uint B = 1024, uint N = B>
|
|
|
class SmallArray {
|
|
|
protected:
|
|
|
typedef FixedSizeArray<T, B> SubArray; ///< inner array
|
|
|
typedef FixedSizeArray<SubArray, N> SuperArray; ///< outer array
|
|
|
|
|
|
static const uint Tcapacity = B * N; ///< total max number of items
|
|
@@ -94,25 +94,25 @@ public:
|
|
|
{
|
|
|
const SubArray &s = data[index / B];
|
|
|
const T &item = s[index % B];
|
|
|
return item;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Helper for creating a human readable output of this data.
|
|
|
* @param dmp The location to dump to.
|
|
|
*/
|
|
|
template <typename D> void Dump(D &dmp) const
|
|
|
{
|
|
|
dmp.WriteLine("capacity = %d", Tcapacity);
|
|
|
dmp.WriteValue("capacity", Tcapacity);
|
|
|
uint num_items = Length();
|
|
|
dmp.WriteLine("num_items = %d", num_items);
|
|
|
CStrA name;
|
|
|
dmp.WriteValue("num_items", num_items);
|
|
|
for (uint i = 0; i < num_items; i++) {
|
|
|
const T &item = (*this)[i];
|
|
|
name.Format("item[%d]", i);
|
|
|
dmp.WriteStructT(name.Data(), &item);
|
|
|
char name[32];
|
|
|
seprintf(name, lastof(name), "item[%d]", i);
|
|
|
dmp.WriteStructT(name, &item);
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
#endif /* ARRAY_HPP */
|