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

DerivedTags.h

Go to the documentation of this file.
00001 #ifndef TAGCOLL_DERIVEDTAGS_H 00002 #define TAGCOLL_DERIVEDTAGS_H 00003 00004 /* 00005 * Model a collection of derived tags and a TagcollFilter to add them to a 00006 * collection 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/TagcollFilter.h> 00028 #include <tagcoll/ParserBase.h> 00029 #include <tagcoll/tagexpr/Tagexpr.h> 00030 00031 #include <map> 00032 #include <string> 00033 00034 #include <stdio.h> 00035 00036 namespace Tagcoll 00037 { 00038 00039 // List of changes to apply to tag names with a tagged collection is being 00040 // parsed 00041 class DerivedTagList 00042 { 00043 protected: 00044 typedef std::map<std::string, Tagexpr*> expressions_t; 00045 expressions_t expressions; 00046 00047 public: 00048 virtual ~DerivedTagList() throw (); 00049 00050 // Add a new derived tag to the list 00051 void add(const std::string& tag, const Tagexpr* expr) throw (); 00052 00053 // Read the derived tag expressions from the given file 00054 void parse(ParserInput& in) throw (ParserException); 00055 00056 // Return the tags in `tags', plus all the derived tags that matched `tags' 00057 OpSet<std::string> getDerived(const OpSet<std::string>& tags) const throw (); 00058 00059 // Return the tags in `tags', plus all the derived tags that matched `tags' 00060 OpSet<std::string> addDerived(const OpSet<std::string>& tags) const throw () { return tags + getDerived(tags); } 00061 }; 00062 00063 template <class ITEM> 00064 class ApplyDerivedTags : public TagcollFilter<ITEM, std::string> 00065 { 00066 protected: 00067 const DerivedTagList& dtags; 00068 00069 public: 00070 ApplyDerivedTags(const DerivedTagList& dtags) throw () 00071 : dtags(dtags) {} 00072 00073 virtual void consume(const ITEM& item) throw () 00074 { 00075 this->consumer->consume(item, dtags.addDerived(OpSet<std::string>())); 00076 } 00077 00078 virtual void consume(const ITEM& item, const OpSet<std::string>& tags) throw () 00079 { 00080 this->consumer->consume(item, dtags.addDerived(tags)); 00081 } 00082 }; 00083 00084 template <class ITEM> 00085 class CompressDerivedTags : public TagcollFilter<ITEM, std::string> 00086 { 00087 protected: 00088 DerivedTagList& dtags; 00089 00090 public: 00091 CompressDerivedTags(DerivedTagList& dtags) throw () 00092 : dtags(dtags) {} 00093 00094 virtual void consume(const ITEM& item) throw () 00095 { 00096 this->consumer->consume(item); 00097 } 00098 00099 virtual void consume(const ITEM& item, const OpSet<std::string>& tags) throw () 00100 { 00101 OpSet<std::string> derived = dtags.getDerived(tags); 00102 this->consumer->consume(item, tags - derived); 00103 } 00104 }; 00105 00106 }; 00107 00108 // vim:set ts=4 sw=4: 00109 #endif

Generated on Mon Aug 16 19:28:47 2004 for libtagcoll by doxygen 1.3.8