Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

TagcollBuilder.h

Go to the documentation of this file.
00001 #ifndef TAGCOLL_BUILDER_H
00002 #define TAGCOLL_BUILDER_H
00003 
00004 /*
00005  * TagcollConsumer that builds a tagged collection
00006  * 
00007  * Copyright (C) 2003  Enrico Zini <enrico@debian.org>
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2.1 of the License, or (at your option) any later version.
00013  *
00014  * This library is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017  * Lesser General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Lesser General Public
00020  * License along with this library; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00022  */
00023 
00024 #pragma interface
00025 
00026 #include <tagcoll/HandleMaker.h>
00027 #include <tagcoll/TagcollConsumer.h>
00028 #include <tagcoll/TagCollection.h>
00029 
00030 namespace Tagcoll
00031 {
00032 
00033 // TagcollConsumer that builds a tagged collection 
00034 class TagcollBuilder : public TagcollConsumer<std::string>
00035 {
00036 protected:
00037     HandleMaker<std::string>& handleMaker;
00038     TagCollection<int, std::string> coll;
00039 
00040     OpSet<int> itemsToHandles(const OpSet<std::string>& ts) throw ()
00041     {
00042         OpSet<int> res;
00043         for (OpSet<std::string>::const_iterator i = ts.begin();
00044                 i != ts.end(); i++)
00045             res += handleMaker.getHandle(*i);
00046         return res;
00047     }
00048     
00049 public:
00050     TagcollBuilder(HandleMaker<std::string>& handleMaker) throw ()
00051         : handleMaker(handleMaker) {}
00052     virtual ~TagcollBuilder() throw () {}
00053 
00054     virtual void consume(const std::string& item) throw ()
00055     {
00056         coll.add(handleMaker.getHandle(item));
00057     }
00058     
00059     virtual void consume(const std::string& item, const OpSet<std::string>& tags) throw ()
00060     {
00061         coll.add(tags, handleMaker.getHandle(item));
00062     }
00063 
00064     virtual void consume(const OpSet<std::string>& items) throw ()
00065     {
00066         coll.add(itemsToHandles(items));
00067     }
00068     
00069     virtual void consume(const OpSet<std::string>& items, const OpSet<std::string>& tags) throw ()
00070     {
00071         coll.add(tags, itemsToHandles(items));
00072     }
00073 
00074     // Retrieve the resulting collection
00075     TagCollection<int, std::string> collection() throw () { return coll; }
00076     const TagCollection<int, std::string> collection() const throw () { return coll; }
00077 };
00078 
00079 };
00080 
00081 // vim:set ts=4 sw=4:
00082 #endif

Generated on Tue Oct 26 19:31:33 2004 for libtagcoll by  doxygen 1.3.9.1