]> git.tdb.fi Git - poefilter.git/blobdiff - source/filter.cpp
Favor vector over list for simple types
[poefilter.git] / source / filter.cpp
index 80ca1932facfa455cc6ee2d0bd631958cf9513d4..02f8c3f6ccf278b1ab974e894f7aa2f09ff1304f 100644 (file)
@@ -50,6 +50,7 @@ void Filter::write(IO::Base &out) const
        {
                list<FilterStatement> st;
                st.push_back(FilterStatement());
+               st.back().set_show(i->show);
                i->appearance.add_lines(st.back());
                i->category->create_statements(st);
 
@@ -57,8 +58,6 @@ void Filter::write(IO::Base &out) const
                for(list<FilterStatement>::const_iterator j=st.begin(); j!=st.end(); ++j)
                        j->write(out);
        }
-
-       out.write("# unmatched\nHide\n");
 }
 
 
@@ -93,50 +92,22 @@ bool Filter::Loader::category_order(const Category *c1, const Category *c2)
        return c1->get_order()<c2->get_order();
 }
 
-void Filter::Loader::hide(const string &name)
+void Filter::Loader::add_categories(const string &name, bool show)
 {
-       list<const Category *> categs;
+       vector<const Category *> categs;
        if(name.find('*')!=string::npos)
        {
                poe.find_categories(glob_to_re(name), categs);
 
                if(categs.empty())
                        throw key_error(name);
-       }
-       else
-               categs.push_back(&poe.get_category(name));
-
-       for(list<const Category *>::const_iterator i=categs.begin(); i!=categs.end(); ++i)
-               for(list<Block>::iterator j=obj.blocks.begin(); j!=obj.blocks.end(); ++j)
-                       if(j->category==*i)
-                       {
-                               obj.blocks.erase(j);
-                               break;
-                       }
-}
 
-void Filter::Loader::include(const string &name)
-{
-       const Filter &base = poe.get_filter(name);
-       obj.blocks.insert(obj.blocks.end(), base.blocks.begin(), base.blocks.end());
-}
-
-void Filter::Loader::show(const string &name)
-{
-       list<const Category *> categs;
-       if(name.find('*')!=string::npos)
-       {
-               poe.find_categories(glob_to_re(name), categs);
-
-               if(categs.empty())
-                       throw key_error(name);
-
-               categs.sort(&category_order);
+               sort(categs, &category_order);
        }
        else
                categs.push_back(&poe.get_category(name));
 
-       for(list<const Category *>::const_iterator i=categs.begin(); i!=categs.end(); ++i)
+       for(vector<const Category *>::const_iterator i=categs.begin(); i!=categs.end(); ++i)
        {
                bool found = false;
                for(list<Block>::const_iterator j=obj.blocks.begin(); (!found && j!=obj.blocks.end()); ++j)
@@ -145,6 +116,7 @@ void Filter::Loader::show(const string &name)
                if(!found)
                {
                        Block blk;
+                       blk.show = show;
                        blk.category = *i;
                        blk.appearance = (*i)->get_appearance();
                        if(const Appearance *app = poe.get_theme().find_appearance((*i)->get_name()))
@@ -153,3 +125,41 @@ void Filter::Loader::show(const string &name)
                }
        }
 }
+
+void Filter::Loader::cancel(const string &name)
+{
+       vector<const Category *> categs;
+       if(name.find('*')!=string::npos)
+       {
+               poe.find_categories(glob_to_re(name), categs);
+
+               if(categs.empty())
+                       throw key_error(name);
+       }
+       else
+               categs.push_back(&poe.get_category(name));
+
+       for(vector<const Category *>::const_iterator i=categs.begin(); i!=categs.end(); ++i)
+               for(list<Block>::iterator j=obj.blocks.begin(); j!=obj.blocks.end(); ++j)
+                       if(j->category==*i)
+                       {
+                               obj.blocks.erase(j);
+                               break;
+                       }
+}
+
+void Filter::Loader::hide(const string &name)
+{
+       add_categories(name, false);
+}
+
+void Filter::Loader::include(const string &name)
+{
+       const Filter &base = poe.get_filter(name);
+       obj.blocks.insert(obj.blocks.end(), base.blocks.begin(), base.blocks.end());
+}
+
+void Filter::Loader::show(const string &name)
+{
+       add_categories(name, true);
+}