1 /*
2 * This file is part of GtkEveMon.
3 *
4 * GtkEveMon is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * You should have received a copy of the GNU General Public License
10 * along with GtkEveMon. If not, see <http://www.gnu.org/licenses/>.
11 */
12
13 #ifndef API_CERT_TREE_HEADER
14 #define API_CERT_TREE_HEADER
15
16 #include <vector>
17 #include <string>
18 #include <map>
19 #include <libxml/parser.h>
20
21 #include "util/ref_ptr.h"
22 #include "apibase.h"
23
24 struct ApiCertCategory
25 {
26 int id;
27 std::string name;
28 };
29
30 /* ---------------------------------------------------------------- */
31
32 struct ApiCertClass
33 {
34 int id;
35 std::string name;
36 ApiCertCategory const* cat_details;
37 };
38
39 /* ---------------------------------------------------------------- */
40
41 class ApiCert : public ApiElement
42 {
43 public:
44 int id;
45 int grade;
46 std::string desc;
47 ApiCertClass const* class_details;
48
49 /* Skill deps are in format (skill id, skill level). */
50 std::vector<std::pair<int, int> > skilldeps;
51 /* Cert deps are in format (cert id, cert grade). */
52 std::vector<std::pair<int, int> > certdeps;
53
54 public:
~ApiCert(void)55 ~ApiCert (void) {}
56 ApiElementType get_type (void) const;
57 void debug (void) const;
58 };
59
60 /* ---------------------------------------------------------------- */
61
62 class ApiCertTree;
63 typedef ref_ptr<ApiCertTree> ApiCertTreePtr;
64 typedef std::map<int, ApiCert> ApiCertMap;
65 typedef std::map<int, ApiCertCategory> ApiCertCategoryMap;
66 typedef std::map<int, ApiCertClass> ApiCertClassMap;
67
68 class ApiCertTree : public ApiBase
69 {
70 private:
71 static ApiCertTreePtr instance;
72
73 protected:
74 ApiCertTree (void);
75 void parse_xml (std::string const& filename);
76 void parse_eveapi_tag (xmlNodePtr node);
77 void parse_result_tag (xmlNodePtr node);
78 void parse_categories_rowset (xmlNodePtr node);
79 void parse_categories_row (ApiCertCategory* category, xmlNodePtr node);
80 void parse_classes_rowset (ApiCertCategory* category, xmlNodePtr node);
81 void parse_classes_row (ApiCertClass* cclass, xmlNodePtr node);
82 void parse_certificates_rowset (ApiCertClass* cclass, xmlNodePtr node);
83 void parse_certificate_row (ApiCert* cert, xmlNodePtr node);
84
85 public:
86 std::string filename;
87 ApiCertMap certificates;
88 ApiCertCategoryMap categories;
89 ApiCertClassMap classes;
90
91 public:
92 static ApiCertTreePtr request (void);
93 void refresh (void);
94 std::string get_filename (void) const;
95
96 ApiCertClass const* get_class_for_id (int id) const;
97 ApiCertCategory const* get_category_for_id (int id) const;
98 ApiCert const* get_certificate_for_id (int id) const;
99
100 static char const* get_name_for_grade (int grade);
101 static int get_grade_index (int grade);
102
103 void debug_dump (void);
104 };
105
106 /* ---------------------------------------------------------------- */
107
108 inline ApiElementType
get_type(void)109 ApiCert::get_type (void) const
110 {
111 return API_ELEM_CERT;
112 }
113
114 #endif /* API_CERT_TREE_HEADER */
115