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

Implications.h

Go to the documentation of this file.
00001 #ifndef TAGCOLL_IMPLICATIONS_H
00002 #define TAGCOLL_IMPLICATIONS_H
00003 
00004 /*
00005  * Collection of tag implications and a a TagcollFilter to apply or compress
00006  * them
00007  * 
00008  * Copyright (C) 2003  Enrico Zini <enrico@debian.org>
00009  *
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or (at your option) any later version.
00014  *
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00023  */
00024 
00025 #pragma interface
00026 
00027 #include <tagcoll/TagcollConsumer.h>
00028 #include <tagcoll/TagcollFilter.h>
00029 
00030 #include <tagcoll/OpSet.h>
00031 
00032 #include <map>
00033 
00034 namespace Tagcoll
00035 {
00036 
00037 // List of explicit implications that can be used to expand a tagged collection
00038 // while it's being parsed
00039 template <class TAG>
00040 class ImplicationList : public TagcollConsumer<TAG>
00041 {
00042 protected:
00043     // DAG arcs: child -> {parents}
00044     typedef std::map< TAG, OpSet<TAG> > impl_t;
00045     impl_t implications;
00046 
00047     // Get the set of all tags seen when walking through all parent lists
00048     OpSet<TAG> getDestinations(const TAG& tag, const OpSet<TAG>& seen = OpSet<TAG>()) const throw ();
00049 
00050     // Return true if tag1 can reach tag2 walking through some path in its parent list
00051     bool reaches(const TAG& tag1, const TAG& tag2, const OpSet<TAG>& seen = OpSet<TAG>()) const throw ();
00052 
00053 public:
00054     virtual ~ImplicationList() throw () {}
00055 
00056     virtual void consume(const TAG& item) throw () {}
00057     virtual void consume(const TAG& item, const OpSet<TAG>& tags) throw ();
00058     
00059     // Expand a single tag
00060     OpSet<TAG> expand(const TAG& tag) throw ();
00061 
00062     // Expand a full tagset
00063     OpSet<TAG> expand(const OpSet<TAG>& tags) throw ();
00064 
00065     // Remove unnecessary arcs from the dag
00066     void pack() throw ();
00067     
00068     // Output the fully expanded implication dag to a TagcollConsumer
00069     void outputFull(TagcollConsumer<TAG>& consumer) throw ();
00070 
00071     // Output the implication dag to a TagcollConsumer
00072     void output(TagcollConsumer<TAG>& consumer) throw ();
00073 };
00074 
00075 template <class TAG>
00076 class ApplyImplications : public TagcollFilter<TAG>
00077 {
00078 protected:
00079     ImplicationList<TAG>& implications;
00080     
00081 public:
00082     ApplyImplications(ImplicationList<TAG>& implications) throw ()
00083         : implications(implications) {}
00084 
00085     virtual void consume(const TAG& item) throw ()
00086     {
00087         this->consumer->consume(item);
00088     }
00089 
00090     virtual void consume(const TAG& item, const OpSet<TAG>& tags) throw ()
00091     {
00092         this->consumer->consume(item, implications.expand(tags));
00093     }
00094 };
00095 
00096 // TagcollConsumer that just outputs the input to a given file handle, removing
00097 // the tags that would be re-added if expanding with the given explicit
00098 // implications
00099 template <class TAG>
00100 class CompressImplications : public TagcollFilter<TAG>
00101 {
00102 protected:
00103     ImplicationList<TAG>& implications;
00104 
00105 public:
00106     CompressImplications(ImplicationList<TAG>& implications) throw ()
00107         : implications(implications) {}
00108 
00109     virtual void consume(const TAG& item) throw ()
00110     {
00111         this->consumer->consume(item);
00112     }
00113     
00114     virtual void consume(const TAG& item, const OpSet<TAG>& tags) throw ();
00115 };
00116 
00117 };
00118 
00119 // vim:set ts=4 sw=4:
00120 #endif

Generated on Thu Jun 23 21:48:05 2005 for libtagcoll by  doxygen 1.4.3-20050530