summaryrefslogtreecommitdiff
path: root/src/misc
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2010-01-16 14:12:18 +0000
committerfrosch <frosch@openttd.org>2010-01-16 14:12:18 +0000
commite6faf06b687d0d98da2d3bb3a7f294bc701dae38 (patch)
tree5660f9be2961628dd65c9f142a4717f3739c5d4d /src/misc
parent085e9251c5b2ca1d6300a46cf88e7d99207bbeb0 (diff)
downloadopenttd-e6faf06b687d0d98da2d3bb3a7f294bc701dae38.tar.xz
(svn r18824) -Codechange: Turn some public members into protected ones. (skidd13)
Diffstat (limited to 'src/misc')
-rw-r--r--src/misc/array.hpp28
-rw-r--r--src/misc/fixedsizearray.hpp29
2 files changed, 29 insertions, 28 deletions
diff --git a/src/misc/array.hpp b/src/misc/array.hpp
index 414d3efe0..e4cf19408 100644
--- a/src/misc/array.hpp
+++ b/src/misc/array.hpp
@@ -19,16 +19,26 @@
* array of fixed size arrays */
template <class T, uint B = 1024, uint N = B>
class SmallArray {
-public:
+protected:
typedef FixedSizeArray<T, B> SubArray; ///< inner array
typedef FixedSizeArray<SubArray, N> SuperArray; ///< outer array
-protected:
+ static const uint Tcapacity = B * N; ///< total max number of items
+
SuperArray data; ///< array of arrays of items
-public:
- static const uint Tcapacity = B * N; ///< total max number of items
+ /** return first sub-array with free space for new item */
+ FORCEINLINE SubArray& FirstFreeSubArray()
+ {
+ uint super_size = data.Length();
+ if (super_size > 0) {
+ SubArray& s = data[super_size - 1];
+ if (!s.IsFull()) return s;
+ }
+ return data.AppendC();
+ }
+public:
/** implicit constructor */
FORCEINLINE SmallArray() { }
/** Clear (destroy) all items */
@@ -45,16 +55,6 @@ public:
FORCEINLINE bool IsEmpty() { return data.IsEmpty(); }
/** return true if array is full */
FORCEINLINE bool IsFull() { return data.IsFull() && data[N - 1].IsFull(); }
- /** return first sub-array with free space for new item */
- FORCEINLINE SubArray& FirstFreeSubArray()
- {
- uint super_size = data.Length();
- if (super_size > 0) {
- SubArray& s = data[super_size - 1];
- if (!s.IsFull()) return s;
- }
- return data.AppendC();
- }
/** allocate but not construct new item */
FORCEINLINE T& Append() { return FirstFreeSubArray().Append(); }
/** allocate and construct new item */
diff --git a/src/misc/fixedsizearray.hpp b/src/misc/fixedsizearray.hpp
index bb0316e1d..fc57c7934 100644
--- a/src/misc/fixedsizearray.hpp
+++ b/src/misc/fixedsizearray.hpp
@@ -20,10 +20,7 @@
* is delayed. */
template <class T, uint C>
struct FixedSizeArray {
- /** the only member of fixed size array is pointer to the block
- * of C array of items. Header can be found on the offset -sizeof(ArrayHeader). */
- T *data;
-
+protected:
/** header for fixed size array */
struct ArrayHeader
{
@@ -35,6 +32,20 @@ struct FixedSizeArray {
static const uint Tsize = sizeof(T); // size of item
static const uint HeaderSize = sizeof(ArrayHeader); // size of header
+ /** the only member of fixed size array is pointer to the block
+ * of C array of items. Header can be found on the offset -sizeof(ArrayHeader). */
+ T *data;
+
+ /** return reference to the array header (non-const) */
+ FORCEINLINE ArrayHeader& Hdr() { return *(ArrayHeader*)(((byte*)data) - HeaderSize); }
+ /** return reference to the array header (const) */
+ FORCEINLINE const ArrayHeader& Hdr() const { return *(ArrayHeader*)(((byte*)data) - HeaderSize); }
+ /** return reference to the block reference counter */
+ FORCEINLINE uint& RefCnt() { return Hdr().reference_count; }
+ /** return reference to number of used items */
+ FORCEINLINE uint& SizeRef() { return Hdr().items; }
+
+public:
/** Default constructor. Preallocate space for items and header, then initialize header. */
FixedSizeArray()
{
@@ -75,16 +86,6 @@ struct FixedSizeArray {
SizeRef() = 0;
}
-protected:
- /** return reference to the array header (non-const) */
- FORCEINLINE ArrayHeader& Hdr() { return *(ArrayHeader*)(((byte*)data) - HeaderSize); }
- /** return reference to the array header (const) */
- FORCEINLINE const ArrayHeader& Hdr() const { return *(ArrayHeader*)(((byte*)data) - HeaderSize); }
- /** return reference to the block reference counter */
- FORCEINLINE uint& RefCnt() { return Hdr().reference_count; }
- /** return reference to number of used items */
- FORCEINLINE uint& SizeRef() { return Hdr().items; }
-public:
/** return number of used items */
FORCEINLINE uint Length() const { return Hdr().items; }
/** return true if array is full */