summaryrefslogtreecommitdiff
path: root/src/misc/fixedsizearray.hpp
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2015-08-08 13:19:38 +0000
committeralberth <alberth@openttd.org>2015-08-08 13:19:38 +0000
commit1105b4d2c99e99750f42b7a39443bb03b40f4afa (patch)
treea936197f608b155036ffd2c553065cc8cbabc014 /src/misc/fixedsizearray.hpp
parentb885d79f506bde93b4ab278b3f84b8ca6254f3b9 (diff)
downloadopenttd-1105b4d2c99e99750f42b7a39443bb03b40f4afa.tar.xz
(svn r27363) -Codechange: Fix codestyle of one-line methods and header codestyle of derived structs.
Diffstat (limited to 'src/misc/fixedsizearray.hpp')
-rw-r--r--src/misc/fixedsizearray.hpp68
1 files changed, 57 insertions, 11 deletions
diff --git a/src/misc/fixedsizearray.hpp b/src/misc/fixedsizearray.hpp
index bf0f3acdd..c694ff7a1 100644
--- a/src/misc/fixedsizearray.hpp
+++ b/src/misc/fixedsizearray.hpp
@@ -41,13 +41,28 @@ protected:
T *data;
/** return reference to the array header (non-const) */
- inline ArrayHeader& Hdr() { return *(ArrayHeader*)(((byte*)data) - HeaderSize); }
+ inline ArrayHeader& Hdr()
+ {
+ return *(ArrayHeader*)(((byte*)data) - HeaderSize);
+ }
+
/** return reference to the array header (const) */
- inline const ArrayHeader& Hdr() const { return *(ArrayHeader*)(((byte*)data) - HeaderSize); }
+ inline const ArrayHeader& Hdr() const
+ {
+ return *(ArrayHeader*)(((byte*)data) - HeaderSize);
+ }
+
/** return reference to the block reference counter */
- inline uint& RefCnt() { return Hdr().reference_count; }
+ inline uint& RefCnt()
+ {
+ return Hdr().reference_count;
+ }
+
/** return reference to number of used items */
- inline uint& SizeRef() { return Hdr().items; }
+ inline uint& SizeRef()
+ {
+ return Hdr().items;
+ }
public:
/** Default constructor. Preallocate space for items and header, then initialize header. */
@@ -96,19 +111,50 @@ public:
}
/** return number of used items */
- inline uint Length() const { return Hdr().items; }
+ inline uint Length() const
+ {
+ return Hdr().items;
+ }
+
/** return true if array is full */
- inline bool IsFull() const { return Length() >= C; }
+ inline bool IsFull() const
+ {
+ return Length() >= C;
+ }
+
/** return true if array is empty */
- inline bool IsEmpty() const { return Length() <= 0; }
+ inline bool IsEmpty() const
+ {
+ return Length() <= 0;
+ }
+
/** add (allocate), but don't construct item */
- inline T *Append() { assert(!IsFull()); return &data[SizeRef()++]; }
+ inline T *Append()
+ {
+ assert(!IsFull());
+ return &data[SizeRef()++];
+ }
+
/** add and construct item using default constructor */
- inline T *AppendC() { T *item = Append(); new(item)T; return item; }
+ inline T *AppendC()
+ {
+ T *item = Append();
+ new(item)T;
+ return item;
+ }
/** return item by index (non-const version) */
- inline T& operator[](uint index) { assert(index < Length()); return data[index]; }
+ inline T& operator[](uint index)
+ {
+ assert(index < Length());
+ return data[index];
+ }
+
/** return item by index (const version) */
- inline const T& operator[](uint index) const { assert(index < Length()); return data[index]; }
+ inline const T& operator[](uint index) const
+ {
+ assert(index < Length());
+ return data[index];
+ }
};
#endif /* FIXEDSIZEARRAY_HPP */