00001 #ifndef TAGCOLL_TAGCOLLECTION_H
00002 #define TAGCOLL_TAGCOLLECTION_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #pragma interface
00025
00026 #include <string>
00027 #include <set>
00028 #include <map>
00029 #include <list>
00030
00031 #include <tagcoll/OpSet.h>
00032 #include <tagcoll/TagcollConsumer.h>
00033 #include <tagcoll/TagcollChange.h>
00034
00035
00036
00037
00038
00039
00040
00041
00042 namespace Tagcoll
00043 {
00044
00045
00046 template<class ITEM, class TAG>
00047 class TagCollection : public TagcollConsumer<ITEM, TAG>
00048 {
00049 protected:
00050 class TagContainer : public std::map<TAG, int>
00051 {
00052 public:
00053 void add(const TAG& tag, int card = 1) throw ();
00054 void del(const TAG& tag, int card = 1) throw ();
00055 };
00056
00057
00058 TagContainer tags;
00059
00060
00061 typedef std::map<OpSet<TAG>, OpSet<ITEM> > tagsets_t;
00062 tagsets_t tagsets;
00063
00064
00065 OpSet<ITEM> untagged;
00066
00067
00068 OpSet<TAG> getImplyingOneOf(const OpSet<TAG>& tags) const throw ();
00069
00070 public:
00071
00072 class Change : public std::map< ITEM, OpSet<TAG> > {};
00073
00074 TagCollection() throw () {}
00075
00076 TagCollection(const TagCollection& tc) throw ()
00077 : tags(tc.tags), tagsets(tc.tagsets), untagged(tc.untagged) {}
00078
00079 virtual ~TagCollection() throw () {}
00080
00081 TagCollection& operator=(const TagCollection& tc) throw ()
00082 {
00083 tags = tc.tags;
00084 tagsets = tc.tagsets;
00085 untagged = tc.untagged;
00086 return *this;
00087 }
00088
00089
00090 typedef typename tagsets_t::const_iterator const_iterator;
00091 typedef typename tagsets_t::iterator iterator;
00092
00093 iterator begin() throw () { return tagsets.begin(); }
00094 iterator end() throw () { return tagsets.end(); }
00095 const_iterator begin() const throw () { return tagsets.begin(); }
00096 const_iterator end() const throw () { return tagsets.end(); }
00097
00098
00099 int tagCount() const throw () { return tags.size(); }
00100
00101
00102 int tagsetCount() const throw () { return tagsets.size(); }
00103
00104
00105 int untaggedCount() const throw () { return untagged.size(); }
00106
00107
00108 int totalCount() const throw ();
00109
00110
00111 OpSet<ITEM> getUntaggedItems() const throw () { return untagged; }
00112
00113
00114 OpSet<ITEM> getItemsForTagset(const OpSet<TAG>& ts) const throw ();
00115
00116
00117
00118
00119 OpSet<TAG> getTagsetForItem(const ITEM& item) const throw ();
00120
00121
00122 OpSet<TAG> getAllTags() const throw ();
00123
00124
00125
00126 OpSet<TAG> getCompanionTags(const OpSet<TAG>& ts) const throw ();
00127
00128
00129 OpSet<ITEM> getAllItems() const throw ();
00130
00131
00132 OpSet<ITEM> getCompanionItems(const OpSet<TAG>& ts) const throw ();
00133
00134
00135 std::map< ITEM, OpSet<TAG> > getCompanionItemsAndTagsets(const OpSet<TAG>& ts) const throw ();
00136
00137
00138 std::list< OpSet<TAG> > getRelatedTagsets(const OpSet<TAG>& ts, int maxdistance = 1) const throw ();
00139
00140
00141
00142 Change applyChange(const Change& change) throw ();
00143 TagcollChange<ITEM, TAG> applyChange(const TagcollChange<ITEM, TAG>& change) throw ();
00144
00145
00146 void add(const ITEM& item) throw ();
00147
00148
00149 void add(const OpSet<ITEM>& items) throw ();
00150
00151
00152 void add(const OpSet<TAG>& tagset, const ITEM& item) throw ();
00153
00154
00155 void add(const OpSet<TAG>& tagset, const OpSet<ITEM>& items) throw ();
00156
00157
00158 void consume(const ITEM& item) throw () { add(item); }
00159
00160
00161 void consume(const OpSet<ITEM>& items) throw () { add(items); }
00162
00163
00164 void consume(const ITEM& item, const OpSet<TAG>& tagset) throw () { add(tagset, item); }
00165
00166
00167 void consume(const OpSet<ITEM>& items, const OpSet<TAG>& tagset) throw () { add(tagset, items); }
00168
00169
00170
00171 TagCollection<ITEM, TAG> getChildCollection(const TAG& tag) const throw ();
00172
00173
00174
00175 TagCollection<ITEM, TAG> getCollectionWithoutTags(const OpSet<TAG>& tag) const throw ();
00176
00177
00178
00179 TagCollection<ITEM, TAG> getCollectionWithoutTagsetsHaving(const TAG& tag) const throw ();
00180
00181
00182
00183 TagCollection<ITEM, TAG> getCollectionWithoutTagsetsHavingAnyOf(const OpSet<TAG>& tag) const throw ();
00184
00185
00186 TAG findTagWithMaxCardinalityNotIn(const OpSet<TAG>& tags, int* card = 0) const throw ();
00187
00188
00189 OpSet<TAG> getImpliedBy(const TAG& tag) const throw ();
00190
00191
00192
00193
00194
00195 void mergeEquivalentTags() throw ();
00196
00197
00198 void removeTagsWithCardinalityLessThan(int card) throw ();
00199
00200
00201 void output(TagcollConsumer<ITEM, TAG>& cons) const throw ();
00202 };
00203
00204 };
00205
00206
00207 #endif