]> git.tdb.fi Git - poefilter.git/blob - source/poefilter.cpp
Associate categories and appearances at filter level
[poefilter.git] / source / poefilter.cpp
1 #include <msp/core/getopt.h>
2 #include <msp/core/maputils.h>
3 #include <msp/io/file.h>
4 #include "category.h"
5 #include "filter.h"
6 #include "poefilter.h"
7
8 using namespace std;
9 using namespace Msp;
10
11 PoeFilter::PoeFilter(int argc, char **argv)
12 {
13         GetOpt getopt;
14         getopt.add_argument("filename", filename, GetOpt::REQUIRED_ARG);
15         getopt(argc, argv);
16 }
17
18 int PoeFilter::main()
19 {
20         DataFile::load(*this, filename);
21
22         for(map<string, Filter>::const_iterator i=filters.begin(); i!=filters.end(); ++i)
23                 if(!i->second.is_abstract())
24                 {
25                         IO::BufferedFile out(i->first+".filter", IO::M_WRITE);
26                         i->second.write(out);
27                 }
28
29         return 0;
30 }
31
32 const Category &PoeFilter::get_category(const string &name) const
33 {
34         return get_item(categories, name);
35 }
36
37 void PoeFilter::find_categories(const Regex &re, list<const Category *> &categs) const
38 {
39         for(map<string, Category>::const_iterator i=categories.begin(); i!=categories.end(); ++i)
40                 if(re.match(i->first))
41                         categs.push_back(&i->second);
42 }
43
44 const Filter &PoeFilter::get_filter(const string &name) const
45 {
46         return get_item(filters, name);
47 }
48
49
50 PoeFilter::Loader::Loader(PoeFilter &f):
51         DataFile::ObjectLoader<PoeFilter>(f)
52 {
53         add("category", &Loader::category);
54         add("filter", &Loader::filter);
55         add("theme", &Loader::theme);
56 }
57
58 void PoeFilter::Loader::category(const string &name)
59 {
60         Category cat(name);
61         load_sub(cat, obj);
62         obj.categories[name] = cat;
63 }
64
65 void PoeFilter::Loader::filter(const string &name)
66 {
67         Filter flt;
68         load_sub(flt, obj);
69         obj.filters[name] = flt;
70 }
71
72 void PoeFilter::Loader::theme()
73 {
74         load_sub(obj.theme);
75 }