Logo Search packages:      
Sourcecode: tagcoll version File versions  Download package

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


 void perform(const PatchList<ITEM, TAG>& change)

Implements Tagcoll::Collection< ITEM, TAG >.

Definition at line 146 of file ItemGrouper.h.

References Tagcoll::PatchList< ITEM, TAG >::patch().

            OpSet<ITEM> involvedItems;

            // Find out the items that are involved by the patch
            for (typename PatchList<ITEM, TAG>::const_iterator i = change.begin(); i != change.end(); i++)
                  involvedItems += i->first;

            // Take the involved items temporarily out of the collection, and save
            // them together with their patched tagset
            std::map< ITEM, OpSet<TAG> > involved;
            OpSet<ITEM> extraItems = involvedItems;
            std::list< typename groups_t::iterator > toremove;
            for (typename groups_t::iterator i = groups.begin();
                        i != groups.end(); i++)
                  OpSet<ITEM> found = i->second ^ involvedItems;
                  extraItems -= found;
                  if (!found.empty())
                        i->second -= found;
                        for (typename OpSet<ITEM>::const_iterator j = found.begin();
                                    j != found.end(); j++)
                              involved.insert(make_pair(*j, change.patch(*j, i->first)));
                        if (i->second.empty())
            for (typename std::list< typename groups_t::iterator >::const_iterator i = toremove.begin();
                        i != toremove.end(); i++)

            // Also add those tags that have been introduced with the patch
            for (typename OpSet<ITEM>::const_iterator i = extraItems.begin();
                        i != extraItems.end(); i++)
                  typename PatchList<ITEM, TAG>::const_iterator found = change.find(*i);
                  if (found != change.end())
                        involved.insert(make_pair(*i, found->second.getAdded()));
            // Reinsert the involved items and their patched tagset
            for (typename std::map< ITEM, OpSet<TAG> >::const_iterator i = involved.begin();
                        i != involved.end(); i++)
                  groups[i->second] += i->first;

Generated by  Doxygen 1.6.0   Back to index