Skip to content

Commit

Permalink
g++/c++ 20 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
barbibulle committed May 4, 2024
1 parent f6bcd2f commit b92b7c3
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 72 deletions.
22 changes: 11 additions & 11 deletions Source/C++/Core/Ap4Array.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
|
****************************************************************/
/**
* @file
* @file
* @brief Arrays
*/

Expand All @@ -51,15 +51,15 @@ const int AP4_ARRAY_INITIAL_COUNT = 64;
/*----------------------------------------------------------------------
| AP4_Array
+---------------------------------------------------------------------*/
template <typename T>
class AP4_Array
template <typename T>
class AP4_Array
{
public:
// methods
AP4_Array(): m_AllocatedCount(0), m_ItemCount(0), m_Items(0) {}
AP4_Array(const T* items, AP4_Size count);
AP4_Array<T>(const AP4_Array<T>& copy);
AP4_Array<T>& operator=(const AP4_Array<T>& copy);
AP4_Array(const AP4_Array<T>& copy);
AP4_Array& operator=(const AP4_Array& copy);
virtual ~AP4_Array();
AP4_Cardinal ItemCount() const { return m_ItemCount; }
AP4_Result Append(const T& item);
Expand Down Expand Up @@ -190,12 +190,12 @@ AP4_Array<T>::EnsureCapacity(AP4_Cardinal count)
| AP4_Array<T>::SetItemCount
+---------------------------------------------------------------------*/
template <typename T>
AP4_Result
AP4_Result
AP4_Array<T>::SetItemCount(AP4_Cardinal item_count)
{
// shortcut
if (item_count == m_ItemCount) return AP4_SUCCESS;

// check for a reduction in the number of items
if (item_count < m_ItemCount) {
// destruct the items that are no longer needed
Expand All @@ -205,11 +205,11 @@ AP4_Array<T>::SetItemCount(AP4_Cardinal item_count)
m_ItemCount = item_count;
return AP4_SUCCESS;
}

// grow the list
AP4_Result result = EnsureCapacity(item_count);
if (AP4_FAILED(result)) return result;

// construct the new items
for (unsigned int i=m_ItemCount; i<item_count; i++) {
new ((void*)&m_Items[i]) T();
Expand Down Expand Up @@ -247,12 +247,12 @@ AP4_Array<T>::Append(const T& item)

// if that's still not enough, just ask for what we need
if (new_count < m_ItemCount+1) new_count = m_ItemCount+1;

// reserve the space
AP4_Result result = EnsureCapacity(new_count);
if (result != AP4_SUCCESS) return result;
}

// store the item
new ((void*)&m_Items[m_ItemCount++]) T(item);

Expand Down
62 changes: 31 additions & 31 deletions Source/C++/Core/Ap4List.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,24 @@ template <typename T> class AP4_List;
/*----------------------------------------------------------------------
| AP4_List
+---------------------------------------------------------------------*/
template <typename T>
class AP4_List
template <typename T>
class AP4_List
{
public:
// types
class Item
class Item
{
public:
// types
class Operator
class Operator
{
public:
// methods
virtual ~Operator() {}
virtual AP4_Result Action(T* data) const = 0;
};

class Finder
class Finder
{
public:
// methods
Expand All @@ -86,8 +86,8 @@ class AP4_List
};

// methods
AP4_List<T>(): m_ItemCount(0), m_Head(0), m_Tail(0) {}
virtual ~AP4_List<T>();
AP4_List(): m_ItemCount(0), m_Head(0), m_Tail(0) {}
virtual ~AP4_List();
AP4_Result Clear();
AP4_Result Add(T* data);
AP4_Result Add(Item* item);
Expand All @@ -106,17 +106,17 @@ class AP4_List
AP4_Cardinal ItemCount() const { return m_ItemCount; }
Item* FirstItem() const { return m_Head; }
Item* LastItem() const { return m_Tail; }

protected:
// members
AP4_Cardinal m_ItemCount;
Item* m_Head;
Item* m_Tail;

private:
// these cannot be used
AP4_List<T>(const AP4_List<T>&);
AP4_List<T>& operator=(const AP4_List<T>&);
AP4_List(const AP4_List&);
AP4_List& operator=(const AP4_List&);
};

/*----------------------------------------------------------------------
Expand All @@ -137,18 +137,18 @@ AP4_Result
AP4_List<T>::Clear()
{
Item* item = m_Head;

while (item) {
Item* next = item->m_Next;
delete item;
item = next;
}
m_ItemCount = 0;
m_Head = m_Tail = NULL;

return AP4_SUCCESS;
}

/*----------------------------------------------------------------------
| AP4_List<T>::Add
+---------------------------------------------------------------------*/
Expand Down Expand Up @@ -182,7 +182,7 @@ AP4_List<T>::Add(Item* item)

// one more item in the list now
m_ItemCount++;

return AP4_SUCCESS;
}

Expand Down Expand Up @@ -241,7 +241,7 @@ AP4_List<T>::Remove(T* data)
}
item = item->m_Next;
}

