KiCad PCB EDA Suite
DHEAD Class Reference

Class DHEAD is only for use by template class DLIST, use that instead. More...

#include <dlist.h>

Inheritance diagram for DHEAD:
DLIST< T > DLIST< BOARD_ITEM > DLIST< D_PAD > DLIST< GERBER_DRAW_ITEM > DLIST< MODULE > DLIST< SCH_ITEM > DLIST< SEGZONE > DLIST< TRACK >

Public Member Functions

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

 DHEAD ()
 Constructor DHEAD is protected so that a DHEAD can only be instantiated from within a DLIST template. More...
 
 ~DHEAD ()
 
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

Class DHEAD is only for use by template class DLIST, use that instead.

Definition at line 40 of file dlist.h.

Constructor & Destructor Documentation

DHEAD::DHEAD ( )
inlineprotected

Constructor DHEAD is protected so that a DHEAD can only be instantiated from within a DLIST template.

Definition at line 53 of file dlist.h.

53  :
54  first(0),
55  last(0),
56  count(0),
57  meOwner(true)
58  {
59  }
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
EDA_ITEM * first
first element in list, or NULL if list empty
Definition: dlist.h:43
DHEAD::~DHEAD ( )
protected

Definition at line 34 of file dlist.cpp.

References DeleteAll(), and meOwner.

35 {
36  if( meOwner )
37  DeleteAll();
38 }
void DeleteAll()
Function DeleteAll deletes all items on the list and leaves the list empty.
Definition: dlist.cpp:41
bool meOwner
I must delete the objects I hold in my destructor.
Definition: dlist.h:46

Member Function Documentation

void DHEAD::append ( EDA_ITEM aNewElement)
protected

Function append adds aNewElement to the end of the list.

Parameters
aNewElementThe element to insert.

Definition at line 59 of file dlist.cpp.

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

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

60 {
61  wxASSERT( aNewElement != NULL );
62 
63  if( first ) // list is not empty, first is not touched
64  {
65  wxASSERT( last != NULL );
66 
67  aNewElement->SetNext( 0 );
68  aNewElement->SetBack( last );
69 
70  last->SetNext( aNewElement );
71  last = aNewElement;
72  }
73  else // list is empty, first and last are changed
74  {
75  aNewElement->SetNext( 0 );
76  aNewElement->SetBack( 0 );
77 
78  first = aNewElement;
79  last = aNewElement;
80  }
81 
82  aNewElement->SetList( this );
83 
84  ++count;
85 }
void SetBack(EDA_ITEM *aBack)
Definition: base_struct.h:212
void SetList(DHEAD *aList)
Definition: base_struct.h:214
unsigned count
how many elements are in the list, automatically maintained.
Definition: dlist.h:45
void SetNext(EDA_ITEM *aNext)
Definition: base_struct.h:211
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
void DHEAD::append ( DHEAD aList)
protected

Function append adds aList to the end of the list.

Parameters
aListThe list to aList.

Definition at line 88 of file dlist.cpp.

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

89 {
90  if( aList.first )
91  {
92  // Change the item's list to me.
93  for( EDA_ITEM* item = aList.first; item; item = item->Next() )
94  item->SetList( this );
95 
96  if( first ) // this list is not empty, set last item's next to the first item in aList
97  {
98  wxCHECK_RET( last != NULL, wxT( "Last list element not set." ) );
99 
100  last->SetNext( aList.first );
101  aList.first->SetBack( last );
102  last = aList.last;
103  }
104  else // this list is empty, first and last are same as aList
105  {
106  first = aList.first;
107  last = aList.last;
108  }
109 
110  count += aList.count;
111 
112  aList.count = 0;
113  aList.first = NULL;
114  aList.last = NULL;
115  }
116 }
void SetBack(EDA_ITEM *aBack)
Definition: base_struct.h:212
EDA_ITEM * Next() const
Definition: base_struct.h:206
unsigned count
how many elements are in the list, automatically maintained.
Definition: dlist.h:45
void SetNext(EDA_ITEM *aNext)
Definition: base_struct.h:211
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:151
EDA_ITEM * first
first element in list, or NULL if list empty
Definition: dlist.h:43
void DHEAD::DeleteAll ( )

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

The destructor for each item is called.

Definition at line 41 of file dlist.cpp.

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

Referenced by Abort_Create_Track(), AbortCreateNewLine(), FOOTPRINT_VIEWER_FRAME::ClickOnFootprintList(), PCB_EDIT_FRAME::Fill_All_Zones(), SCH_SCREEN::FreeDrawList(), DISPLAY_FOOTPRINTS_FRAME::InitDisplay(), MODULE::operator=(), PCB_EDIT_FRAME::Process_Special_Functions(), FOOTPRINT_WIZARD_FRAME::ReloadFootprint(), FOOTPRINT_VIEWER_FRAME::SelectAndViewFootprint(), ~DHEAD(), and GERBER_FILE_IMAGE::~GERBER_FILE_IMAGE().

