Laxkit
0.0.7.1
|
A generic stack for pointers (like anXWindow *, char *), not values. More...
Public Member Functions | |
PtrStack (char nar=1) | |
virtual | ~PtrStack () |
PtrStack Destructor, just calls flush(). | |
virtual T * | operator[] (int i) |
Return pointer to element i, or NULL. | |
virtual void | flush () |
Flush the stack. Makes e==NULL. | |
virtual int | howmany () |
Returns how many things are on the stack. | |
virtual void | swap (int i1, int i2) |
Swap the elements with indices i1 and i2. | |
virtual int | push (T *nd, char local=-1, int where=-1) |
Push a pointer onto the stack before index where. Transfers pointer, does not duplicate. | |
virtual int | popp (T *topop, int *local=NULL) |
Pop the first item that points where topop points. | |
virtual int | pop (T *&popped, int which=-1, int *local=NULL) |
Pop element with index which (defaults to top), and make popped point to it. | |
virtual T * | pop (int which=-1, int *local=NULL) |
Pop element with index which, or the top if which not specified. | |
virtual int | findindex (T *t) |
Find the index (in the range [0,n-1]) corresponding to the pointer t. | |
virtual int | remove (int which=-1) |
Pop and delete (if islocal) the element at index which. | |
virtual int | pushnodup (T *nd, char local, int where=-1) |
Pushes an element only if it is not already on the stack. | |
virtual void | Delta (int ndelta) |
Set the delta. | |
virtual int | Delta () |
Get the delta. | |
virtual T ** | extractArrays (char **local=NULL, int *nn=NULL) |
Return the e and islocal arrays, and internally set them to NULL, max=n=0. | |
virtual int | insertArrays (T **a, char *nl, int nn) |
Flush, then use a as the new array. |
Public Attributes | |
char * | islocal |
int | n |
The number of elements on the stack. | |
T ** | e |
The elements of the stack. |
Protected Attributes | |
int | max |
The number of spaces allocated in the internal array. | |
int | delta |
Size of chunks of memory to add or remove from internal array. | |
char | arrays |
The default local value for elements of the stack. |
A generic stack for pointers (like anXWindow *, char *), not values.
The internal array has max elements allocated. When an item is pushed, and the number of actual elements is greater than max, then the array is reallocated with max+delta spaces. If an element is popped, and the number of elements is less than max-2*delta, then the array is reallocated with max-delta spaces.
If created PtrStack(2), then all the elements are assumed to be arrays, and will be deleted with a call like delete[] element
rather than delete element
. If PtrStack(1) (the defualt constructor), then default is delete item. If PtrStack(0), then default is to not delete at all.
When elements are pushed, there is the option of specifying that the stack should not delete the element at all. Calling push(blah,1) means that "delete blah" will be called when removing the item or flushing the stack. Calling push(blah,2) means that "delete[] blah" will be called. When push(blah,-1) is called, the value of arrays is used for its local tag. push(blah, any other number) will result in the element not being delete'd at all.
Laxkit::PtrStack< T >::PtrStack | ( | char | nar = 1 | ) |
nar==1 (the default) means elements get delete'd, 2 means delete[]'d, other means don't delete.
|
virtual |
Return the e and islocal arrays, and internally set them to NULL, max=n=0.
If local==NULL, then just delete local, rather than return it.
|
virtual |
Find the index (in the range [0,n-1]) corresponding to the pointer t.
If the element is not in the stack, then -2 is returned. The -2 is used rather than -1 so that one can call pop(findindex(t)) and not pop anything if the element is not there. Otherwise, pop(-1) makes the top of the stack popped.
Referenced by Laxkit::TreeSelector::addselect(), LaxInterfaces::PathInterface::ChangeCurpathop(), LaxInterfaces::ViewportWithStack::ChangeObject(), LaxInterfaces::ViewportWithStack::DeleteObject(), LaxInterfaces::PathInterface::DeletePoint(), Laxkit::TreeSelector::Deselect(), Laxkit::TreeSelector::drawItemContents(), Laxkit::SplitWindow::FindBoxIndex(), LaxInterfaces::ViewportWithStack::FindObject(), Laxkit::SplitWindow::Join(), Laxkit::SplitWindow::joinwindow(), LaxInterfaces::PathInterface::LBDown(), LaxInterfaces::ViewportWindow::Pop(), Laxkit::SplitWindow::Refresh(), LaxInterfaces::PathInterface::Refresh(), Laxkit::anXApp::refresh(), Laxkit::SplitWindow::RemoveCurbox(), Laxkit::TagCloud::RemoveObject(), Laxkit::anXApp::reparent(), LaxInterfaces::ViewerWindow::SelectTool(), LaxInterfaces::PathInterface::SetPointType(), and Laxkit::SplitWindow::Split().
|
virtual |
Flush the stack. Makes e==NULL.
If the element's local==2 then the elements are delete with delete[]
. If the local==1 it is just deleted with delete
. If the islocal flag for the element is !=1 or 2, then the element is not delete'd at all.
Reimplemented in Laxkit::RefPtrStack< T >, Laxkit::RefPtrStack< anInterface >, Laxkit::RefPtrStack< Color >, Laxkit::RefPtrStack< ShortcutHandler >, Laxkit::RefPtrStack< anXWindow >, Laxkit::RefPtrStack< SomeData >, Laxkit::RefPtrStack< TouchObject >, Laxkit::RefPtrStack< MenuItem >, and Laxkit::RefPtrStack< LaxFont >.
Referenced by LaxInterfaces::PathInterface::AddPoint(), Laxkit::RowColBox::arrangeBoxes(), LaxInterfaces::PathInterface::ChangeCurpathop(), Laxkit::TreeSelector::CharInput(), LaxInterfaces::PathsData::clear(), LaxInterfaces::PathInterface::Clear(), Laxkit::ShortcutManager::ClearKeys(), LaxInterfaces::PathInterface::clearSelection(), LaxInterfaces::PathInterface::deletedata(), LaxInterfaces::EngraverFillData::FillRegularLinesHorizontal(), Laxkit::ListBox::Flush(), Laxkit::RowColBox::Flush(), LaxInterfaces::PathInterface::LBDown(), LaxInterfaces::PathInterface::MergeEndpoints(), LaxInterfaces::PathInterface::selectPoint(), and LaxFiles::XMLChunkToAttribute().
|
inlinevirtual |
Returns how many things are on the stack.
This function is not called from within PtrStack, so derived classes can make "how many things on the stack" mean something other than how many elements are in e.
References Laxkit::PtrStack< T >::n.
|
virtual |
Flush, then use a as the new array.
Note that it is assumed that flush sets e and islocal=NULL. e is then set to a. No element copying is done, the actual arrays a and nl are used. Does not alter delta, sets max=nn.
If nl==NULL, the islocal array is filled with the value of the arrays variable.
Returns 0 for success, nonzero for error.
Please note that if you are simply reaaranging the elements currently on the stack, this function will not work, since the current stack is flush()'d first, potentiall deleting the elements.
|
virtual |
Pop element with index which (defaults to top), and make popped point to it.
If there is no element to return, popped is set to NULL. If which is out of bounds, then the top most element is popped.
If local!=NULL, then put whether the item was local there.
Returns the number of elements still in the stack.
Referenced by Laxkit::PrintDialog::addOptions(), Laxkit::SliderPopup::DeleteItem(), LaxInterfaces::PathInterface::DeletePoint(), LaxInterfaces::PathInterface::MakeCircle(), Laxkit::DoublePanner::PopAxes(), Laxkit::DisplayerCairo::PopAxes(), Laxkit::DisplayerXlib::PopAxes(), and Laxkit::RefPtrStack< T >::remove().
|
virtual |
Pop element with index which, or the top if which not specified.
If which==-1 (the default) then pop off the top (highest index) of the stack. If which==-2, do nothing (see findindex()) and return NULL.
If local!=NULL, then put whether the item was local there.
|
virtual |
Pop the first item that points where topop points.
Return 1 if item popped, else 0.
If local!=NULL, then put whether the item was local there.
Referenced by LaxInterfaces::ViewportWindow::Pop().
|
virtual |
Push a pointer onto the stack before index where. Transfers pointer, does not duplicate.
If called without where, pointer is pushed onto the top (highest n) position.
If local==-1, then use arrays for local. If local==1, then when the stack flushes or the the element is removed, then it is delete'd. If local==2, then the element will be delete[]'d. If local is any other value, then delete is not called on the element.
Please note that pushing NULL objects is ok.
Returns the index of the new element on the stack, or -1 if the push failed.
Reimplemented in Laxkit::RefPtrStack< T >, Laxkit::RefPtrStack< anInterface >, Laxkit::RefPtrStack< Color >, Laxkit::RefPtrStack< ShortcutHandler >, Laxkit::RefPtrStack< anXWindow >, Laxkit::RefPtrStack< SomeData >, Laxkit::RefPtrStack< TouchObject >, Laxkit::RefPtrStack< MenuItem >, and Laxkit::RefPtrStack< LaxFont >.
Referenced by Laxkit::SplitWindow::Add(), Laxkit::ShortcutHandler::AddAction(), Laxkit::IconSelector::AddBox(), Laxkit::TreeSelector::AddColumn(), Laxkit::TagCloud::AddObject(), Laxkit::IconManager::addpath(), LaxInterfaces::PathInterface::AddPoint(), Laxkit::ShortcutHandler::AddShortcut(), Laxkit::SimpleUnit::AddUnits(), Laxkit::TabFrame::AddWin(), Laxkit::SplitWindow::AddWindowType(), LaxInterfaces::PathsData::append(), Laxkit::RowColBox::arrangeBoxes(), Laxkit::TreeSelector::CharInput(), LaxInterfaces::SomeDataFactory::DefineNewObject(), LaxInterfaces::EngraverFillData::dump_in_atts(), LaxInterfaces::PathsData::dump_in_atts(), LaxInterfaces::EngraverFillData::FillRegularLinesHorizontal(), Laxkit::SplitWindow::init(), Laxkit::Tagged::InsertTag(), Laxkit::lark_id_from_str(), LaxInterfaces::FreehandInterface::LBDown(), LaxInterfaces::FreehandInterface::MouseMove(), Laxkit::newCoreXlibDeviceManager(), Laxkit::RefPtrStack< T >::push(), Laxkit::ListBox::Push(), Laxkit::RowColBox::Push(), Laxkit::DoublePanner::PushAxes(), Laxkit::DisplayerCairo::PushAxes(), Laxkit::DisplayerXlib::PushAxes(), LaxInterfaces::PathsData::pushEmpty(), and Laxkit::SplitWindow::splitthewindow().
|
virtual |
Pushes an element only if it is not already on the stack.
Please note that this checks for whether anything on the stack points to the same address that the supplied pointer points to, (address equality) NOT whether the contents of whatever the pointer points to match the contents of any element on the stack (content equality).
If item already exists, where is ignored... should it cause a swap instead?
local is interpreted same way as in normal push(): -1 use default, 1 delete item, 2 delete[] item. Other value, don't delete item.
Returns -1 if the item was pushed, otherwise the index of the item in the stack.
Referenced by Laxkit::TreeSelector::addselect(), LaxInterfaces::PathInterface::LBDown(), LaxInterfaces::PathInterface::MakeCircle(), LaxInterfaces::PathInterface::MergeEndpoints(), and LaxInterfaces::PathInterface::selectPoint().
|
virtual |
Pop and delete (if islocal) the element at index which.
This purges the element by popping and then (if islocal==1 or 2) deleting it. Default if no index is specified is to remove the top element (which==-1). If which==-2 then do nothing (see findindex()).
Return 1 if an item is removed, else 0.
Reimplemented in Laxkit::RefPtrStack< T >, Laxkit::RefPtrStack< anInterface >, Laxkit::RefPtrStack< Color >, Laxkit::RefPtrStack< ShortcutHandler >, Laxkit::RefPtrStack< anXWindow >, Laxkit::RefPtrStack< SomeData >, Laxkit::RefPtrStack< TouchObject >, Laxkit::RefPtrStack< MenuItem >, and Laxkit::RefPtrStack< LaxFont >.
Referenced by Laxkit::TreeSelector::addselect(), LaxInterfaces::PathsData::clear(), Laxkit::ShortcutHandler::ClearShortcut(), Laxkit::TreeSelector::Collapse(), LaxInterfaces::PathInterface::DeletePoint(), Laxkit::TreeSelector::Deselect(), Laxkit::SplitWindow::joinwindow(), LaxInterfaces::PathInterface::MergeEndpoints(), Laxkit::ListBox::Pop(), Laxkit::RowColBox::Pop(), Laxkit::ShortcutHandler::ReassignKey(), Laxkit::ShortcutHandler::RemoveAction(), Laxkit::TagCloud::RemoveObject(), Laxkit::Tagged::RemoveTag(), Laxkit::TagCloud::RemoveTag(), Laxkit::StackFrame::ReplaceWin(), Laxkit::anXApp::Resource(), and LaxFiles::touch_recently_used().
|
virtual |
Swap the elements with indices i1 and i2.
If i1 or i2 is out of bounds, then substitute the top of the stack for it.
|
protected |
The default local value for elements of the stack.
This should be 2 to delete[] elements, rather than just delete (1) or 0 to not delete at all.