#include <ItemGrouper.h>
Inheritance diagram for Tagcoll::ItemGrouper< ITEM, TAG >:
Public Member Functions | |
virtual | ~ItemGrouper () throw () |
virtual bool | hasItem (const ITEM &item) const |
virtual bool | hasTag (const TAG &tag) const |
Check if the collection contains a tag. | |
virtual void | applyChange (const PatchList< ITEM, TAG > &change) |
Apply a patch to the collection. | |
virtual OpSet< ITEM > | getTaggedItems () const |
Get the set of all the items that have tags according to this collection. | |
virtual OpSet< TAG > | getAllTags () const |
Get the set of all the tags in this collection. | |
virtual OpSet< TAG > | getCompanionTags (const OpSet< TAG > &tags) const |
Get the set of all tags in this collection that appear in tagsets containing `tags'. | |
virtual OpSet< ITEM > | getRelatedItems (const OpSet< TAG > &tags, int maxdistance=1) const |
Get the related items at the given maximum distance. | |
virtual void | output (Consumer< ITEM, TAG > &consumer) const |
Output all the contents of the collection to a Consumer. | |
void | outputReversed (Consumer< TAG, ITEM > &consumer) const |
Send the merged data to a consumer, but reversed: the tag become items, and they are tagged with the items that had them. | |
virtual void | outputHavingTags (const OpSet< TAG > &tags, Consumer< ITEM, TAG > &consumer) const |
Send to a consumer all the items which are tagged with at least the given tags. | |
void | clear () |
Remove all the items from this ItemGrouper. | |
Protected Types | |
typedef std::map< OpSet< TAG >, OpSet< ITEM > > | groups_t |
Protected Member Functions | |
virtual void | consumeItem (const ITEM &item, const OpSet< TAG > &tags) |
Process a tagged item, with its tags. | |
virtual void | consumeItems (const OpSet< ITEM > &items, const OpSet< TAG > &tags) |
Process a set of items identically tagged, with their tags. | |
virtual OpSet< ITEM > | getItemsHavingTag (const TAG &tag) const |
Get the items which are tagged with at least the tag `tag'. | |
virtual OpSet< ITEM > | getItemsHavingTags (const OpSet< TAG > &tags) const |
Get the items which are tagged with at least the tags `tags'. | |
virtual OpSet< TAG > | getTagsOfItem (const ITEM &item) const |
Get the tags attached to an item. | |
virtual OpSet< TAG > | getTagsOfItems (const OpSet< ITEM > &items) const |
Get all the tags attached to the items in a set. | |
Protected Attributes | |
groups_t | groups |
The intended usage is mainly for compressing a stream of tags putting items together, for example to have a more compact output when serialising.
For most other collection operations, it's even more unefficient than InputMerger.
Examples:
// Serialize the collection, giving the serializer a chance to group // together the items with the same tags void serializeCompact(const Collection<Item, Tag>& coll) { ItemGrouper<Item, Tag> grouper; coll.output(grouper); grouper.output(serializer); } // Serialize the reversed collection, associating to tags the items that // have them in the input. It also won't output the same item twice, and // it gives the serializer a chance to group together the items with the // same tags void serializeReversed(const Collection<Item, Tag>& coll) { ItemGrouper<Item, Tag> grouper; coll.output(grouper); grouper.outputReversed(serializer); }
|
|
|
|
|
Apply a patch to the collection. Example: void perform(const PatchList<ITEM, TAG>& change) { collection.applyChange(change); undo.push_back(change.getReverse()); } Implements Tagcoll::Collection< ITEM, TAG >. |
|
Remove all the items from this ItemGrouper.
|
|
Process a tagged item, with its tags.
Implements Tagcoll::Consumer< ITEM, TAG >. |
|
Process a set of items identically tagged, with their tags.
Reimplemented from Tagcoll::Consumer< ITEM, TAG >. |
|
Get the set of all the tags in this collection.
Implements Tagcoll::ReadonlyCollection< ITEM, TAG >. |
|
Get the set of all tags in this collection that appear in tagsets containing `tags'. Example: void refineSelection(const OpSet<Tag>& selection) { OpSet<Tag> extraTags = collection.getCompanionTags(selection); tagMenu.setAvailableOptions(extraTags); } Reimplemented from Tagcoll::ReadonlyCollection< ITEM, TAG >. |
|
Get the items which are tagged with at least the tag `tag'.
Implements Tagcoll::ReadonlyCollection< ITEM, TAG >. |
|
Get the items which are tagged with at least the tags `tags'.
Reimplemented from Tagcoll::ReadonlyCollection< ITEM, TAG >. |
|
Get the related items at the given maximum distance. Examples: // Get the items related to a given one, at the given distance OpSet<Item> getRelated(const Item& item, int distance) { OpSet<Item> res = collection.getRelatedItems(collection.getTags(item), distance); return res - item; } // Get the items related to the given ones, at the given distance OpSet<Item> getRelated(const OpSet<Item>& items, int distance) { OpSet<Item> res = collection.getRelatedItems(collection.getTags(items), distance); return res - items; } // Get the related items, increasing the distance until it finds at // least 'minimum' items OpSet<Item> getRelated(const Item& item, int minimum) { OpSet<Tag> tags = collection.getTags(item); OpSet<Item> res; for (int i = 0; i < tags.size() && res.size() < minimum; i++) res += collection.getRelatedItems(tags, i); return res - item; } Reimplemented from Tagcoll::ReadonlyCollection< ITEM, TAG >. |
|
Get the set of all the items that have tags according to this collection.
Implements Tagcoll::ReadonlyCollection< ITEM, TAG >. |
|
Get the tags attached to an item.
Implements Tagcoll::ReadonlyCollection< ITEM, TAG >. |
|
Get all the tags attached to the items in a set.
Reimplemented from Tagcoll::ReadonlyCollection< ITEM, TAG >. |
|
|
|
Check if the collection contains a tag.
Reimplemented from Tagcoll::ReadonlyCollection< ITEM, TAG >. |
|
Output all the contents of the collection to a Consumer.
Implements Tagcoll::ReadonlyCollection< ITEM, TAG >. |
|
Send to a consumer all the items which are tagged with at least the given tags.
Reimplemented from Tagcoll::ReadonlyCollection< ITEM, TAG >. |
|
Send the merged data to a consumer, but reversed: the tag become items, and they are tagged with the items that had them.
|
|
|