فهرست منبع

Simplify documentation and do some renaming

Daniele Bartolini 13 سال پیش
والد
کامیت
591f35627a
2فایلهای تغییر یافته به همراه86 افزوده شده و 134 حذف شده
  1. 30 54
      src/core/containers/Array.h
  2. 56 80
      src/core/containers/List.h

+ 30 - 54
src/core/containers/Array.h

@@ -53,7 +53,7 @@ public:
 	uint					size() const;
 	uint					size() const;
 	uint					get_capacity() const;
 	uint					get_capacity() const;
 
 
-	uint					push_back(const T& element);
+	uint					push_back(const T& item);
 	void					pop_back();
 	void					pop_back();
 
 
 	void					clear();
 	void					clear();
@@ -67,8 +67,8 @@ public:
 
 
 private:
 private:
 
 
-	uint					mCount;			// The number of elements
-	T						mArray[SIZE];
+	uint					m_count;			// The number of items
+	T						m_array[SIZE];
 };
 };
 
 
 /**
 /**
@@ -77,12 +77,10 @@ private:
 	Does not initialize array memory.
 	Does not initialize array memory.
 */
 */
 template <typename T, uint SIZE>
 template <typename T, uint SIZE>
-inline Array<T, SIZE>::Array()
+inline Array<T, SIZE>::Array() : m_count(0)
 {
 {
 	assert(SIZE > 0);
 	assert(SIZE > 0);
 
 
-	mCount = 0;
-
 	// Do not initialize for efficiency
 	// Do not initialize for efficiency
 }
 }
 
 
@@ -107,64 +105,50 @@ inline Array<T, SIZE>::~Array()
 	Random access.
 	Random access.
 @note
 @note
 	The index has to be smaller than size()
 	The index has to be smaller than size()
-@param index
-	The index
-@return
-	The element at the given index
 */
 */
 template <typename T, uint SIZE>
 template <typename T, uint SIZE>
 inline T& Array<T, SIZE>::operator[](uint index)
 inline T& Array<T, SIZE>::operator[](uint index)
 {
 {
 	assert(index >= 0);
 	assert(index >= 0);
-	assert(index < mCount);
+	assert(index < m_count);
 
 
-	return mArray[index];
+	return m_array[index];
 }
 }
 
 
 /**
 /**
 	Random access.
 	Random access.
 @note
 @note
 	The index has to be smaller than size()
 	The index has to be smaller than size()
-@param index
-	The index
-@return
-	The element at the given index
 */
 */
 template <typename T, uint SIZE>
 template <typename T, uint SIZE>
 inline const T& Array<T, SIZE>::operator[](uint index) const
 inline const T& Array<T, SIZE>::operator[](uint index) const
 {
 {
 	assert(index >= 0);
 	assert(index >= 0);
-	assert(index < mCount);
+	assert(index < m_count);
 
 
-	return mArray[index];
+	return m_array[index];
 }
 }
 
 
 /**
 /**
 	Returns whether the array is empty.
 	Returns whether the array is empty.
-@return
-	True if empty, false otherwise
 */
 */
 template <typename T, uint SIZE>
 template <typename T, uint SIZE>
 inline bool Array<T, SIZE>::empty() const
 inline bool Array<T, SIZE>::empty() const
 {
 {
-	return mCount == 0;
+	return m_count == 0;
 }
 }
 
 
 /**
 /**
-	Returns the number of elements in the array.
-@return
-	The number of elements
+	Returns the number of items in the array.
 */
 */
 template <typename T, uint SIZE>
 template <typename T, uint SIZE>
 inline uint Array<T, SIZE>::size() const
 inline uint Array<T, SIZE>::size() const
 {
 {
-	return mCount;
+	return m_count;
 }
 }
 
 
 /**
 /**
-	Returns the maximum number of elements the array can hold.
-@return
-	The maximum number of elements
+	Returns the maximum number of items the array can hold.
 */
 */
 template <typename T, uint SIZE>
 template <typename T, uint SIZE>
 inline uint Array<T, SIZE>::get_capacity() const
 inline uint Array<T, SIZE>::get_capacity() const
@@ -173,61 +157,53 @@ inline uint Array<T, SIZE>::get_capacity() const
 }
 }
 
 
 /**
 /**
-	Appends an element to the array and returns its index or -1 if full.
-@param element
-	The element to append
-@return
-	The index of the element or -1 if full
+	Appends an item to the array and returns its index.
 */
 */
 template <typename T, uint SIZE>
 template <typename T, uint SIZE>