42 {
43  EDA_ITEM* next;
44  EDA_ITEM* item = first;
45 
46  while( item )
47  {
48  next = item->Next();
49  delete item; // virtual destructor, class specific
50  item = next;
51  }
52 
53  first = 0;
54  last = 0;
55  count = 0;
56 }
CITER next(CITER it)
Definition: ptree.cpp:130
EDA_ITEM * Next() const
Definition: base_struct.h:206
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
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:151
EDA_ITEM * first
first element in list, or NULL if list empty
Definition: dlist.h:43
void DHEAD::insert ( EDA_ITEM aNewElement,
EDA_ITEM aElementAfterMe 
)
protected

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 119 of file dlist.cpp.

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

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

120 {
121  wxASSERT( aNewElement != NULL );
122 
123  if( !aAfterMe )
124  append( aNewElement );
125  else
126  {
127  wxASSERT( aAfterMe->GetList() == this );
128 
129  // the list cannot be empty if aAfterMe is supposedly on the list
130  wxASSERT( first && last );
131 
132  if( first == aAfterMe )
133  {
134  aAfterMe->SetBack( aNewElement );
135 
136  aNewElement->SetBack( 0 ); // first in list does not point back
137  aNewElement->SetNext( aAfterMe );
138 
139  first = aNewElement;
140  }
141  else
142  {
143  EDA_ITEM* oldBack = aAfterMe->Back();
144 
145  aAfterMe->SetBack( aNewElement );
146 
147  aNewElement->SetBack( oldBack );
148  aNewElement->SetNext( aAfterMe );
149 
150  oldBack->SetNext( aNewElement );
151  }
152 
153  aNewElement->SetList( this );
154 
155  ++count;
156  }
157 }
void SetBack(EDA_ITEM *aBack)
Definition: base_struct.h:212
EDA_ITEM * Back() const
Definition: base_struct.h:207
void SetList(DHEAD *aList)
Definition: base_struct.h:214
unsigned count
how many elements are in the list, automatically maintained.
Definition: dlist.h:45
void SetNext(EDA_ITEM *aNext)
Definition: base_struct.h:211
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:151
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:59
void DHEAD::insert ( EDA_ITEM aNewElement)
inlineprotected

Function insert puts aNewElement in front of list sequence.

Parameters
aNewElementThe element to insert.

Definition at line 92 of file dlist.h.

References 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:119
EDA_ITEM * first
first element in list, or NULL if list empty
Definition: dlist.h:43
void DHEAD::remove ( EDA_ITEM aElement)
protected

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

Parameters
aElementThe element to remove.

Definition at line 160 of file dlist.cpp.

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

161 {
162  wxASSERT( aElement );
163  wxASSERT( aElement->GetList() == this );
164 
165  if( aElement->Next() )
166  {
167  aElement->Next()->SetBack( aElement->Back() );
168  }
169  else // element being removed is last
170  {
171  wxASSERT( last == aElement );
172  last = aElement->Back();
173  }
174 
175  if( aElement->Back() )
176  {
177  aElement->Back()->SetNext( aElement->Next() );
178  }
179  else // element being removed is first
180  {
181  wxASSERT( first == aElement );
182  first = aElement->Next();
183  }
184 
185  aElement->SetBack( 0 );
186  aElement->SetNext( 0 );
187  aElement->SetList( 0 );
188 
189  --count;
190 }
DHEAD * GetList() const
Definition: base_struct.h:209
void SetBack(EDA_ITEM *aBack)
Definition: base_struct.h:212
EDA_ITEM * Back() const
Definition: base_struct.h:207
void SetList(DHEAD *aList)
Definition: base_struct.h:214
EDA_ITEM * Next() const
Definition: base_struct.h:206
unsigned count
how many elements are in the list, automatically maintained.
Definition: dlist.h:45
void SetNext(EDA_ITEM *aNext)
Definition: base_struct.h:211
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
void DHEAD::SetOwnership ( bool  Iown)
inline

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_EDIT_FRAME::Process_Special_Functions(), and SCH_EDIT_FRAME::PutDataInPreviousState().

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
protected

how many elements are in the list, automatically maintained.

Definition at line 45 of file dlist.h.

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

EDA_ITEM* DHEAD::first
protected

first element in list, or NULL if list empty

Definition at line 43 of file dlist.h.

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

EDA_ITEM* DHEAD::last
protected

last elment in list, or NULL if empty

Definition at line 44 of file dlist.h.

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

bool DHEAD::meOwner
protected

I must delete the objects I hold in my destructor.

Definition at line 46 of file dlist.h.

Referenced by ~DHEAD().


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