KiCad PCB EDA Suite
INTRUSIVE_LIST< T > Class Template Reference

A lightweight intrusive list container

More...

#include <intrusive_list.h>

Public Member Functions

 INTRUSIVE_LIST ()
 
void ListClear ()
 
T * ListRemove ()
 
int ListSize () const
 
void ListInsert (T *item)
 
T * ListNext () const
 
T * ListPrev () const
 

Private Attributes

int m_count
 
T * m_prev
 
T * m_next
 
T * m_root
 

Detailed Description

template<class T>
class INTRUSIVE_LIST< T >

A lightweight intrusive list container

Definition at line 30 of file intrusive_list.h.

Constructor & Destructor Documentation

template<class T>
INTRUSIVE_LIST< T >::INTRUSIVE_LIST ( )
inline

Definition at line 33 of file intrusive_list.h.

34  {
35  ListClear();
36  }

Member Function Documentation

template<class T>
void INTRUSIVE_LIST< T >::ListClear ( )
inline

Definition at line 38 of file intrusive_list.h.

Referenced by INTRUSIVE_LIST< CN_ITEM >::INTRUSIVE_LIST().

39  {
40  m_prev = nullptr;
41  m_next = nullptr;
42  m_root = (T*) this;
43  m_count = 1;
44  }
template<class T>
void INTRUSIVE_LIST< T >::ListInsert ( T *  item)
inline

Definition at line 74 of file intrusive_list.h.

Referenced by CN_CONNECTIVITY_ALGO::SearchClusters().

75  {
76  if( !m_root )
77  m_root = item;
78 
79  if( m_next )
80  m_next->m_prev = item;
81 
82  item->m_prev = (T*) this;
83  item->m_next = m_next;
84  item->m_root = m_root;
85  m_root->m_count++;
86 
87  m_next = item;
88  }
template<class T>
T* INTRUSIVE_LIST< T >::ListNext ( ) const
inline

Definition at line 90 of file intrusive_list.h.

90 { return m_next; };
template<class T>
T* INTRUSIVE_LIST< T >::ListPrev ( ) const
inline

Definition at line 91 of file intrusive_list.h.

91 { return m_prev; };
template<class T>
T* INTRUSIVE_LIST< T >::ListRemove ( )
inline

Definition at line 46 of file intrusive_list.h.

Referenced by CN_CONNECTIVITY_ALGO::SearchClusters().

47  {
48  if( m_prev )
49  m_prev->m_next = m_next;
50 
51  if( m_next )
52  m_next->m_prev = m_prev;
53 
54  m_root->m_count--;
55 
56  T* rv = nullptr;
57 
58  if( m_prev )
59  rv = m_prev;
60  else if( m_next )
61  rv = m_next;
62 
63  m_root = nullptr;
64  m_prev = nullptr;
65  m_next = nullptr;
66  return rv;
67  }
template<class T>
int INTRUSIVE_LIST< T >::ListSize ( ) const
inline

Definition at line 69 of file intrusive_list.h.

70  {
71  return m_root ? m_root->m_count : 0;
72  }

Member Data Documentation

template<class T>
int INTRUSIVE_LIST< T >::m_count
private

Definition at line 91 of file intrusive_list.h.

Referenced by INTRUSIVE_LIST< CN_ITEM >::ListClear().

template<class T>
T* INTRUSIVE_LIST< T >::m_prev
private

The documentation for this class was generated from the following file: