KiCad PCB EDA Suite
DLIST< T > Class Template Reference

Class DLIST is the head of a doubly linked list. More...

#include <dlist.h>

Inheritance diagram for DLIST< T >:
DHEAD

Public Member Functions

 operator T * () const
 operator T* is a casting operator that returns GetFirst(), a T* More...
 
T * operator-> () const
 operator -> is a dereferencing operator that returns GetFirst(), a T* More...
 
T * GetFirst () const
 Function GetFirst returns the first T* in the list without removing it, or NULL if the list is empty. More...
 
T * GetLast () const
 Function GetLast returns the last T* in the list without removing it, or NULL if the list is empty. More...
 
void Append (T *aNewElement)
 Function Append adds aNewElement to the end of the list. More...
 
void Append (DLIST &aList)
 Function Append adds aList to the end of the list. More...
 
void Insert (T *aNewElement, T *aElementAfterMe)
 Function Insert puts aNewElement just in front of aElementAfterMe in the list sequence. More...
 
T * Remove (T *aElement)
 Function Remove removes aElement from the list, but does not delete it. More...
 
T * begin () const
 
T * end () const
 
T * PopFront ()
 
T * PopBack ()
 
void PushFront (T *aNewElement)
 Function PushFront puts aNewElement at front of list sequence. More...
 
void PushBack (T *aNewElement)
 Function PushBack puts aNewElement at the end of the list sequence. More...
 
void DeleteAll ()
 Function DeleteAll deletes all items on the list and leaves the list empty. More...
 
void SetOwnership (bool Iown)
 Function SetOwnership controls whether the list owns the objects and is responsible for deleteing their memory at time of this object's destruction. More...
 
unsigned GetCount () const
 Function GetCount returns the number of elements in the list. More...
 

Protected Member Functions

void append (EDA_ITEM *aNewElement)
 Function append adds aNewElement to the end of the list. More...
 
void append (DHEAD &aList)
 Function append adds aList to the end of the list. More...
 
void insert (EDA_ITEM *aNewElement, EDA_ITEM *aElementAfterMe)
 Function insert puts aNewElement just in front of aElementAfterMe in the list sequence. More...
 
void insert (EDA_ITEM *aNewElement)
 Function insert puts aNewElement in front of list sequence. More...
 
void remove (EDA_ITEM *aElement)
 Function remove removes aElement from the list, but does not delete it. More...
 

Protected Attributes

EDA_ITEMfirst
 first element in list, or NULL if list empty More...
 
EDA_ITEMlast
 last elment in list, or NULL if empty More...
 
unsigned count
 how many elements are in the list, automatically maintained. More...
 
bool meOwner
 I must delete the objects I hold in my destructor. More...
 

Detailed Description

template<class T>
class DLIST< T >

Class DLIST is the head of a doubly linked list.

It contains pointers to the first and last elements in a doubly linked list. The elements in the list must be of class T or derived from T, and T must be derived from EDA_ITEM.

See also
DHEAD for additional public functions.

Definition at line 142 of file dlist.h.

Member Function Documentation

void DHEAD::append ( EDA_ITEM aNewElement)
protectedinherited

Function append adds aNewElement to the end of the list.

Parameters
aNewElementThe element to insert.

Definition at line 63 of file dlist.cpp.

References CHECK_OWNERSHIP, DHEAD::count, DHEAD::first, DHEAD::last, EDA_ITEM::Next(), EDA_ITEM::SetBack(), EDA_ITEM::SetList(), and EDA_ITEM::SetNext().

Referenced by DLIST< TRACK >::Append(), DHEAD::DHEAD(), DHEAD::insert(), and DLIST< TRACK >::PushBack().

64 {
65  wxCHECK( aNewElement, /*void*/ );
66 
67  if( first ) // list is not empty, first is not touched
68  {
69  wxASSERT( count > 0 );
70  wxCHECK( last, /*void*/ ); // 'first' is non-null, so 'last' should be non-null too
71 
72  aNewElement->SetNext( 0 );
73  aNewElement->SetBack( last );
74 
75  wxASSERT( !last->Next() ); // the last element should point to nullptr
76  last->SetNext( aNewElement );
77  last = aNewElement;
78  }
79  else // list is empty, first and last are changed
80  {
81  wxASSERT( count == 0 );
82  wxASSERT( !last ); // 'first' is null, then 'last' should be too
83  aNewElement->SetNext( 0 );
84  aNewElement->SetBack( 0 );
85 
86  first = aNewElement;
87  last = aNewElement;
88  }
89 
90  CHECK_OWNERSHIP( aNewElement );
91  aNewElement->SetList( this );
92 
93  ++count;
94 }
void SetBack(EDA_ITEM *aBack)
Definition: base_struct.h:215
void SetList(DHEAD *aList)
Definition: base_struct.h:217
EDA_ITEM * Next() const
Definition: base_struct.h:209
unsigned count
how many elements are in the list, automatically maintained.
Definition: dlist.h:45
void SetNext(EDA_ITEM *aNext)
Definition: base_struct.h:214
EDA_ITEM * last
last elment in list, or NULL if empty
Definition: dlist.h:44
EDA_ITEM * first
first element in list, or NULL if list empty
Definition: dlist.h:43
#define CHECK_OWNERSHIP(a)
Definition: dlist.cpp:32
void DHEAD::append ( DHEAD aList)
protectedinherited