-inline uint Array<T, SIZE>::push_back(const T& element)
+inline uint Array<T, SIZE>::push_back(const T& item)
 {
 {
-	assert(mCount < SIZE);
+	assert(m_count < SIZE);
 
 
-	mArray[mCount] = element;
+	m_array[m_count] = item;
 
 
-	return mCount++;
+	return m_count++;
 }
 }
 
 
 /**
 /**
-	Removes the element at the given index.
-@param index
-	The index of the element to remove
+	Removes the item at the given index.
 */
 */
 template <typename T, uint SIZE>
 template <typename T, uint SIZE>
 inline void Array<T, SIZE>::pop_back()
 inline void Array<T, SIZE>::pop_back()
 {
 {
-	assert(mCount > 0);
+	assert(m_count > 0);
 
 
-	mCount--;
+	m_count--;
 }
 }
 
 
 /**
 /**
 	Clears the content of the array.
 	Clears the content of the array.
 @note
 @note
 	Does not free memory, it only zeroes
 	Does not free memory, it only zeroes
-	the number of elements in the array.
+	the number of items in the array.
 */
 */
 template <typename T, uint SIZE>
 template <typename T, uint SIZE>
 inline void Array<T, SIZE>::clear()
 inline void Array<T, SIZE>::clear()
 {
 {
-	mCount = 0;
+	m_count = 0;
 }
 }
 
 
 /**
 /**
-	Copies the content of the other list into this.
-@return
-	The reference to list after copying
+	Copies the content of other list into this.
 */
 */
 template <typename T, uint SIZE>
 template <typename T, uint SIZE>
 inline const Array<T, SIZE>& Array<T, SIZE>::operator=(const Array<T, SIZE>& b)
 inline const Array<T, SIZE>& Array<T, SIZE>::operator=(const Array<T, SIZE>& b)
 {
 {
-	for (uint i = 0; i < b.mCount; i++)
+	for (uint i = 0; i < b.m_count; i++)
 	{
 	{
-		mArray[i] = b.mArray[i];
+		m_array[i] = b.m_array[i];
 	}
 	}
 
 
-	mCount = b.mCount;
+	m_count = b.m_count;
 
 
 	return *this;
 	return *this;
 }
 }