return AP4_ERROR_NO_SUCH_ITEM;
}

Expand Down Expand Up @@ -335,20 +335,20 @@ AP4_List<T>::PopHead(T*& data)

// one less item in the list now
m_ItemCount--;

return AP4_SUCCESS;
}

/*----------------------------------------------------------------------
| AP4_List<T>::Apply
+---------------------------------------------------------------------*/
template <typename T>
inline
inline
AP4_Result
AP4_List<T>::Apply(const typename Item::Operator& op) const
{
Item* item = m_Head;

while (item) {
op.Action(item->m_Data);
item = item->m_Next;
Expand All @@ -361,12 +361,12 @@ AP4_List<T>::Apply(const typename Item::Operator& op) const
| AP4_List<T>::ApplyUntilFailure
+---------------------------------------------------------------------*/
template <typename T>
inline
inline
AP4_Result
AP4_List<T>::ApplyUntilFailure(const typename Item::Operator& op) const
{
Item* item = m_Head;

while (item) {
AP4_Result result;
result = op.Action(item->m_Data);
Expand All @@ -381,12 +381,12 @@ AP4_List<T>::ApplyUntilFailure(const typename Item::Operator& op) const
| AP4_List<T>::ApplyUntilSuccess
+---------------------------------------------------------------------*/
template <typename T>
inline
inline
AP4_Result
AP4_List<T>::ApplyUntilSuccess(const typename Item::Operator& op) const
{
Item* item = m_Head;

while (item) {
AP4_Result result;
result = op.Action(item->m_Data);
Expand All @@ -401,12 +401,12 @@ AP4_List<T>::ApplyUntilSuccess(const typename Item::Operator& op) const
| AP4_List<T>::ReverseApply
+---------------------------------------------------------------------*/
template <typename T>
inline
inline
AP4_Result
AP4_List<T>::ReverseApply(const typename Item::Operator& op) const
{
Item* item = m_Tail;

while (item) {
if (op.Action(item->m_Data) != AP4_SUCCESS) {
return AP4_ERROR_LIST_OPERATION_ABORTED;
Expand All @@ -421,12 +421,12 @@ AP4_List<T>::ReverseApply(const typename Item::Operator& op) const
| AP4_List<T>::Find
+---------------------------------------------------------------------*/
template <typename T>
inline
inline
AP4_Result
AP4_List<T>::Find(const typename Item::Finder& finder, T*& data) const
{
Item* item = m_Head;

while (item) {
if (finder.Test(item->m_Data) == AP4_SUCCESS) {
data = item->m_Data;
Expand All @@ -443,12 +443,12 @@ AP4_List<T>::Find(const typename Item::Finder& finder, T*& data) const
| AP4_List<T>::ReverseFind
+---------------------------------------------------------------------*/
template <typename T>
inline
inline
AP4_Result
AP4_List<T>::ReverseFind(const typename Item::Finder& finder, T*& data) const
{
Item* item = m_Tail;

while (item) {
if (finder.Test(item->m_Data) == AP4_SUCCESS) {
data = item->m_Data;
Expand All @@ -465,12 +465,12 @@ AP4_List<T>::ReverseFind(const typename Item::Finder& finder, T*& data) const
| AP4_List<T>::DeleteReferences
+---------------------------------------------------------------------*/
template <typename T>
inline
inline
AP4_Result
AP4_List<T>::DeleteReferences()
{
Item* item = m_Head;

while (item) {
Item* next = item->m_Next;
delete item->m_Data;
Expand Down
Loading

0 comments on commit b92b7c3

Please sign in to comment.