Function append adds aList to the end of the list.

Parameters
aListThe list to aList.

Definition at line 97 of file dlist.cpp.

References DHEAD::count, DHEAD::first, DHEAD::last, EDA_ITEM::Next(), EDA_ITEM::SetBack(), and EDA_ITEM::SetNext().

98 {
99  if( aList.first )
100  {
101  // Change the item's list to me.
102  for( EDA_ITEM* item = aList.first; item; item = item->Next() )
103  {
104  wxASSERT( item->GetList() == &aList );
105  item->SetList( this );
106  }
107 
108  if( first ) // this list is not empty, set last item's next to the first item in aList
109  {
110  wxCHECK_RET( last != NULL, wxT( "Last list element not set." ) );
111 
112  last->SetNext( aList.first );
113  aList.first->SetBack( last );
114  last = aList.last;
115  }
116  else // this list is empty, first and last are same as aList
117  {
118  first = aList.first;
119  last = aList.last;
120  }
121 
122  count += aList.count;
123 
124  aList.count = 0;
125  aList.first = NULL;
126  aList.last = NULL;
127  }
128 }
void SetBack(EDA_ITEM *aBack)
Definition: base_struct.h:215
EDA_ITEM * Next() const
Definition: base_struct.h:209
unsigned count
how many elements are in the list, automatically maintained.
Definition: dlist.h:45
void SetNext(EDA_ITEM *aNext)
Definition: base_struct.h:214
EDA_ITEM * last
last elment in list, or NULL if empty
Definition: dlist.h:44
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:154
EDA_ITEM * first
first element in list, or NULL if list empty
Definition: dlist.h:43
template<class T>
void DLIST< T >::Append ( T *  aNewElement)
inline

Function Append adds aNewElement to the end of the list.

Parameters
aNewElementThe element to insert.

Definition at line 177 of file dlist.h.

Referenced by PCAD2KICAD::PCB_LINE::AddToBoard(), PCAD2KICAD::PCB_PAD::AddToBoard(), SCH_SCREEN::Append(), PCB_EDIT_FRAME::Exchange_Module(), GERBER_FILE_IMAGE::Execute_DCODE_Command(), SCH_SCREEN::ReplaceWires(), and GERBER_FILE_IMAGE::StepAndRepeatItem().

178  {
179  append( aNewElement );
180  }
void append(EDA_ITEM *aNewElement)
Function append adds aNewElement to the end of the list.
Definition: dlist.cpp:63
template<class T>
void DLIST< T >::Append ( DLIST< T > &  aList)
inline

Function Append adds aList to the end of the list.

Parameters
aListThe list to append to the end of the list.

Definition at line 187 of file dlist.h.

188  {
189  append( aList );
190  }
void append(EDA_ITEM *aNewElement)
Function append adds aNewElement to the end of the list.
Definition: dlist.cpp:63
void DHEAD::DeleteAll ( )
inherited

Function DeleteAll deletes all items on the list and leaves the list empty.

The destructor for each item is called.

Definition at line 44 of file dlist.cpp.

References DHEAD::count, DHEAD::first, DHEAD::last, DHEAD::meOwner, next(), and EDA_ITEM::Next().

Referenced by Abort_Create_Track(), AbortCreateNewLine(), FOOTPRINT_VIEWER_FRAME::ClickOnFootprintList(), ZONE_FILLER::Fill(), SCH_SCREEN::FreeDrawList(), DSN::SPECCTRA_DB::FromSESSION(), DISPLAY_FOOTPRINTS_FRAME::InitDisplay(), DHEAD::insert(), MODULE::operator=(), PCB_EDIT_FRAME::Process_Special_Functions(), FOOTPRINT_WIZARD_FRAME::ReloadFootprint(), FOOTPRINT_VIEWER_FRAME::SelectAndViewFootprint(), DHEAD::~DHEAD(), and GERBER_FILE_IMAGE::~GERBER_FILE_IMAGE().

45 {
46  wxCHECK( meOwner, /*void*/ ); // only owning lists may delete the contents
47  EDA_ITEM* next;
48  EDA_ITEM* item = first;
49 
50  while( item )
51  {
52  next = item->Next();
53  delete item; // virtual destructor, class specific
54  item = next;
55  }
56 
57  first = 0;
58  last = 0;
59  count = 0;
60 }
CITER next(CITER it)
Definition: ptree.cpp:130
EDA_ITEM * Next() const
Definition: base_struct.h:209
unsigned count
how many elements are in the list, automatically maintained.
Definition: dlist.h:45
EDA_ITEM * last
last elment in list, or NULL if empty
Definition: dlist.h:44
bool meOwner
I must delete the objects I hold in my destructor.
Definition: dlist.h:46
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:154
EDA_ITEM * first
first element in list, or NULL if list empty
Definition: dlist.h:43
template<class T>
T* DLIST< T >::end ( ) const
inline

Definition at line 219 of file dlist.h.

219 { return NULL; }
template<class T>
T* DLIST< T >::GetLast ( ) const
inline

Function GetLast returns the last T* in the list without removing it, or NULL if the list is empty.

Definition at line 170 of file dlist.h.

Referenced by PCB_EDIT_FRAME::AppendBoardFile(), DrawSegment(), SCH_EDIT_FRAME::EndSegment(), GERBER_FILE_IMAGE::Execute_DCODE_Command(), GERBER_FILE_IMAGE::Execute_G_Command(), TRACK::GetBestInsertPoint(), DIALOG_EXCHANGE_FOOTPRINTS::processMatchingModules(), BOARD::ReplaceNetlist(), and BOARD_NETLIST_UPDATER::UpdateNetlist().

170 { return (T*) last; }
EDA_ITEM * last
last elment in list, or NULL if empty
Definition: dlist.h:44
void DHEAD::insert ( EDA_ITEM aNewElement,
EDA_ITEM aElementAfterMe 
)
protectedinherited

Function insert puts aNewElement just in front of aElementAfterMe in the list sequence.

If aElementAfterMe is NULL, then simply append().

Parameters
aNewElementThe element to insert.
aElementAfterMeThe element to insert aNewElement before, if NULL then append aNewElement onto end of list.

Definition at line 131 of file dlist.cpp.

References DHEAD::append(), EDA_ITEM::Back(), CHECK_OWNERSHIP, DHEAD::count, DHEAD::first, EDA_ITEM::GetList(), DHEAD::last, EDA_ITEM::SetBack(), EDA_ITEM::SetList(), and EDA_ITEM::SetNext().

Referenced by DHEAD::DHEAD(), DHEAD::insert(), DLIST< TRACK >::Insert(), and DLIST< TRACK >::PushFront().

132 {
133  wxCHECK( aNewElement, /*void*/ );
134 
135  if( !aAfterMe )
136  append( aNewElement );
137  else
138  {
139  wxCHECK( aAfterMe->GetList() == this, /*void*/ );
140 
141  // the list cannot be empty if aAfterMe is supposedly on the list
142  wxASSERT( first && last && count > 0 );
143 
144  if( first == aAfterMe )
145  {
146  aAfterMe->SetBack( aNewElement );
147 
148  aNewElement->SetBack( 0 ); // first in list does not point back
149  aNewElement->SetNext( aAfterMe );
150 
151  first = aNewElement;
152  }
153  else
154  {
155  EDA_ITEM* oldBack = aAfterMe->Back();
156 
157  aAfterMe->SetBack( aNewElement );
158 
159  aNewElement->SetBack( oldBack );
160  aNewElement->SetNext( aAfterMe );
161 
162  oldBack->SetNext( aNewElement );
163  }
164 
165  CHECK_OWNERSHIP( aNewElement );
166  aNewElement->SetList( this );
167 
168  ++count;
169  }
170 }
void SetBack(EDA_ITEM *aBack)
Definition: base_struct.h:215
EDA_ITEM * Back() const
Definition: base_struct.h:210
void SetList(DHEAD *aList)
Definition: base_struct.h:217
unsigned count
how many elements are in the list, automatically maintained.
Definition: dlist.h:45
void SetNext(EDA_ITEM *aNext)
Definition: base_struct.h:214
EDA_ITEM * last
last elment in list, or NULL if empty
Definition: dlist.h:44
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:154
EDA_ITEM * first
first element in list, or NULL if list empty
Definition: dlist.h:43
void append(EDA_ITEM *aNewElement)
Function append adds aNewElement to the end of the list.
Definition: dlist.cpp:63
#define CHECK_OWNERSHIP(a)
Definition: dlist.cpp:32
void DHEAD::insert ( EDA_ITEM aNewElement)
inlineprotectedinherited