@@ -236,28 +212,28 @@ inline const Array<T, SIZE>& Array<T, SIZE>::operator=(const Array<T, SIZE>& b)
 template <typename T, uint SIZE>
 template <typename T, uint SIZE>
 inline const T* Array<T, SIZE>::begin() const
 inline const T* Array<T, SIZE>::begin() const
 {
 {
-	return mArray;
+	return m_array;
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 template <typename T, uint SIZE>
 template <typename T, uint SIZE>
 inline T* Array<T, SIZE>::begin()
 inline T* Array<T, SIZE>::begin()
 {
 {
-	return mArray;
+	return m_array;
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 template <typename T, uint SIZE>
 template <typename T, uint SIZE>
 inline const T* Array<T, SIZE>::end() const
 inline const T* Array<T, SIZE>::end() const
 {
 {
-	return mArray + (mCount - 1);
+	return m_array + (m_count - 1);
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 template <typename T, uint SIZE>
 template <typename T, uint SIZE>
 inline T* Array<T, SIZE>::end()
 inline T* Array<T, SIZE>::end()
 {
 {
-	return mArray + (mCount - 1);
+	return m_array + (m_count - 1);
 }
 }
 
 
 } // namespace crown
 } // namespace crown

+ 56 - 80
src/core/containers/List.h

@@ -57,7 +57,7 @@ public:
 
 
 	void				condense();
 	void				condense();
 
 
-	uint				push_back(const T& element);
+	uint				push_back(const T& item);
 	void				pop_back();
 	void				pop_back();
 	void				clear();
 	void				clear();
 
 
@@ -70,9 +70,9 @@ public:
 
 
 private:
 private:
 
 
-	uint				mCapacity;
-	uint				mSize;
-	T*					mArray;
+	uint				m_capacity;
+	uint				m_size;
+	T*					m_array;
 };
 };
 
 
 /**
 /**
@@ -82,9 +82,9 @@ private:
 */
 */
 template <typename T>
 template <typename T>
 inline List<T>::List() :
 inline List<T>::List() :
-	mCapacity(0),
-	mSize(0),
-	mArray(0)
+	m_capacity(0),
+	m_size(0),
+	m_array(0)
 {
 {
 }
 }
 
 
@@ -95,9 +95,9 @@ inline List<T>::List() :
 */
 */
 template <typename T>
 template <typename T>
 inline List<T>::List(uint capacity) :
 inline List<T>::List(uint capacity) :
-	mCapacity(0),
-	mSize(0),
-	mArray(0)
+	m_capacity(0),
+	m_size(0),
+	m_array(0)
 {
 {
 	set_capacity(capacity);
 	set_capacity(capacity);
 }
 }
@@ -107,9 +107,9 @@ inline List<T>::List(uint capacity) :
 */
 */
 template <typename T>
 template <typename T>
 inline List<T>::List(const List<T>& list) :
 inline List<T>::List(const List<T>& list) :
-	mCapacity(0),
-	mSize(0),
-	mArray(0)
+	m_capacity(0),
+	m_size(0),
+	m_array(0)
 {
 {
 	*this = list;
 	*this = list;
 }
 }
@@ -120,9 +120,9 @@ inline List<T>::List(const List<T>& list) :
 template <typename T>
 template <typename T>
 inline List<T>::~List()
 inline List<T>::~List()
 {
 {
-	if (mArray)
+	if (m_array)
 	{
 	{
-		delete[] mArray;
+		delete[] m_array;
 	}
 	}
 }
 }
 
 
@@ -130,99 +130,83 @@ inline List<T>::~List()
 	Random access.
 	Random access.
 @note
 @note
 	The index has to be smaller than size()
 	The index has to be smaller than size()
-@param index
-	The index
-@return
-	The element at the given index
 */
 */
 template <typename T>
 template <typename T>
 inline T& List<T>::operator[](uint index)
 inline T& List<T>::operator[](uint index)
 {
 {
-	assert(index < mSize);
+	assert(index < m_size);
 
 
-	return mArray[index];
+	return m_array[index];
 }
 }
 
 
 /**
 /**
 	Random access.
 	Random access.
 @note
 @note
 	The index has to be smaller than size()
 	The index has to be smaller than size()
-@param index
-	The index
-@return
-	The element at the given index
 */
 */
 template <typename T>
 template <typename T>
 inline const T& List<T>::operator[](uint index) const
 inline const T& List<T>::operator[](uint index) const
 {
 {
-	assert(index < mSize);
+	assert(index < m_size);
 
 
-	return mArray[index];
+	return m_array[index];
 }
 }
 
 
 /**
 /**
 	Returns whether the array is empty.
 	Returns whether the array is empty.
-@return
-	True if empty, false otherwise
 */
 */
 template <typename T>
 template <typename T>
 inline bool List<T>::empty() const
 inline bool List<T>::empty() const
 {
 {
-	return mSize == 0;
+	return m_size == 0;
 }
 }
 
 
 /**
 /**
-	Returns the number of elements in the array.
-@return
-	The number of elements
+	Returns the number of items in the array.
 */
 */
 template <typename T>
 template <typename T>
 inline uint List<T>::size() const
 inline uint List<T>::size() const
 {
 {
-	return mSize;
+	return m_size;
 }
 }
 
 
 /**
 /**
-	Returns the maximum number of elements the array can hold.
-@return
-	The maximum number of elements
+	Returns the maximum number of items the array can hold.
 */
 */
 template <typename T>
 template <typename T>
 inline uint List<T>::capacity() const
 inline uint List<T>::capacity() const
 {
 {
-	return mCapacity;
+	return m_capacity;
 }
 }
 
 
 /**
 /**
 	Resizes the array to the given capacity.
 	Resizes the array to the given capacity.
 @note
 @note
-	Old elements will be copied to the newly created array.
+	Old items will be copied to the newly created array.
 	If the new capacity is smaller than the previous one, the
 	If the new capacity is smaller than the previous one, the
 	previous array will be truncated.
 	previous array will be truncated.
-@param capatity
-	The new capacity
 */
 */
 template <typename T>
 template <typename T>
 inline void List<T>::set_capacity(uint capacity)
 inline void List<T>::set_capacity(uint capacity)
 {
 {
 	assert(capacity > 0);
 	assert(capacity > 0);
 
 
-	if (mCapacity == capacity)
+	if (m_capacity == capacity)
 	{
 	{
 		return;
 		return;
 	}
 	}
 
 
-	T* tmp = mArray;
-	mCapacity = capacity;
+	T* tmp = m_array;
+	m_capacity = capacity;
 
 
-	if (capacity < mSize)
+	if (capacity < m_size)
 	{
 	{
-		mSize = capacity;
+		m_size = capacity;
 	}
 	}
 
 
-	mArray = new T[capacity];
+	m_array = new T[capacity];
 
 
-	memcpy(mArray, tmp, sizeof(T) * mSize);
+	memcpy(m_array, tmp, sizeof(T) * m_size);
 
 
 	if (tmp)
 	if (tmp)
 	{
 	{
@@ -233,85 +217,77 @@ inline void List<T>::set_capacity(uint capacity)
 template <typename T>
 template <typename T>
 inline void List<T>::grow()
 inline void List<T>::grow()
 {
 {
-	set_capacity(mCapacity * 2 + 16);
+	set_capacity(m_capacity * 2 + 16);
 }
 }
 
 
 /**
 /**
 	Condenses the array so the capacity matches the actual number
 	Condenses the array so the capacity matches the actual number
-	of elements in the array.
+	of items in the array.
 */
 */
 template <typename T>
 template <typename T>
 inline void List<T>::condense()
 inline void List<T>::condense()
 {
 {
-	set_capacity(mSize);
+	set_capacity(m_size);
 }
 }
 
 
 /**
 /**
-	Appends an element to the array and returns its index or -1 if full.
-@param element
-	The element to append
-@return
-	The index of the element or -1 if full
+	Appends an item to the array and returns its index or -1 if full.
 */
 */
 template <typename T>
 template <typename T>
-inline uint List<T>::push_back(const T& element)
+inline uint List<T>::push_back(const T& item)
 {
 {
-	if (mCapacity == mSize)
+	if (m_capacity == m_size)
 	{
 	{
 		grow();
 		grow();
 	}
 	}
 
 
-	mArray[mSize] = element;
+	m_array[m_size] = item;
 
 
-	return 	mSize++;
+	return 	m_size++;
 }
 }
 
 
 /**
 /**
-	Removes the element at the given index.
-@param index
-	The index of the element to remove
+	Removes the item at the given index.
 */
 */
 template <typename T>
 template <typename T>
 inline void List<T>::pop_back()
 inline void List<T>::pop_back()
 {
 {
-	assert(mSize > 0);
+	assert(m_size > 0);
 
 
-	mSize--;
+	m_size--;
 }
 }
 
 
 /**
 /**
 	Clears the content of the array.
 	Clears the content of the array.
 @note
 @note
 	Does not free memory, it only zeroes
 	Does not free memory, it only zeroes
-	the number of elements in the array.
+	the number of items in the array.
 */
 */
 template <typename T>
 template <typename T>
 inline void List<T>::clear()
 inline void List<T>::clear()
 {
 {
-	mSize = 0;
+	m_size = 0;
 }
 }
 
 
 /**
 /**
 	Copies the content of the other list into this.
 	Copies the content of the other list into this.
-@return
-	The reference to list after copying
 */
 */
 template <typename T>
 template <typename T>
 inline const List<T>& List<T>::operator=(const List<T>& other)
 inline const List<T>& List<T>::operator=(const List<T>& other)
 {
 {
-	if (mArray)
+	if (m_array)
 	{
 	{
-		delete[] mArray;
+		delete[] m_array;
 	}
 	}
 
 
-	mSize = other.mSize;
-	mCapacity = other.mCapacity;
+	m_size = other.m_size;
+	m_capacity = other.m_capacity;
 
 
-	if (mCapacity)
+	if (m_capacity)
 	{
 	{
-		mArray = new T[mCapacity];
+		m_array = new T[m_capacity];
 
 
-		memcpy(mArray, other.mArray, mSize);
+		memcpy(m_array, other.m_array, m_size);
 	}
 	}
 
 
 	return *this;
 	return *this;
@@ -321,28 +297,28 @@ inline const List<T>& List<T>::operator=(const List<T>& other)
 template <typename T>
 template <typename T>
 inline const T* List<T>::begin() const
 inline const T* List<T>::begin() const
 {
 {
-	return mArray;
+	return m_array;
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 template <typename T>
 template <typename T>
 inline T* List<T>::begin()
 inline T* List<T>::begin()
 {
 {
-	return mArray;
+	return m_array;
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 template <typename T>
 template <typename T>
 inline const T* List<T>::end() const
 inline const T* List<T>::end() const
 {
 {
-	return mArray + (mSize - 1);
+	return m_array + (m_size - 1);
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 template <typename T>
 template <typename T>
 inline T* List<T>::end()
 inline T* List<T>::end()
 {
 {
-	return mArray + (mSize - 1);
+	return m_array + (m_size - 1);
 }
 }
 
 
 } // namespace crown
 } // namespace crown