FLTK 1.4.5: Fl_Tree_Item_Array Class Reference

FLTK 1.4.5

Loading...
Searching...
No Matches
Fl_Tree_Item_Array Class Reference

Manages an array of Fl_Tree_Item pointers. More...

`#include <Fl_Tree_Item_Array.H>`

## Public Member Functions
void | add (Fl_Tree_Item *val)
| Add an item* to the end of the array.
void | clear ()
| Clear the entire array.
int | deparent (int pos)
| Deparent item at `'pos'` from our list of children.
| Fl_Tree_Item_Array (const Fl_Tree_Item_Array *o)
| Copy constructor. Makes new copy of array, with new instances of each item.
| Fl_Tree_Item_Array (int new_chunksize=10)
| Constructor; creates an empty array.
void | insert (int pos, Fl_Tree_Item *new_item)
| Insert an item at index position `pos`.
int | manage_item_destroy () const
void | manage_item_destroy (int val)
| Option to control if Fl_Tree_Item_Array's destructor will also destroy the Fl_Tree_Item's.
int | move (int to, int from)
| Move item at 'from' to new position 'to' in the array.
Fl_Tree_Item * | operator[] (int i)
| Return the item and index `i`.
const Fl_Tree_Item * | operator[] (int i) const
| Const version of operator[](int i).
int | remove (Fl_Tree_Item *item)
| Remove the item from the array.
void | remove (int index)
| Remove the item at.
int | reparent (Fl_Tree_Item *item, Fl_Tree_Item *newparent, int pos)
| Reparent specified item as a child of ourself.
void | replace (int pos, Fl_Tree_Item *new_item)
| Replace the item at `index` with `newitem`.
void | swap (int ax, int bx)
| Swap the two items at index positions `ax` and `bx`.
int | total () const
| Return the total items in the array, or 0 if empty.
| ~Fl_Tree_Item_Array ()
| Destructor. Calls each item's destructor, destroys internal _items array.

## Detailed Description

Manages an array of Fl_Tree_Item pointers.

Because FLTK 1.x.x. has mandated that templates and STL not be used, we use this class to dynamically manage the arrays.

None of the methods do range checking on index values; the caller must be sure that index values are within the range 0<index<total() (unless otherwise noted).

## Constructor & Destructor Documentation

## ◆ Fl_Tree_Item_Array()

Fl_Tree_Item_Array::Fl_Tree_Item_Array | ( | int | new_chunksize = 10 | ) |

Constructor; creates an empty array.

    The optional 'chunksize' can be specified to optimize
    memory allocation for potentially large arrays. Default chunksize is 10.

## Member Function Documentation

## ◆ add()

void Fl_Tree_Item_Array::add | ( | Fl_Tree_Item * | val | ) |

Add an item* to the end of the array.

    Assumes the item was created with 'new', and will remain
    allocated.. Fl_Tree_Item_Array will handle calling the
    item's destructor when the array is cleared or the item remove()'ed.

## ◆ clear()

void Fl_Tree_Item_Array::clear | ( |  | ) |

Clear the entire array.

    Each item will be deleted (destructors will be called),
    and the array will be cleared. total() will return 0.

## ◆ deparent()

int Fl_Tree_Item_Array::deparent | ( | int | pos | ) |

Deparent item at `'pos'` from our list of children.

Similar to a remove() without the destruction of the item. This creates an orphaned item (still allocated, has no parent) which soon after is typically reparented elsewhere.

    \returns 0 on success, -1 on error (e.g. if \p 'pos' out of range)

## ◆ insert()

void Fl_Tree_Item_Array::insert | ( | int | pos,
|  | Fl_Tree_Item * | new_item )

Insert an item at index position `pos`.

    Handles enlarging array if needed, total increased by 1.
    If \p pos \>= total(), the item is appended to the array.
    If \p pos \< 0, the item is prepended (works like pos == 0).

## ◆ manage_item_destroy()

void Fl_Tree_Item_Array::manage_item_destroy | ( | int | val | ) |
| inline

Option to control if Fl_Tree_Item_Array's destructor will also destroy the Fl_Tree_Item's.

If set: items and item array is destroyed. If clear: only the item array is destroyed, not items themselves.

## ◆ move()

int Fl_Tree_Item_Array::move | ( | int | to,
|  | int | from )

Move item at 'from' to new position 'to' in the array.

Due to how the moving an item shuffles the array around, a positional 'move' implies things that may not be obvious:

- When 'from' moved lower in tree, appears BELOW item that was at 'to'.

- When 'from' moved higher in tree, appears ABOVE item that was at 'to'.

  Returns
    0 on success, -1 on range error (e.g. if `'to'` or `'from'` out of range)

## ◆ remove() [1/2]

int Fl_Tree_Item_Array::remove | ( | Fl_Tree_Item * | item | ) |

Remove the item from the array.

    \returns 0 if removed, or -1 if the item was not in the array.

## ◆ remove() [2/2]

void Fl_Tree_Item_Array::remove | ( | int | index | ) |

Remove the item at.

Parameters

  [in] | index | from the array.
      The item will be delete'd (if non-NULL), so its destructor will be called.

## ◆ reparent()

int Fl_Tree_Item_Array::reparent | ( | Fl_Tree_Item * | item,
|  | Fl_Tree_Item * | newparent,
|  | int | pos )

Reparent specified item as a child of ourself.

Typically 'newchild' was recently orphaned with deparent().

    \returns 0 on success, -1 on error (e.g. if \p 'pos' out of range)

## ◆ replace()

void Fl_Tree_Item_Array::replace | ( | int | index,
|  | Fl_Tree_Item * | newitem )

Replace the item at `index` with `newitem`.

Old item at index position will be destroyed, and the new item will take it's place, and stitched into the linked list.

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

- Fl_Tree_Item_Array.H
- Fl_Tree_Item_Array.cxx