Reformat the code, using:

find -type f |  # list all regular files
  grep -E '\.(h|cpp|mm)$' |  # filter for source files
  grep -v '/mt_' |  # filter out generated files
  grep -v '/vendor/' | # and vendored GL
  grep -v '/test/image_loader_test.cpp' |  # and this file (has giant literals arrays)
  xargs -n 1 -P $(nproc) clang-format -i  # reformat everything

Co-authored-by: numzero <numzer0@yandex.ru>
This commit is contained in:
Desour
2024-03-20 19:35:52 +01:00
committed by sfan5
parent 9814510b1b
commit f5c6d3e945
292 changed files with 37376 additions and 42421 deletions

View File

@ -17,28 +17,33 @@ namespace core
//! Self reallocating template array (like stl vector) with additional features.
/** Some features are: Heap sorting, binary search methods, easier debugging.
*/
*/
template <class T>
class array
{
public:
static_assert(!std::is_same<T, bool>::value,
"irr::core::array<T> with T = bool not supported. Use std::vector instead.");
"irr::core::array<T> with T = bool not supported. Use std::vector instead.");
//! Default constructor for empty array.
array() : m_data(), is_sorted(true)
{ }
array() :
m_data(), is_sorted(true)
{
}
//! Constructs an array and allocates an initial chunk of memory.
/** \param start_count Amount of elements to pre-allocate. */
explicit array(u32 start_count) : m_data(), is_sorted(true)
explicit array(u32 start_count) :
m_data(), is_sorted(true)
{
m_data.reserve(start_count);
}
//! Copy constructor
array(const array<T>& other) : m_data(other.m_data), is_sorted(other.is_sorted)
{ }
array(const array<T> &other) :
m_data(other.m_data), is_sorted(other.is_sorted)
{
}
//! Reallocates the array, make it bigger or smaller.
/** \param new_size New size of array.
@ -46,7 +51,7 @@ public:
enough space is available. Setting this flag to false can speed up
array usage, but may use more memory than required by the data.
*/
void reallocate(u32 new_size, bool canShrink=true)
void reallocate(u32 new_size, bool canShrink = true)
{
size_t allocated = m_data.capacity();
if (new_size < allocated) {
@ -60,42 +65,40 @@ public:
//! Adds an element at back of array.
/** If the array is too small to add this new element it is made bigger.
\param element: Element to add at the back of the array. */
void push_back(const T& element)
void push_back(const T &element)
{
m_data.push_back(element);
is_sorted = false;
}
void push_back(T&& element)
void push_back(T &&element)
{
m_data.push_back(std::move(element));
is_sorted = false;
}
//! Adds an element at the front of the array.
/** If the array is to small to add this new element, the array is
made bigger. Please note that this is slow, because the whole array
needs to be copied for this.
\param element Element to add at the back of the array. */
void push_front(const T& element)
void push_front(const T &element)
{
m_data.insert(m_data.begin(), element);
is_sorted = false;
}
void push_front(T&& element)
void push_front(T &&element)
{
m_data.insert(m_data.begin(), std::move(element));
is_sorted = false;
}
//! Insert item into array at specified position.
/**
\param element: Element to be inserted
\param index: Where position to insert the new element. */
void insert(const T& element, u32 index=0)
void insert(const T &element, u32 index = 0)
{
_IRR_DEBUG_BREAK_IF(index > m_data.size()) // access violation
auto pos = std::next(m_data.begin(), index);
@ -119,7 +122,7 @@ public:
May reduce memory usage, but call is more whenever size changes.
\param newDataIsSorted Info if you pass sorted/unsorted data
*/
void set_data(const T* newData, u32 newSize, bool newDataIsSorted=false, bool canShrink=false)
void set_data(const T *newData, u32 newSize, bool newDataIsSorted = false, bool canShrink = false)
{
m_data.resize(newSize);
if (canShrink) {
@ -133,7 +136,7 @@ public:
/** Like operator ==, but without the need to create the array
\param otherData Address to data against which we compare, must contain size elements
\param size Amount of elements in otherData */
bool equals(const T* otherData, u32 size) const
bool equals(const T *otherData, u32 size) const
{
if (m_data.size() != size)
return false;
@ -148,7 +151,7 @@ public:
}
//! Assignment operator
const array<T>& operator=(const array<T>& other)
const array<T> &operator=(const array<T> &other)
{
if (this == &other)
return *this;
@ -157,14 +160,14 @@ public:
return *this;
}
array<T>& operator=(const std::vector<T> &other)
array<T> &operator=(const std::vector<T> &other)
{
m_data = other;
is_sorted = false;
return *this;
}
array<T>& operator=(std::vector<T> &&other)
array<T> &operator=(std::vector<T> &&other)
{
m_data = std::move(other);
is_sorted = false;
@ -172,71 +175,63 @@ public:
}
//! Equality operator
bool operator == (const array<T>& other) const
bool operator==(const array<T> &other) const
{
return equals(other.const_pointer(), other.size());
}
//! Inequality operator
bool operator != (const array<T>& other) const
bool operator!=(const array<T> &other) const
{
return !(*this==other);
return !(*this == other);
}
//! Direct access operator
T& operator [](u32 index)
T &operator[](u32 index)
{
_IRR_DEBUG_BREAK_IF(index >= m_data.size()) // access violation
return m_data[index];
}
//! Direct const access operator
const T& operator [](u32 index) const
const T &operator[](u32 index) const
{
_IRR_DEBUG_BREAK_IF(index >= m_data.size()) // access violation
return m_data[index];
}
//! Gets last element.
T& getLast()
T &getLast()
{
_IRR_DEBUG_BREAK_IF(m_data.empty()) // access violation
return m_data.back();
}
//! Gets last element
const T& getLast() const
const T &getLast() const
{
_IRR_DEBUG_BREAK_IF(m_data.empty()) // access violation
return m_data.back();
}
//! Gets a pointer to the array.
/** \return Pointer to the array. */
T* pointer()
T *pointer()
{
return m_data.empty() ? nullptr : &m_data[0];
}
//! Gets a const pointer to the array.
/** \return Pointer to the array. */
const T* const_pointer() const
const T *const_pointer() const
{
return m_data.empty() ? nullptr : &m_data[0];
}
//! Get number of occupied elements of the array.
/** \return Size of elements in the array which are actually occupied. */
u32 size() const
@ -244,7 +239,6 @@ public:
return static_cast<u32>(m_data.size());
}
//! Get amount of memory allocated.
/** \return Amount of memory allocated. The amount of bytes
allocated would be allocated_size() * sizeof(ElementTypeUsed); */
@ -253,7 +247,6 @@ public:
return m_data.capacity();
}
//! Check if array is empty.
/** \return True if the array is empty false if not. */
bool empty() const
@ -261,7 +254,6 @@ public:
return m_data.empty();
}
//! Sorts the array using heapsort.
/** There is no additional memory waste and the algorithm performs
O(n*log n) in worst case. */
@ -273,7 +265,6 @@ public:
}
}
//! Performs a binary search for an element, returns -1 if not found.
/** The array will be sorted before the binary search if it is not
already sorted. Caution is advised! Be careful not to call this on
@ -281,7 +272,7 @@ public:
\param element Element to search for.
\return Position of the searched element if it was found,
otherwise -1 is returned. */
s32 binary_search(const T& element)
s32 binary_search(const T &element)
{
sort();
return binary_search(element, 0, (s32)m_data.size() - 1);
@ -293,7 +284,7 @@ public:
\param element Element to search for.
\return Position of the searched element if it was found,
otherwise -1 is returned. */
s32 binary_search(const T& element) const
s32 binary_search(const T &element) const
{
if (is_sorted)
return binary_search(element, 0, (s32)m_data.size() - 1);
@ -307,7 +298,7 @@ public:
\param right Last right index.
\return Position of the searched element if it was found, otherwise -1
is returned. */
s32 binary_search(const T& element, s32 left, s32 right) const
s32 binary_search(const T &element, s32 left, s32 right) const
{
if (left > right)
return -1;
@ -320,7 +311,6 @@ public:
return static_cast<u32>(it - m_data.begin());
}
//! Performs a binary search for an element, returns -1 if not found.
//! it is used for searching a multiset
/** The array will be sorted before the binary search if it is not
@ -329,7 +319,7 @@ public:
\param &last return lastIndex of equal elements
\return Position of the first searched element if it was found,
otherwise -1 is returned. */
s32 binary_search_multi(const T& element, s32 &last)
s32 binary_search_multi(const T &element, s32 &last)
{
sort();
auto iters = std::equal_range(m_data.begin(), m_data.end(), element);
@ -339,14 +329,13 @@ public:
return static_cast<s32>(iters.first - m_data.begin());
}
//! Finds an element in linear time, which is very slow.
/** Use binary_search for faster finding. Only works if ==operator is
implemented.
\param element Element to search for.
\return Position of the searched element if it was found, otherwise -1
is returned. */
s32 linear_search(const T& element) const
s32 linear_search(const T &element) const
{
auto it = std::find(m_data.begin(), m_data.end(), element);
if (it == m_data.end())
@ -354,14 +343,13 @@ public:
return static_cast<u32>(it - m_data.begin());
}
//! Finds an element in linear time, which is very slow.
/** Use binary_search for faster finding. Only works if ==operator is
implemented.
\param element: Element to search for.
\return Position of the searched element if it was found, otherwise -1
is returned. */
s32 linear_reverse_search(const T& element) const
s32 linear_reverse_search(const T &element) const
{
auto it = std::find(m_data.rbegin(), m_data.rend(), element);
if (it == m_data.rend())
@ -370,7 +358,6 @@ public:
return m_data.size() - offset - 1;
}
//! Erases an element from the array.
/** May be slow, because all elements following after the erased
element have to be copied.
@ -382,7 +369,6 @@ public:
m_data.erase(it);
}
//! Erases some elements from the array.
/** May be slow, because all elements following after the erased
element have to be copied.
@ -404,12 +390,11 @@ public:
is_sorted = _is_sorted;
}
//! Swap the content of this array container with the content of another array
/** Afterward this object will contain the content of the other object and the other
object will contain the content of this object.
\param other Swap content with this object */
void swap(array<T>& other)
void swap(array<T> &other)
{
m_data.swap(other.m_data);
std::swap(is_sorted, other.is_sorted);
@ -435,5 +420,3 @@ private:
} // end namespace core
} // end namespace irr