Function insert puts aNewElement in front of list sequence.

Parameters
aNewElementThe element to insert.

Definition at line 92 of file dlist.h.

References DHEAD::DeleteAll(), and DHEAD::insert().

93  {
94  insert( aNewElement, first );
95  }
void insert(EDA_ITEM *aNewElement, EDA_ITEM *aElementAfterMe)
Function insert puts aNewElement just in front of aElementAfterMe in the list sequence.
Definition: dlist.cpp:131
EDA_ITEM * first
first element in list, or NULL if list empty
Definition: dlist.h:43
template<class T>
void DLIST< T >::Insert ( T *  aNewElement,
T *  aElementAfterMe 
)
inline

Function Insert puts aNewElement just in front of aElementAfterMe in the list sequence.

If aElementAfterMe is NULL, then simply Append()

Parameters
aNewElementThe element to insert.
aElementAfterMeThe element to insert aNewElement before, if NULL then append aNewElement onto end of list.

Definition at line 200 of file dlist.h.

Referenced by BOARD::Add(), PCB_EDIT_FRAME::Add45DegreeSegment(), AddNewTrace(), FOOTPRINT_EDIT_FRAME::Begin_Edge_Module(), MWAVE::CreateMicrowaveInductor(), PCB_EDIT_FRAME::End_Route(), and SCH_EDIT_FRAME::SaveWireImage().

201  {
202  insert( aNewElement, aElementAfterMe );
203  }
void insert(EDA_ITEM *aNewElement, EDA_ITEM *aElementAfterMe)
Function insert puts aNewElement just in front of aElementAfterMe in the list sequence.
Definition: dlist.cpp:131
template<class T>
DLIST< T >::operator T * ( ) const
inline

operator T* is a casting operator that returns GetFirst(), a T*

Definition at line 150 of file dlist.h.

150 { return GetFirst(); }
T * GetFirst() const
Function GetFirst returns the first T* in the list without removing it, or NULL if the list is empty...
Definition: dlist.h:163
template<class T>
T* DLIST< T >::operator-> ( ) const
inline

operator -> is a dereferencing operator that returns GetFirst(), a T*

Definition at line 156 of file dlist.h.

156 { return GetFirst(); }
T * GetFirst() const
Function GetFirst returns the first T* in the list without removing it, or NULL if the list is empty...
Definition: dlist.h:163
template<class T>
T* DLIST< T >::PopBack ( )
inline

Definition at line 228 of file dlist.h.

Referenced by PCB_EDIT_FRAME::Delete_Segment(), and OrCell_Trace().

229  {
230  if( GetLast() )
231  return Remove( GetLast() );
232  return NULL;
233  }
T * Remove(T *aElement)
Function Remove removes aElement from the list, but does not delete it.
Definition: dlist.h:211
T * GetLast() const
Function GetLast returns the last T* in the list without removing it, or NULL if the list is empty...
Definition: dlist.h:170
template<class T>
T* DLIST< T >::PopFront ( )
inline

Definition at line 221 of file dlist.h.

Referenced by AddNewTrace(), PCB_EDIT_FRAME::End_Route(), and moveNoFlagToVector().

222  {
223  if( GetFirst() )
224  return Remove( GetFirst() );
225  return NULL;
226  }
T * Remove(T *aElement)
Function Remove removes aElement from the list, but does not delete it.
Definition: dlist.h:211
T * GetFirst() const
Function GetFirst returns the first T* in the list without removing it, or NULL if the list is empty...
Definition: dlist.h:163
template<class T>
void DLIST< T >::PushFront ( T *  aNewElement)
inline

Function PushFront puts aNewElement at front of list sequence.

Parameters
aNewElementThe element to insert at the front of the list.

Definition at line 240 of file dlist.h.

Referenced by MODULE::Add(), BOARD::Add(), FOOTPRINT_EDIT_FRAME::Begin_Edge_Module(), CopyMarkedItems(), PCB_EDIT_FRAME::Create_MuWavePolygonShape(), MWAVE::CreateMicrowaveInductor(), PCB_EDIT_FRAME::CreateMuWaveBaseFootprint(), and FOOTPRINT_EDIT_FRAME::CreateTextModule().

