(svn r27363) -Codechange: Fix codestyle of one-line methods and header codestyle of derived structs.

This commit is contained in:
alberth
2015-08-08 13:19:38 +00:00
parent 48485a6a5a
commit 894f69e1fd
13 changed files with 302 additions and 121 deletions

View File

@@ -42,9 +42,16 @@ protected:
public:
/** implicit constructor */
inline SmallArray() { }
inline SmallArray()
{
}
/** Clear (destroy) all items */
inline void Clear() {data.Clear();}
inline void Clear()
{
data.Clear();
}
/** Return actual number of items */
inline uint Length() const
{
@@ -54,13 +61,29 @@ public:
return (super_size - 1) * B + sub_size;
}
/** return true if array is empty */
inline bool IsEmpty() { return data.IsEmpty(); }
inline bool IsEmpty()
{
return data.IsEmpty();
}
/** return true if array is full */
inline bool IsFull() { return data.IsFull() && data[N - 1].IsFull(); }
inline bool IsFull()
{
return data.IsFull() && data[N - 1].IsFull();
}
/** allocate but not construct new item */
inline T *Append() { return FirstFreeSubArray().Append(); }
inline T *Append()
{
return FirstFreeSubArray().Append();
}
/** allocate and construct new item */
inline T *AppendC() { return FirstFreeSubArray().AppendC(); }
inline T *AppendC()
{
return FirstFreeSubArray().AppendC();
}
/** indexed access (non-const) */
inline T& operator[](uint index)
{

View File

@@ -157,21 +157,30 @@ public:
*
* @return The number of items in the queue
*/
inline uint Length() const { return this->items; }
inline uint Length() const
{
return this->items;
}
/**
* Test if the priority queue is empty.
*
* @return True if empty
*/
inline bool IsEmpty() const { return this->items == 0; }
inline bool IsEmpty() const
{
return this->items == 0;
}
/**
* Test if the priority queue is full.
*
* @return True if full.
*/
inline bool IsFull() const { return this->items >= this->capacity; }
inline bool IsFull() const
{
return this->items >= this->capacity;
}
/**
* Get the smallest item in the binary tree.
@@ -287,7 +296,10 @@ public:
* Make the priority queue empty.
* All remaining items will remain untouched.
*/
inline void Clear() { this->items = 0; }
inline void Clear()
{
this->items = 0;
}
};
#endif /* BINARYHEAP_HPP */

View File

@@ -71,7 +71,10 @@ public:
static const size_t header_size = sizeof(BlobHeader);
/** default constructor - initializes empty blob */
inline ByteBlob() { InitEmpty(); }
inline ByteBlob()
{
InitEmpty();
}
/** copy constructor */
inline ByteBlob(const ByteBlob &src)
@@ -311,9 +314,22 @@ public:
struct OnTransfer {
typename base::BlobHeader *header;
OnTransfer(const OnTransfer& src) : header(src.header) {assert(src.header != NULL); *const_cast<typename base::BlobHeader**>(&src.header) = NULL;}
OnTransfer(CBlobT& src) : header(src.header) {src.InitEmpty();}
~OnTransfer() {assert(header == NULL);}
OnTransfer(const OnTransfer& src) : header(src.header)
{
assert(src.header != NULL);
*const_cast<typename base::BlobHeader**>(&src.header) = NULL;
}
OnTransfer(CBlobT& src) : header(src.header)
{
src.InitEmpty();
}
~OnTransfer()
{
assert(header == NULL);
}
};
/** Default constructor - makes new Blob ready to accept any data */

View File

