00001 #ifndef TAGCOLL_DERIVEDTAGS_H
00002 #define TAGCOLL_DERIVEDTAGS_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00040
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
00051 void add(const std::string& tag, const Tagexpr* expr) throw ();
00052
00053
00054 void parse(ParserInput& in) throw (ParserException);
00055
00056
00057 OpSet<std::string> getDerived(const OpSet<std::string>& tags) const throw ();
00058
00059
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
00109 #endif