diff options
author | rubidium <rubidium@openttd.org> | 2009-01-10 00:31:47 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2009-01-10 00:31:47 +0000 |
commit | 28ea38ae5572d99598aa400fb62eb38f5f7ffd7b (patch) | |
tree | 29e703244d28f29c8634b2d30f42b34852fe74bc /src/misc | |
parent | 86d50b6415635d1f1fb87bd62f1e08aa7b8f0033 (diff) | |
download | openttd-28ea38ae5572d99598aa400fb62eb38f5f7ffd7b.tar.xz |
(svn r14949) -Cleanup: pointer coding style
Diffstat (limited to 'src/misc')
-rw-r--r-- | src/misc/binaryheap.hpp | 6 | ||||
-rw-r--r-- | src/misc/blob.hpp | 66 | ||||
-rw-r--r-- | src/misc/countedptr.hpp | 22 | ||||
-rw-r--r-- | src/misc/crc32.hpp | 10 | ||||
-rw-r--r-- | src/misc/dbg_helpers.cpp | 6 | ||||
-rw-r--r-- | src/misc/dbg_helpers.h | 4 | ||||
-rw-r--r-- | src/misc/fixedsizearray.hpp | 2 | ||||
-rw-r--r-- | src/misc/hashtable.hpp | 38 | ||||
-rw-r--r-- | src/misc/str.hpp | 14 |
9 files changed, 84 insertions, 84 deletions
diff --git a/src/misc/binaryheap.hpp b/src/misc/binaryheap.hpp index f8a343724..ed5a44b71 100644 --- a/src/misc/binaryheap.hpp +++ b/src/misc/binaryheap.hpp @@ -5,9 +5,9 @@ #ifndef BINARYHEAP_HPP #define BINARYHEAP_HPP -//void* operator new (size_t size, void* p) {return p;} +//void *operator new (size_t size, void *p) {return p;} #if defined(_MSC_VER) && (_MSC_VER >= 1400) -//void operator delete (void* p, void* p2) {} +//void operator delete (void *p, void *p2) {} #endif @@ -36,7 +36,7 @@ public: private: int m_size; ///< Number of items in the heap int m_max_size; ///< Maximum number of items the heap can hold - ItemPtr* m_items; ///< The heap item pointers + ItemPtr *m_items; ///< The heap item pointers public: explicit CBinaryHeapT(int max_items = 102400) diff --git a/src/misc/blob.hpp b/src/misc/blob.hpp index 12f7e54ff..d28f6f00d 100644 --- a/src/misc/blob.hpp +++ b/src/misc/blob.hpp @@ -101,7 +101,7 @@ protected: } /** initialize blob by attaching it to the given header followed by data */ - FORCEINLINE void Init(CHdr* hdr) + FORCEINLINE void Init(CHdr *hdr) { ptr_u.m_pHdr_1 = &hdr[1]; } @@ -144,13 +144,13 @@ public: }; /** return pointer to the first byte of data - non-const version */ - FORCEINLINE bitem_t* RawData() + FORCEINLINE bitem_t *RawData() { return ptr_u.m_pData; } /** return pointer to the first byte of data - const version */ - FORCEINLINE const bitem_t* RawData() const + FORCEINLINE const bitem_t *RawData() const { return ptr_u.m_pData; } @@ -218,7 +218,7 @@ public: /** Reallocate if there is no free space for num_bytes bytes. * @return pointer to the new data to be added */ - FORCEINLINE bitem_t* MakeRawFreeSpace(bsize_t num_bytes) + FORCEINLINE bitem_t *MakeRawFreeSpace(bsize_t num_bytes) { assert(num_bytes >= 0); bsize_t new_size = RawSize() + num_bytes; @@ -228,9 +228,9 @@ public: /** Increase RawSize() by num_bytes. * @return pointer to the new data added */ - FORCEINLINE bitem_t* GrowRawSize(bsize_t num_bytes) + FORCEINLINE bitem_t *GrowRawSize(bsize_t num_bytes) { - bitem_t* pNewData = MakeRawFreeSpace(num_bytes); + bitem_t *pNewData = MakeRawFreeSpace(num_bytes); RawSizeRef() += num_bytes; return pNewData; } @@ -255,7 +255,7 @@ public: // ask allocation policy for some reasonable block size bsize_t alloc_size = AllocPolicy(min_alloc_size); // allocate new block - CHdr* pNewHdr = RawAlloc(alloc_size); + CHdr *pNewHdr = RawAlloc(alloc_size); // setup header pNewHdr->m_size = RawSize(); pNewHdr->m_max_size = alloc_size - (sizeof(CHdr) + Ttail_reserve); @@ -263,7 +263,7 @@ public: if (RawSize() > 0) memcpy(pNewHdr + 1, ptr_u.m_pData, pNewHdr->m_size); // replace our block with new one - CHdr* pOldHdr = &Hdr(); + CHdr *pOldHdr = &Hdr(); Init(pNewHdr); if (old_max_size > 0) RawFree(pOldHdr); @@ -289,13 +289,13 @@ public: } /** all allocation should happen here */ - static FORCEINLINE CHdr* RawAlloc(bsize_t num_bytes) + static FORCEINLINE CHdr *RawAlloc(bsize_t num_bytes) { return (CHdr*)MallocT<byte>(num_bytes); } /** all deallocations should happen here */ - static FORCEINLINE void RawFree(CHdr* p) + static FORCEINLINE void RawFree(CHdr *p) { free(p); } @@ -370,26 +370,26 @@ public: } /** Return pointer to the first data item - non-const version */ - FORCEINLINE Titem* Data() + FORCEINLINE Titem *Data() { return (Titem*)Tbase::RawData(); } /** Return pointer to the first data item - const version */ - FORCEINLINE const Titem* Data() const + FORCEINLINE const Titem *Data() const { return (const Titem*)Tbase::RawData(); } /** Return pointer to the idx-th data item - non-const version */ - FORCEINLINE Titem* Data(bsize_t idx) + FORCEINLINE Titem *Data(bsize_t idx) { CheckIdx(idx); return (Data() + idx); } /** Return pointer to the idx-th data item - const version */ - FORCEINLINE const Titem* Data(bsize_t idx) const + FORCEINLINE const Titem *Data(bsize_t idx) const { CheckIdx(idx); return (Data() + idx); @@ -419,22 +419,22 @@ public: bsize_t old_size = Size(); if (old_size > 0) { // destroy removed items; - Titem* pI_last_to_destroy = Data(0); - for (Titem* pI = Data(old_size - 1); pI >= pI_last_to_destroy; pI--) pI->~Titem_(); + Titem *pI_last_to_destroy = Data(0); + for (Titem *pI = Data(old_size - 1); pI >= pI_last_to_destroy; pI--) pI->~Titem_(); } Tbase::Free(); } /** Grow number of data items in Blob by given number - doesn't construct items */ - FORCEINLINE Titem* GrowSizeNC(bsize_t num_items) + FORCEINLINE Titem *GrowSizeNC(bsize_t num_items) { return (Titem*)Tbase::GrowRawSize(num_items * Titem_size); } /** Grow number of data items in Blob by given number - constructs new items (using Titem_'s default constructor) */ - FORCEINLINE Titem* GrowSizeC(bsize_t num_items) + FORCEINLINE Titem *GrowSizeC(bsize_t num_items) { - Titem* pI = GrowSizeNC(num_items); + Titem *pI = GrowSizeNC(num_items); for (bsize_t i = num_items; i > 0; i--, pI++) new (pI) Titem(); } @@ -446,34 +446,34 @@ public: assert(num_items <= old_size); bsize_t new_size = (num_items <= old_size) ? (old_size - num_items) : 0; // destroy removed items; - Titem* pI_last_to_destroy = Data(new_size); - for (Titem* pI = Data(old_size - 1); pI >= pI_last_to_destroy; pI--) pI->~Titem(); + Titem *pI_last_to_destroy = Data(new_size); + for (Titem *pI = Data(old_size - 1); pI >= pI_last_to_destroy; pI--) pI->~Titem(); // remove them Tbase::ReduceRawSize(num_items * Titem_size); } /** Append one data item at the end (calls Titem_'s default constructor) */ - FORCEINLINE Titem* AppendNew() + FORCEINLINE Titem *AppendNew() { Titem& dst = *GrowSizeNC(1); // Grow size by one item - Titem* pNewItem = new (&dst) Titem(); // construct the new item by calling in-place new operator + Titem *pNewItem = new (&dst) Titem(); // construct the new item by calling in-place new operator return pNewItem; } /** Append the copy of given item at the end of Blob (using copy constructor) */ - FORCEINLINE Titem* Append(const Titem& src) + FORCEINLINE Titem *Append(const Titem& src) { Titem& dst = *GrowSizeNC(1); // Grow size by one item - Titem* pNewItem = new (&dst) Titem(src); // construct the new item by calling in-place new operator with copy ctor() + Titem *pNewItem = new (&dst) Titem(src); // construct the new item by calling in-place new operator with copy ctor() return pNewItem; } /** Add given items (ptr + number of items) at the end of blob */ - FORCEINLINE Titem* Append(const Titem* pSrc, bsize_t num_items) + FORCEINLINE Titem *Append(const Titem *pSrc, bsize_t num_items) { - Titem* pDst = GrowSizeNC(num_items); - Titem* pDstOrg = pDst; - Titem* pDstEnd = pDst + num_items; + Titem *pDst = GrowSizeNC(num_items); + Titem *pDstOrg = pDst; + Titem *pDstEnd = pDst + num_items; while (pDst < pDstEnd) new (pDst++) Titem(*(pSrc++)); return pDstOrg; } @@ -483,14 +483,14 @@ public: { CheckIdx(idx); // destroy removed item - Titem* pRemoved = Data(idx); + Titem *pRemoved = Data(idx); RemoveBySwap(pRemoved); } /** Remove item given by pointer replacing it by the last item and reducing the size by one */ - FORCEINLINE void RemoveBySwap(Titem* pItem) + FORCEINLINE void RemoveBySwap(Titem *pItem) { - Titem* pLast = Data(Size() - 1); + Titem *pLast = Data(Size() - 1); assert(pItem >= Data() && pItem <= pLast); // move last item to its new place if (pItem != pLast) { @@ -505,7 +505,7 @@ public: /** Ensures that given number of items can be added to the end of Blob. Returns pointer to the * first free (unused) item */ - FORCEINLINE Titem* MakeFreeSpace(bsize_t num_items) + FORCEINLINE Titem *MakeFreeSpace(bsize_t num_items) { return (Titem*)Tbase::MakeRawFreeSpace(num_items * Titem_size); } diff --git a/src/misc/countedptr.hpp b/src/misc/countedptr.hpp index c19e64b0b..59e1273a6 100644 --- a/src/misc/countedptr.hpp +++ b/src/misc/countedptr.hpp @@ -23,11 +23,11 @@ public: protected: /** here we hold our pointer to the target */ - Tcls* m_pT; + Tcls *m_pT; public: /** default (NULL) construct or construct from a raw pointer */ - FORCEINLINE CCountedPtr(Tcls* pObj = NULL) : m_pT(pObj) {AddRef();}; + FORCEINLINE CCountedPtr(Tcls *pObj = NULL) : m_pT(pObj) {AddRef();}; /** copy constructor (invoked also when initializing from another smart ptr) */ FORCEINLINE CCountedPtr(const CCountedPtr& src) : m_pT(src.m_pT) {AddRef();}; @@ -41,13 +41,13 @@ protected: public: /** release smart pointer (and decrement ref count) if not null */ - FORCEINLINE void Release() {if (m_pT != NULL) {Tcls* pT = m_pT; m_pT = NULL; pT->Release();}} + FORCEINLINE void Release() {if (m_pT != NULL) {Tcls *pT = m_pT; m_pT = NULL; pT->Release();}} /** dereference of smart pointer - const way */ - FORCEINLINE const Tcls* operator -> () const {assert(m_pT != NULL); return m_pT;}; + FORCEINLINE const Tcls *operator -> () const {assert(m_pT != NULL); return m_pT;}; /** dereference of smart pointer - non const way */ - FORCEINLINE Tcls* operator -> () {assert(m_pT != NULL); return m_pT;}; + FORCEINLINE Tcls *operator -> () {assert(m_pT != NULL); return m_pT;}; /** raw pointer casting operator - const way */ FORCEINLINE operator const Tcls*() const {assert(m_pT == NULL); return m_pT;} @@ -59,13 +59,13 @@ public: FORCEINLINE Tcls** operator &() {assert(m_pT == NULL); return &m_pT;} /** assignment operator from raw ptr */ - FORCEINLINE CCountedPtr& operator = (Tcls* pT) {Assign(pT); return *this;} + FORCEINLINE CCountedPtr& operator = (Tcls *pT) {Assign(pT); return *this;} /** assignment operator from another smart ptr */ FORCEINLINE CCountedPtr& operator = (const CCountedPtr& src) {Assign(src.m_pT); return *this;} /** assignment operator helper */ - FORCEINLINE void Assign(Tcls* pT); + FORCEINLINE void Assign(Tcls *pT); /** one way how to test for NULL value */ FORCEINLINE bool IsNull() const {return m_pT == NULL;} @@ -77,19 +77,19 @@ public: //FORCEINLINE bool operator != (const CCountedPtr& sp) const {return m_pT != sp.m_pT;} /** assign pointer w/o incrementing ref count */ - FORCEINLINE void Attach(Tcls* pT) {Release(); m_pT = pT;} + FORCEINLINE void Attach(Tcls *pT) {Release(); m_pT = pT;} /** detach pointer w/o decrementing ref count */ - FORCEINLINE Tcls* Detach() {Tcls* pT = m_pT; m_pT = NULL; return pT;} + FORCEINLINE Tcls *Detach() {Tcls *pT = m_pT; m_pT = NULL; return pT;} }; template <class Tcls_> -FORCEINLINE void CCountedPtr<Tcls_>::Assign(Tcls* pT) +FORCEINLINE void CCountedPtr<Tcls_>::Assign(Tcls *pT) { // if they are the same, we do nothing if (pT != m_pT) { if (pT) pT->AddRef(); // AddRef new pointer if any - Tcls* pTold = m_pT; // save original ptr + Tcls *pTold = m_pT; // save original ptr m_pT = pT; // update m_pT to new value if (pTold) pTold->Release(); // release old ptr if any } diff --git a/src/misc/crc32.hpp b/src/misc/crc32.hpp index 1d2f86dcd..2c0ca3abd 100644 --- a/src/misc/crc32.hpp +++ b/src/misc/crc32.hpp @@ -11,18 +11,18 @@ struct CCrc32 static uint32 Calc(const void *pBuffer, int nCount) { uint32 crc = 0xffffffff; - const uint32* pTable = CrcTable(); + const uint32 *pTable = CrcTable(); - uint8* begin = (uint8*)pBuffer; - uint8* end = begin + nCount; - for(uint8* cur = begin; cur < end; cur++) + uint8 *begin = (uint8*)pBuffer; + uint8 *end = begin + nCount; + for(uint8 *cur = begin; cur < end; cur++) crc = (crc >> 8) ^ pTable[cur[0] ^ (uint8)(crc & 0xff)]; crc ^= 0xffffffff; return crc; } - static const uint32* CrcTable() + static const uint32 *CrcTable() { static const uint32 Table[256] = { diff --git a/src/misc/dbg_helpers.cpp b/src/misc/dbg_helpers.cpp index 1c34e25b3..11fdaf19b 100644 --- a/src/misc/dbg_helpers.cpp +++ b/src/misc/dbg_helpers.cpp @@ -11,7 +11,7 @@ #include "dbg_helpers.h" /** Trackdir & TrackdirBits short names. */ -static const char* trackdir_names[] = { +static const char *trackdir_names[] = { "NE", "SE", "UE", "LE", "LS", "RS", "rne", "rse", "SW", "NW", "UW", "LW", "LN", "RN", "rsw", "rnw", }; @@ -34,7 +34,7 @@ CStrA ValueStr(TrackdirBits td_bits) /** DiagDirection short names. */ -static const char* diagdir_names[] = { +static const char *diagdir_names[] = { "NE", "SE", "SW", "NW", }; @@ -48,7 +48,7 @@ CStrA ValueStr(DiagDirection dd) /** SignalType short names. */ -static const char* signal_type_names[] = { +static const char *signal_type_names[] = { "NORMAL", "ENTRY", "EXIT", "COMBO", "PBS", "NOENTRY", }; diff --git a/src/misc/dbg_helpers.h b/src/misc/dbg_helpers.h index 83aa6c294..7cbe57810 100644 --- a/src/misc/dbg_helpers.h +++ b/src/misc/dbg_helpers.h @@ -59,7 +59,7 @@ inline typename ArrayT<T>::item_t ItemAtT(E idx, T &t, typename ArrayT<T>::item_ * or t_unk when index is out of bounds. */ template <typename E, typename T> -inline CStrA ComposeNameT(E value, T &t, const char* t_unk, E val_inv, const char* name_inv) +inline CStrA ComposeNameT(E value, T &t, const char *t_unk, E val_inv, const char *name_inv) { CStrA out; if (value == val_inv) { @@ -123,7 +123,7 @@ struct DumpTarget { static size_t& LastTypeId(); CStrA GetCurrentStructName(); - bool FindKnownName(size_t type_id, const void* ptr, CStrA &name); + bool FindKnownName(size_t type_id, const void *ptr, CStrA &name); void WriteIndent(); diff --git a/src/misc/fixedsizearray.hpp b/src/misc/fixedsizearray.hpp index 10eb4eaa1..cd3d8c904 100644 --- a/src/misc/fixedsizearray.hpp +++ b/src/misc/fixedsizearray.hpp @@ -63,7 +63,7 @@ struct CFixedSizeArrayT { FORCEINLINE void Clear() { // walk through all allocated items backward and destroy them - for (Titem* pItem = &m_items[Size() - 1]; pItem >= m_items; pItem--) { + for (Titem *pItem = &m_items[Size() - 1]; pItem >= m_items; pItem--) { pItem->~Titem_(); } // number of items become zero diff --git a/src/misc/hashtable.hpp b/src/misc/hashtable.hpp index 7b93b6cd8..2f1c18530 100644 --- a/src/misc/hashtable.hpp +++ b/src/misc/hashtable.hpp @@ -10,7 +10,7 @@ struct CHashTableSlotT { typedef typename Titem_::Key Key; // make Titem_::Key a property of HashTable - Titem_* m_pFirst; + Titem_ *m_pFirst; CHashTableSlotT() : m_pFirst(NULL) {} @@ -18,9 +18,9 @@ struct CHashTableSlotT FORCEINLINE void Clear() {m_pFirst = NULL;} /** hash table slot helper - linear search for item with given key through the given blob - const version */ - FORCEINLINE const Titem_* Find(const Key& key) const + FORCEINLINE const Titem_ *Find(const Key& key) const { - for (const Titem_* pItem = m_pFirst; pItem != NULL; pItem = pItem->GetHashNext()) { + for (const Titem_ *pItem = m_pFirst; pItem != NULL; pItem = pItem->GetHashNext()) { if (pItem->GetKey() == key) { // we have found the item, return it return pItem; @@ -30,9 +30,9 @@ struct CHashTableSlotT } /** hash table slot helper - linear search for item with given key through the given blob - non-const version */ - FORCEINLINE Titem_* Find(const Key& key) + FORCEINLINE Titem_ *Find(const Key& key) { - for (Titem_* pItem = m_pFirst; pItem != NULL; pItem = pItem->GetHashNext()) { + for (Titem_ *pItem = m_pFirst; pItem != NULL; pItem = pItem->GetHashNext()) { if (pItem->GetKey() == key) { // we have found the item, return it return pItem; @@ -57,12 +57,12 @@ struct CHashTableSlotT item_to_remove.SetHashNext(NULL); return true; } - Titem_* pItem = m_pFirst; + Titem_ *pItem = m_pFirst; while (true) { if (pItem == NULL) { return false; } - Titem_* pNextItem = pItem->GetHashNext(); + Titem_ *pNextItem = pItem->GetHashNext(); if (pNextItem == &item_to_remove) break; pItem = pNextItem; } @@ -72,7 +72,7 @@ struct CHashTableSlotT } /** hash table slot helper - remove and return item from a slot */ - FORCEINLINE Titem_* Detach(const Key& key) + FORCEINLINE Titem_ *Detach(const Key& key) { // do we have any items? if (m_pFirst == NULL) { @@ -86,8 +86,8 @@ struct CHashTableSlotT return &ret_item; } // find it in the following items - Titem_* pPrev = m_pFirst; - for (Titem_* pItem = m_pFirst->GetHashNext(); pItem != NULL; pPrev = pItem, pItem = pItem->GetHashNext()) { + Titem_ *pPrev = m_pFirst; + for (Titem_ *pItem = m_pFirst->GetHashNext(); pItem != NULL; pPrev = pItem, pItem = pItem->GetHashNext()) { if (pItem->GetKey() == key) { // we have found the item, unlink and return it pPrev->SetHashNext(pItem->GetHashNext()); @@ -133,8 +133,8 @@ protected: * Titem contains pointer to the next item - GetHashNext(), SetHashNext() */ typedef CHashTableSlotT<Titem_> Slot; - Slot* m_slots; // here we store our data (array of blobs) - int m_num_items; // item counter + Slot *m_slots; // here we store our data (array of blobs) + int m_num_items; // item counter public: // default constructor @@ -171,29 +171,29 @@ public: FORCEINLINE void Clear() const {for (int i = 0; i < Tcapacity; i++) m_slots[i].Clear();} /** const item search */ - const Titem_* Find(const Tkey& key) const + const Titem_ *Find(const Tkey& key) const { int hash = CalcHash(key); const Slot& slot = m_slots[hash]; - const Titem_* item = slot.Find(key); + const Titem_ *item = slot.Find(key); return item; } /** non-const item search */ - Titem_* Find(const Tkey& key) + Titem_ *Find(const Tkey& key) { int hash = CalcHash(key); Slot& slot = m_slots[hash]; - Titem_* item = slot.Find(key); + Titem_ *item = slot.Find(key); return item; } /** non-const item search & optional removal (if found) */ - Titem_* TryPop(const Tkey& key) + Titem_ *TryPop(const Tkey& key) { int hash = CalcHash(key); Slot& slot = m_slots[hash]; - Titem_* item = slot.Detach(key); + Titem_ *item = slot.Detach(key); if (item != NULL) { m_num_items--; } @@ -203,7 +203,7 @@ public: /** non-const item search & removal */ Titem_& Pop(const Tkey& key) { - Titem_* item = TryPop(key); + Titem_ *item = TryPop(key); assert(item != NULL); return *item; } diff --git a/src/misc/str.hpp b/src/misc/str.hpp index 93e60d441..666c03187 100644 --- a/src/misc/str.hpp +++ b/src/misc/str.hpp @@ -19,19 +19,19 @@ struct CStrT : public CBlobT<Tchar> typedef typename base::OnTransfer OnTransfer; ///< temporary 'transfer ownership' object type /** Construction from C zero ended string. */ - FORCEINLINE CStrT(const Tchar* str = NULL) + FORCEINLINE CStrT(const Tchar *str = NULL) { AppendStr(str); } /** Construction from C string and given number of characters. */ - FORCEINLINE CStrT(const Tchar* str, bsize_t num_chars) : base(str, num_chars) + FORCEINLINE CStrT(const Tchar *str, bsize_t num_chars) : base(str, num_chars) { base::FixTail(); } /** Construction from C string determined by 'begin' and 'end' pointers. */ - FORCEINLINE CStrT(const Tchar* str, const Tchar* end) + FORCEINLINE CStrT(const Tchar *str, const Tchar *end) : base(str, end - str) { base::FixTail(); @@ -58,15 +58,15 @@ struct CStrT : public CBlobT<Tchar> } /** Grow the actual buffer and fix the trailing zero at the end. */ - FORCEINLINE Tchar* GrowSizeNC(bsize_t count) + FORCEINLINE Tchar *GrowSizeNC(bsize_t count) { - Tchar* ret = base::GrowSizeNC(count); + Tchar *ret = base::GrowSizeNC(count); base::FixTail(); return ret; } /** Append zero-ended C string. */ - FORCEINLINE void AppendStr(const Tchar* str) + FORCEINLINE void AppendStr(const Tchar *str) { if (str != NULL && str[0] != '\0') { base::Append(str, (bsize_t)Api::StrLen(str)); @@ -84,7 +84,7 @@ struct CStrT : public CBlobT<Tchar> } /** Assignment from C string. */ - FORCEINLINE CStrT& operator = (const Tchar* src) + FORCEINLINE CStrT& operator = (const Tchar *src) { base::Clear(); AppendStr(src); |