@@ -35,48 +35,97 @@ protected:
public:
/** default (NULL) construct or construct from a raw pointer */
inline CCountedPtr(Tcls *pObj = NULL) : m_pT(pObj) {AddRef();}
inline CCountedPtr(Tcls *pObj = NULL) : m_pT(pObj)
{
AddRef();
}
/** copy constructor (invoked also when initializing from another smart ptr) */
inline CCountedPtr(const CCountedPtr &src) : m_pT(src.m_pT) {AddRef();}
inline CCountedPtr(const CCountedPtr &src) : m_pT(src.m_pT)
{
AddRef();
}
/** destructor releasing the reference */
inline ~CCountedPtr() {Release();}
inline ~CCountedPtr()
{
Release();
}
protected:
/** add one ref to the underlaying object */
inline void AddRef() {if (m_pT != NULL) m_pT->AddRef();}
inline void AddRef()
{
if (m_pT != NULL) m_pT->AddRef();
}
public:
/** release smart pointer (and decrement ref count) if not null */
inline void Release() {if (m_pT != NULL) {Tcls *pT = m_pT; m_pT = NULL; pT->Release();}}
inline void Release()
{
if (m_pT != NULL) {
Tcls *pT = m_pT;
m_pT = NULL;
pT->Release();
}
}
/** dereference of smart pointer - const way */
inline const Tcls *operator->() const {assert(m_pT != NULL); return m_pT;}
inline const Tcls *operator->() const
{
assert(m_pT != NULL);
return m_pT;
}
/** dereference of smart pointer - non const way */
inline Tcls *operator->() {assert(m_pT != NULL); return m_pT;}
inline Tcls *operator->()
{
assert(m_pT != NULL);
return m_pT;
}
/** raw pointer casting operator - const way */
inline operator const Tcls*() const {assert(m_pT == NULL); return m_pT;}
inline operator const Tcls*() const
{
assert(m_pT == NULL);
return m_pT;
}
/** raw pointer casting operator - non-const way */
inline operator Tcls*() {return m_pT;}
inline operator Tcls*()
{
return m_pT;
}
/** operator & to support output arguments */
inline Tcls** operator&() {assert(m_pT == NULL); return &m_pT;}
inline Tcls** operator&()
{
assert(m_pT == NULL);
return &m_pT;
}
/** assignment operator from raw ptr */
inline CCountedPtr& operator=(Tcls *pT) {Assign(pT); return *this;}
inline CCountedPtr& operator=(Tcls *pT)
{
Assign(pT);
return *this;
}
/** assignment operator from another smart ptr */
inline CCountedPtr& operator=(const CCountedPtr &src) {Assign(src.m_pT); return *this;}
inline CCountedPtr& operator=(const CCountedPtr &src)
{
Assign(src.m_pT);
return *this;
}
/** assignment operator helper */
inline void Assign(Tcls *pT);
/** one way how to test for NULL value */
inline bool IsNull() const {return m_pT == NULL;}
inline bool IsNull() const
{
return m_pT == NULL;
}
/** another way how to test for NULL value */
//inline bool operator == (const CCountedPtr &sp) const {return m_pT == sp.m_pT;}
@@ -85,10 +134,19 @@ public:
//inline bool operator != (const CCountedPtr &sp) const {return m_pT != sp.m_pT;}
/** assign pointer w/o incrementing ref count */
inline void Attach(Tcls *pT) {Release(); m_pT = pT;}
inline void Attach(Tcls *pT)
{
Release();
m_pT = pT;
}
/** detach pointer w/o decrementing ref count */
inline Tcls *Detach() {Tcls *pT = m_pT; m_pT = NULL; return pT;}
inline Tcls *Detach()
{
Tcls *pT = m_pT;
m_pT = NULL;
return pT;
}
};
template <class Tcls_>
@@ -136,7 +194,6 @@ template <class T> struct AdaptT {
}
};
/**
* Simple counted object. Use it as base of your struct/class if you want to use
* basic reference counting. Your struct/class will destroy and free itself when
@@ -161,7 +218,4 @@ struct SimpleCountedObject {
virtual void FinalRelease() {};
};
#endif /* COUNTEDPTR_HPP */

View File

@@ -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 */

View File

@@ -24,7 +24,10 @@ struct CHashTableSlotT
inline CHashTableSlotT() : m_pFirst(NULL) {}
/** hash table slot helper - clears the slot by simple forgetting its items */
inline void Clear() {m_pFirst = NULL;}
inline void Clear()
{
m_pFirst = NULL;
}
/** hash table slot helper - linear search for item with given key through the given blob - const version */
inline const Titem_ *Find(const Key &key) const
@@ -168,14 +171,23 @@ protected:
}
/** static helper - return hash for the given item modulo number of slots */
inline static int CalcHash(const Titem_ &item) {return CalcHash(item.GetKey());}
inline static int CalcHash(const Titem_ &item)
{
return CalcHash(item.GetKey());
}
public:
/** item count */
inline int Count() const {return m_num_items;}
inline int Count() const
{
return m_num_items;
}
/** simple clear - forget all items - used by CSegmentCostCacheT.Flush() */
inline void Clear() {for (int i = 0; i < Tcapacity; i++) m_slots[i].Clear();}
inline void Clear()
{
for (int i = 0; i < Tcapacity; i++) m_slots[i].Clear();
}
/** const item search */
const Titem_ *Find(const Tkey &key) const