1 #include <msp/core/algorithm.h>
2 #include <msp/core/maputils.h>
3 #include <msp/io/print.h>
11 FilterStatement::FilterStatement():
15 void FilterStatement::set_show(bool s)
20 void FilterStatement::add_line(const string &l)
25 void FilterStatement::add_line(list<FilterStatement> &st, const string &line)
27 for(list<FilterStatement>::iterator i=st.begin(); i!=st.end(); ++i)
31 void FilterStatement::write(IO::Base &out) const
38 for(list<string>::const_iterator i=lines.begin(); i!=lines.end(); ++i)
39 IO::print(out, "\t%s\n", *i);
47 void Filter::write(IO::Base &out) const
49 for(list<Block>::const_iterator i=blocks.begin(); i!=blocks.end(); ++i)
51 list<FilterStatement> st;
52 st.push_back(FilterStatement());
53 st.back().set_show(i->show);
54 i->appearance.add_lines(st.back());
55 i->category->create_statements(st);
57 IO::print(out, "# %s\n", i->category->get_name());
58 for(list<FilterStatement>::const_iterator j=st.begin(); j!=st.end(); ++j)
64 Filter::Loader::Loader(Filter &f, const PoeFilter &p):
65 DataFile::ObjectLoader<Filter>(f),
68 add("abstract", &Filter::abstract);
69 add("cancel", &Loader::cancel);
70 add("hide", &Loader::hide);
71 add("include", &Loader::include);
72 add("show", &Loader::show);
75 string Filter::Loader::glob_to_re(const string &glob)
78 for(string::const_iterator i=glob.begin(); i!=glob.end(); ++i)
91 bool Filter::Loader::category_order(const Category *c1, const Category *c2)
93 return c1->get_order()<c2->get_order();
96 void Filter::Loader::add_categories(const string &name, bool show)
98 vector<const Category *> categs;
99 if(name.find('*')!=string::npos)
101 poe.find_categories(glob_to_re(name), categs);
104 throw key_error(name);
106 sort(categs, &category_order);
109 categs.push_back(&poe.get_category(name));
111 for(vector<const Category *>::const_iterator i=categs.begin(); i!=categs.end(); ++i)
114 for(list<Block>::const_iterator j=obj.blocks.begin(); (!found && j!=obj.blocks.end()); ++j)
115 found = (j->category==*i);
122 blk.appearance = (*i)->get_appearance();
123 if(const Appearance *app = poe.get_theme().find_appearance((*i)->get_name()))
124 blk.appearance.merge_from(*app);
125 obj.blocks.push_back(blk);
130 void Filter::Loader::cancel(const string &name)
132 vector<const Category *> categs;
133 if(name.find('*')!=string::npos)
135 poe.find_categories(glob_to_re(name), categs);
138 throw key_error(name);
141 categs.push_back(&poe.get_category(name));
143 for(vector<const Category *>::const_iterator i=categs.begin(); i!=categs.end(); ++i)
144 for(list<Block>::iterator j=obj.blocks.begin(); j!=obj.blocks.end(); ++j)
152 void Filter::Loader::hide(const string &name)
154 add_categories(name, false);
157 void Filter::Loader::include(const string &name)
159 const Filter &base = poe.get_filter(name);
160 obj.blocks.insert(obj.blocks.end(), base.blocks.begin(), base.blocks.end());
163 void Filter::Loader::show(const string &name)
165 add_categories(name, true);