241  {
242  insert( aNewElement );
243  }
void insert(EDA_ITEM *aNewElement, EDA_ITEM *aElementAfterMe)
Function insert puts aNewElement just in front of aElementAfterMe in the list sequence.
Definition: dlist.cpp:131
void DHEAD::remove ( EDA_ITEM aElement)
protectedinherited

Function remove removes aElement from the list, but does not delete it.

Parameters
aElementThe element to remove.

Definition at line 173 of file dlist.cpp.

References EDA_ITEM::Back(), DHEAD::count, DHEAD::first, EDA_ITEM::GetList(), i, DHEAD::last, EDA_ITEM::Next(), EDA_ITEM::SetBack(), EDA_ITEM::SetList(), and EDA_ITEM::SetNext().

174 {
175  wxCHECK( aElement && aElement->GetList() == this, /*void*/ );
176 
177  if( aElement->Next() )
178  {
179  aElement->Next()->SetBack( aElement->Back() );
180  }
181  else // element being removed is last
182  {
183  wxASSERT( last == aElement );
184  last = aElement->Back();
185  }
186 
187  if( aElement->Back() )
188  {
189  aElement->Back()->SetNext( aElement->Next() );
190  }
191  else // element being removed is first
192  {
193  wxASSERT( first == aElement );
194  first = aElement->Next();
195  }
196 
197  aElement->SetBack( 0 );
198  aElement->SetNext( 0 );
199  aElement->SetList( 0 );
200 
201  --count;
202  wxASSERT( ( first && last ) || count == 0 );
203 }
DHEAD * GetList() const
Definition: base_struct.h:212
void SetBack(EDA_ITEM *aBack)
Definition: base_struct.h:215
EDA_ITEM * Back() const
Definition: base_struct.h:210
void SetList(DHEAD *aList)
Definition: base_struct.h:217
EDA_ITEM * Next() const
Definition: base_struct.h:209
unsigned count
how many elements are in the list, automatically maintained.
Definition: dlist.h:45
void SetNext(EDA_ITEM *aNext)
Definition: base_struct.h:214
EDA_ITEM * last
last elment in list, or NULL if empty
Definition: dlist.h:44
EDA_ITEM * first
first element in list, or NULL if list empty
Definition: dlist.h:43
template<class T>
T* DLIST< T >::Remove ( T *  aElement)
inline

Function Remove removes aElement from the list, but does not delete it.

Parameters
aElementThe element to remove from the list.
Returns
T* - the removed element, so you can easily delete it upon return.

Definition at line 211 of file dlist.h.

Referenced by PCB_EDIT_FRAME::Delete_net(), SCH_SCREEN::DeleteItem(), DeleteNullTrackSegments(), MODULE::Remove(), SCH_SCREEN::Remove(), BOARD::Remove(), PCB_EDIT_FRAME::Remove_One_Track(), and RemoveBacktracks().

212  {
213  remove( aElement );
214  return aElement;
215  }
void DHEAD::SetOwnership ( bool  Iown)
inlineinherited

Function SetOwnership controls whether the list owns the objects and is responsible for deleteing their memory at time of this object's destruction.

Definition at line 119 of file dlist.h.

Referenced by SCH_SCREEN::Append().

119 { meOwner = Iown; }
bool meOwner
I must delete the objects I hold in my destructor.
Definition: dlist.h:46

Member Data Documentation

unsigned DHEAD::count
protectedinherited

how many elements are in the list, automatically maintained.

Definition at line 45 of file dlist.h.

Referenced by DHEAD::append(), DHEAD::DeleteAll(), DHEAD::GetCount(), DHEAD::insert(), and DHEAD::remove().

EDA_ITEM* DHEAD::first
protectedinherited

first element in list, or NULL if list empty

Definition at line 43 of file dlist.h.

Referenced by DHEAD::append(), DHEAD::DeleteAll(), DLIST< TRACK >::GetFirst(), DHEAD::insert(), and DHEAD::remove().

EDA_ITEM* DHEAD::last
protectedinherited

last elment in list, or NULL if empty

Definition at line 44 of file dlist.h.

Referenced by DHEAD::append(), DHEAD::DeleteAll(), DLIST< TRACK >::GetLast(), DHEAD::insert(), and DHEAD::remove().

bool DHEAD::meOwner
protectedinherited

I must delete the objects I hold in my destructor.

Definition at line 46 of file dlist.h.

Referenced by DHEAD::DeleteAll(), and DHEAD::~DHEAD().


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