Tagcoll::ItemGrouper< ITEM, TAG > Class Template Reference

Collection grouping items having the same tagset. More...

#include <ItemGrouper.h>

Inheritance diagram for Tagcoll::ItemGrouper< ITEM, TAG >:

Inheritance graph
[legend]
Collaboration diagram for Tagcoll::ItemGrouper< ITEM, TAG >:

Collaboration graph
[legend]
List of all members.

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

Detailed Description

template<class ITEM, class TAG>
class Tagcoll::ItemGrouper< ITEM, TAG >

Collection grouping items having the same tagset.

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);
 }


Member Typedef Documentation

template<class ITEM, class TAG>
typedef std::map<OpSet<TAG>, OpSet<ITEM> > Tagcoll::ItemGrouper< ITEM, TAG >::groups_t [protected]


Constructor & Destructor Documentation

template<class ITEM, class TAG>
virtual Tagcoll::ItemGrouper< ITEM, TAG >::~ItemGrouper (  )  throw () [inline, virtual]


Member Function Documentation

template<class ITEM, class TAG>
virtual void Tagcoll::ItemGrouper< ITEM, TAG >::consumeItem ( const ITEM &  item,
const OpSet< TAG > &  tags 
) [inline, protected, virtual]

Process a tagged item, with its tags.

Implements Tagcoll::Consumer< ITEM, TAG >.

template<class ITEM, class TAG>
virtual void Tagcoll::ItemGrouper< ITEM, TAG >::consumeItems ( const OpSet< ITEM > &  items,
const OpSet< TAG > &  tags 
) [inline, protected, virtual]

Process a set of items identically tagged, with their tags.

Reimplemented from Tagcoll::Consumer< ITEM, TAG >.

template<class ITEM, class TAG>
virtual OpSet<ITEM> Tagcoll::ItemGrouper< ITEM, TAG >::getItemsHavingTag ( const TAG &  tag  )  const [inline, protected, virtual]

Get the items which are tagged with at least the tag `tag'.

Returns:
The items found, or an empty set if no items have that tag

Implements Tagcoll::ReadonlyCollection< ITEM, TAG >.

template<class ITEM, class TAG>
virtual OpSet<ITEM> Tagcoll::ItemGrouper< ITEM, TAG >::getItemsHavingTags ( const OpSet< TAG > &  tags  )  const [inline, protected, virtual]

Get the items which are tagged with at least the tags `tags'.

Returns:
The items found, or an empty set if no items have that tag

Reimplemented from Tagcoll::ReadonlyCollection< ITEM, TAG >.

template<class ITEM, class TAG>
virtual OpSet<TAG> Tagcoll::ItemGrouper< ITEM, TAG >::getTagsOfItem ( const ITEM &  item  )  const [inline, protected, virtual]

Get the tags attached to an item.

Parameters:
item The item to query
Returns:
The set of tags, or an empty set if the item has no tags or it does not exist.

Implements Tagcoll::ReadonlyCollection< ITEM, TAG >.

template<class ITEM, class TAG>
virtual OpSet<TAG> Tagcoll::ItemGrouper< ITEM, TAG >::getTagsOfItems ( const OpSet< ITEM > &  items  )  const [inline, protected, virtual]

Get all the tags attached to the items in a set.

Parameters:
items The items to query
Returns:
The set of tags, or an empty set if the items have no tags or do not exist.

Reimplemented from Tagcoll::ReadonlyCollection< ITEM, TAG >.

template<class ITEM, class TAG>
virtual bool Tagcoll::ItemGrouper< ITEM, TAG >::hasItem ( const ITEM &  item  )  const [inline, virtual]

template<class ITEM, class TAG>
virtual bool Tagcoll::ItemGrouper< ITEM, TAG >::hasTag ( const TAG &  tag  )  const [inline, virtual]

Check if the collection contains a tag.

Parameters:
tag The tag to look for
Returns:
true if the collection contains tag, false otherwise

Reimplemented from Tagcoll::ReadonlyCollection< ITEM, TAG >.

template<class ITEM, class TAG>
virtual void Tagcoll::ItemGrouper< ITEM, TAG >::applyChange ( const PatchList< ITEM, TAG > &  change  )  [inline, virtual]

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 >.

template<class ITEM, class TAG>
virtual OpSet<ITEM> Tagcoll::ItemGrouper< ITEM, TAG >::getTaggedItems (  )  const [inline, virtual]

Get the set of all the items that have tags according to this collection.

Implements Tagcoll::ReadonlyCollection< ITEM, TAG >.

template<class ITEM, class TAG>
virtual OpSet<TAG> Tagcoll::ItemGrouper< ITEM, TAG >::getAllTags (  )  const [inline, virtual]

Get the set of all the tags in this collection.

Implements Tagcoll::ReadonlyCollection< ITEM, TAG >.

template<class ITEM, class TAG>
virtual OpSet<TAG> Tagcoll::ItemGrouper< ITEM, TAG >::getCompanionTags ( const OpSet< TAG > &  tags  )  const [inline, virtual]

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 >.

template<class ITEM, class TAG>
virtual OpSet<ITEM> Tagcoll::ItemGrouper< ITEM, TAG >::getRelatedItems ( const OpSet< TAG > &  tags,
int  maxdistance = 1 
) const [inline, virtual]

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 >.

template<class ITEM, class TAG>
virtual void Tagcoll::ItemGrouper< ITEM, TAG >::output ( Consumer< ITEM, TAG > &  consumer  )  const [inline, virtual]

Output all the contents of the collection to a Consumer.

Implements Tagcoll::ReadonlyCollection< ITEM, TAG >.

template<class ITEM, class TAG>
void Tagcoll::ItemGrouper< ITEM, TAG >::outputReversed ( Consumer< TAG, ITEM > &  consumer  )  const [inline]

Send the merged data to a consumer, but reversed: the tag become items, and they are tagged with the items that had them.

template<class ITEM, class TAG>
virtual void Tagcoll::ItemGrouper< ITEM, TAG >::outputHavingTags ( const OpSet< TAG > &  tags,
Consumer< ITEM, TAG > &  consumer 
) const [inline, virtual]

Send to a consumer all the items which are tagged with at least the given tags.

Reimplemented from Tagcoll::ReadonlyCollection< ITEM, TAG >.

template<class ITEM, class TAG>
void Tagcoll::ItemGrouper< ITEM, TAG >::clear (  )  [inline]

Remove all the items from this ItemGrouper.


Member Data Documentation

template<class ITEM, class TAG>
groups_t Tagcoll::ItemGrouper< ITEM, TAG >::groups [protected]


The documentation for this class was generated from the following file:
Generated on Sat Jan 17 03:11:07 2009 for libtagcoll by  doxygen 1.5.1