#include <itemset.h>
Public Member Functions | |
virtual void | append (const Item &itm) |
Append an item at the end of the sequence. | |
virtual const Item & | back () const |
Gets the last item in the list. | |
virtual void | clear () |
Removes all the elements in the list. | |
virtual FalconData * | clone () const |
Deletes the list. | |
virtual bool | empty () const |
Tells if the list is empty. | |
void | erase (ItemSetElement *elem) |
Remove given element. | |
ItemSetElement * | find (const Item &item) |
Finds an item and eventually returns the relative element. | |
ItemSetElement * | first () const |
Gets the pointer to the first element for list traversal. | |
virtual const Item & | front () const |
Gets the first item in the list. | |
virtual void | gcMark (uint32 mark) |
Perform marking of items stored in the list. | |
void | getIteratorAt (Iterator &tgt, ItemSetElement *elem) |
Creates an iterator. | |
void | insert (const Item &item) |
Insert an item after given before given element. | |
ItemSet (const ItemSet &l) | |
Clones a list. | |
ItemSet () | |
Builds an empty list. | |
ItemSetElement * | last () const |
Gets the pointer to the last element for list traversal. | |
virtual bool | onCriterion (Iterator *elem) const |
Criterion called back by disposeIteratorOnCriterion(). | |
virtual void | prepend (const Item &itm) |
Prepend an item at the beginning of the sequence. | |
uint32 | size () const |
Return the number of the items in the list. | |
virtual | ~ItemSet () |
Protected Member Functions | |
virtual void | copyIterator (Iterator &tgt, const Iterator &source) const |
Copy an iterator so that the two points to the same item. | |
virtual bool | equalIterator (const Iterator &first, const Iterator &second) const |
virtual void | erase (Iterator &iter) |
Deletes the element at position indicated by the iterator. | |
virtual Item & | getCurrent (const Iterator &iter) |
virtual Item & | getCurrentKey (const Iterator &iter) |
virtual void | getIterator (Iterator &tgt, bool tail=false) const |
Gets an Iterator valid for this sequence. | |
virtual bool | hasCurrent (const Iterator &iter) const |
virtual bool | hasNext (const Iterator &iter) const |
virtual bool | hasPrev (const Iterator &iter) const |
virtual void | insert (Iterator &iter, const Item &data) |
Inserts an element in a position indicated by the iterator. | |
virtual bool | next (Iterator &iter) const |
virtual bool | prev (Iterator &iter) const |
This class is designed to work together with Falcon object as a UserData, but it can be also used alone to store unique entities of items.
The set is internally represented as a binary tree (eventuall balanced).
Falcon::ItemSet::ItemSet | ( | ) | [inline] |
Builds an empty list.
Falcon::ItemSet::ItemSet | ( | const ItemSet & | l | ) |
Clones a list.
virtual Falcon::ItemSet::~ItemSet | ( | ) | [inline, virtual] |
virtual void Falcon::ItemSet::append | ( | const Item & | data | ) | [inline, virtual] |
virtual const Item& Falcon::ItemSet::back | ( | ) | const [virtual] |
Gets the last item in the list.
If the list is empty, you will crash, so use this only when the list is NOT empty.
Implements Falcon::Sequence.
virtual void Falcon::ItemSet::clear | ( | ) | [virtual] |
virtual FalconData* Falcon::ItemSet::clone | ( | ) | const [virtual] |
virtual void Falcon::ItemSet::copyIterator | ( | Iterator & | tgt, | |
const Iterator & | source | |||
) | const [protected, virtual] |
Copy an iterator so that the two points to the same item.
The source iterator may point to the past-end element, but must not be invalid.
Reimplemented from Falcon::Sequence.
virtual bool Falcon::ItemSet::empty | ( | ) | const [inline, virtual] |
virtual bool Falcon::ItemSet::equalIterator | ( | const Iterator & | first, | |
const Iterator & | second | |||
) | const [protected, virtual] |
Implements Falcon::Sequence.
virtual void Falcon::ItemSet::erase | ( | Iterator & | iter | ) | [protected, virtual] |
Deletes the element at position indicated by the iterator.
The implementation must check that the iterator is a valid iterator created by this object and pointing to a valid position.
Deletion happens at given position, shifting all the remaining elements backward; after a successful erase, the iterator must point to the element that was previously next in the series, or must be invalidated if the removed element was the last.
If the sequence is empty or the iterator is invalid, an AccessError must be thrown. If the iterator is referencing another sequence, a CodeError must be thrown.
iter | an iterator (possibly invalid or not generated by this class). |
Implements Falcon::Sequence.
void Falcon::ItemSet::erase | ( | ItemSetElement * | elem | ) |
Remove given element.
If this is the last element of the list, the method returns 0, else it return the element that was following the delete element in the list, and that now has its place.
elem | an element from this list (or you'll witness psychedelic crashes) |
ItemSetElement* Falcon::ItemSet::find | ( | const Item & | item | ) |
Finds an item and eventually returns the relative element.
This function is useful for direct deletion of an item, or creation of an iterator at a given position.
ItemSetElement* Falcon::ItemSet::first | ( | ) | const |
Gets the pointer to the first element for list traversal.
The list element is just an item with previous and next pointers. If the list is empty, this method will return 0.
virtual const Item& Falcon::ItemSet::front | ( | ) | const [virtual] |
Gets the first item in the list.
If the list is empty, you will crash, so use this only when the list is NOT empty.
Implements Falcon::Sequence.
virtual void Falcon::ItemSet::gcMark | ( | uint32 | mark | ) | [virtual] |
Implements Falcon::Sequence.
Implements Falcon::Sequence.
virtual void Falcon::ItemSet::getIterator | ( | Iterator & | tgt, | |
bool | tail = false | |||
) | const [protected, virtual] |
Gets an Iterator valid for this sequence.
If you need an iterator as a pointer or in the target stack, use Iterator( Sequence*, bool) instead.
The iterator constructor calls back this method to be configured.
It is possible to call this method thereafter to reset the iterator, even if it's gone invalid.
However, it is not legal to call this method with an iterator coming from another sequence; this will cause the program to throw a CodeError.
An | Iterator to be set. | |
tail | if false, get an iterator to the first element, else get an iterator to the last element. |
Reimplemented from Falcon::Sequence.
void Falcon::ItemSet::getIteratorAt | ( | Iterator & | tgt, | |
ItemSetElement * | elem | |||
) |
Creates an iterator.
virtual bool Falcon::ItemSet::hasCurrent | ( | const Iterator & | iter | ) | const [protected, virtual] |
Implements Falcon::Sequence.
virtual bool Falcon::ItemSet::hasNext | ( | const Iterator & | iter | ) | const [protected, virtual] |
Implements Falcon::Sequence.
virtual bool Falcon::ItemSet::hasPrev | ( | const Iterator & | iter | ) | const [protected, virtual] |
Implements Falcon::Sequence.
Inserts an element in a position indicated by the iterator.
The implementation must check that the iterator is a valid iterator created by this object and pointing to a valid position.
Insertion happens at given position, shifting all the remaining elements forward; after a successful insert, the iterator must point to the newly inserted element, and the previously current element is found safely in the next() position of the iterator.
Valid iterators (generated by this owner) pointing to invalid positions must be treated as pointing to last-past-one element; insertion causes append on tail, and at return they must be valid and point to the last valid element (the one just inserted).
If the iterator cannot be used, for example because their owner is not this item, this method will raise a CodeError.
iterator | an iterator. | |
data | the item to be inserted |
Implements Falcon::Sequence.
void Falcon::ItemSet::insert | ( | const Item & | item | ) |
Insert an item after given before given element.
To insert an item past the last element, use 0 as element pointer (last->next); this will work also to insert an item in an empty list.
item | the item to be inserted. |
ItemSetElement* Falcon::ItemSet::last | ( | ) | const |
Gets the pointer to the last element for list traversal.
The list element is just an item with previous and next pointers. If the list is empty, this method will return 0.
virtual bool Falcon::ItemSet::next | ( | Iterator & | iter | ) | const [protected, virtual] |
Implements Falcon::Sequence.
virtual bool Falcon::ItemSet::onCriterion | ( | Iterator * | elem | ) | const [virtual] |
Criterion called back by disposeIteratorOnCriterion().
Return true to remove this iterator, false to let it alive. Disposed iterators are removed from the iterator list of this sequence and invalidated.
Reimplemented from Falcon::Sequence.
virtual void Falcon::ItemSet::prepend | ( | const Item & | data | ) | [inline, virtual] |
virtual bool Falcon::ItemSet::prev | ( | Iterator & | iter | ) | const [protected, virtual] |
Implements Falcon::Sequence.
uint32 Falcon::ItemSet::size | ( | ) | const [inline] |
Return the number of the items in the list.