1 | // ==================================================================== // |
---|
2 | // // |
---|
3 | // File : ad_config.h // |
---|
4 | // Purpose : Read/write editor configurations // |
---|
5 | // // |
---|
6 | // // |
---|
7 | // Coded by Ralf Westram (coder@reallysoft.de) in May 2005 // |
---|
8 | // Copyright Department of Microbiology (Technical University Munich) // |
---|
9 | // // |
---|
10 | // Visit our web site at: http://www.arb-home.de/ // |
---|
11 | // // |
---|
12 | // ==================================================================== // |
---|
13 | |
---|
14 | #ifndef AD_CONFIG_H |
---|
15 | #define AD_CONFIG_H |
---|
16 | |
---|
17 | #ifndef ARBDB_BASE_H |
---|
18 | #include "arbdb_base.h" |
---|
19 | #endif |
---|
20 | #ifndef ARBTOOLS_H |
---|
21 | #include <arbtools.h> |
---|
22 | #endif |
---|
23 | |
---|
24 | #define CONFIG_DATA_PATH "configuration_data" |
---|
25 | #define CONFIG_ITEM "configuration" |
---|
26 | |
---|
27 | #define DEFAULT_CONFIGURATION "default_configuration" |
---|
28 | |
---|
29 | GBDATA *GBT_find_configuration(GBDATA *gb_main, const char *name); |
---|
30 | void GBT_get_configuration_names(struct ConstStrArray& configNames, GBDATA *gb_main); |
---|
31 | |
---|
32 | class GBT_config : virtual Noncopyable { |
---|
33 | char *top_area; |
---|
34 | char *middle_area; |
---|
35 | char *comment; // NULp if no comment exists |
---|
36 | public: |
---|
37 | GBT_config(GBDATA *gb_main, const char *name, GB_ERROR& error); |
---|
38 | GBT_config() : top_area(NULp), middle_area(NULp), comment(NULp) {} |
---|
39 | ~GBT_config() { |
---|
40 | free(top_area); |
---|
41 | free(middle_area); |
---|
42 | free(comment); |
---|
43 | } |
---|
44 | |
---|
45 | static const int TOP_AREA = 0; |
---|
46 | static const int MIDDLE_AREA = 1; |
---|
47 | |
---|
48 | bool exists() const { return top_area || middle_area; } |
---|
49 | |
---|
50 | const char *get_definition(int area) const { |
---|
51 | arb_assert(area == TOP_AREA || area == MIDDLE_AREA); |
---|
52 | return area == TOP_AREA ? top_area : middle_area; |
---|
53 | } |
---|
54 | void set_definition(int area, char *new_def) { |
---|
55 | arb_assert(area == TOP_AREA || area == MIDDLE_AREA); |
---|
56 | char*& Area = area == TOP_AREA ? top_area : middle_area; |
---|
57 | freeset(Area, new_def); |
---|
58 | } |
---|
59 | |
---|
60 | const char *get_comment() const { return comment; } |
---|
61 | void set_comment(const char *newComment) { freedup(comment, newComment); } |
---|
62 | |
---|
63 | GB_ERROR saveAsOver(GBDATA *gb_main, const char *name, const char *oldName, bool warnIfSavingDefault) const; |
---|
64 | GB_ERROR save(GBDATA *gb_main, const char *name, bool warnIfSavingDefault) const { |
---|
65 | return saveAsOver(gb_main, name, name, warnIfSavingDefault); |
---|
66 | } |
---|
67 | }; |
---|
68 | |
---|
69 | enum GBT_CONFIG_ITEM_TYPE { |
---|
70 | CI_UNKNOWN = 1, |
---|
71 | CI_GROUP = 2, |
---|
72 | CI_FOLDED_GROUP = 4, |
---|
73 | CI_SPECIES = 8, |
---|
74 | CI_SAI = 16, |
---|
75 | CI_CLOSE_GROUP = 32, |
---|
76 | CI_END_OF_CONFIG = 64, |
---|
77 | }; |
---|
78 | |
---|
79 | struct GBT_config_item : virtual Noncopyable { |
---|
80 | GBT_CONFIG_ITEM_TYPE type; |
---|
81 | char *name; |
---|
82 | |
---|
83 | GBT_config_item() : type(CI_UNKNOWN), name(NULp) {} |
---|
84 | GBT_config_item(GBT_CONFIG_ITEM_TYPE type_, const char *name_) : type(type_), name(nulldup(name_)) {} |
---|
85 | ~GBT_config_item() { free(name); } |
---|
86 | }; |
---|
87 | |
---|
88 | class GBT_config_parser : virtual Noncopyable { |
---|
89 | char *config_string; |
---|
90 | int parse_pos; |
---|
91 | |
---|
92 | GBT_config_item item; |
---|
93 | public: |
---|
94 | GBT_config_parser(const GBT_config& cfg, int area) |
---|
95 | : config_string(nulldup(cfg.get_definition(area))), |
---|
96 | parse_pos(0) |
---|
97 | {} |
---|
98 | ~GBT_config_parser() { free(config_string); } |
---|
99 | |
---|
100 | const GBT_config_item& nextItem(GB_ERROR& error); |
---|
101 | }; |
---|
102 | |
---|
103 | void GBT_append_to_config_string(const GBT_config_item& item, struct GBS_strstruct *strstruct); |
---|
104 | |
---|
105 | #if defined(DEBUG) |
---|
106 | void GBT_test_config_parser(GBDATA *gb_main); |
---|
107 | #endif // DEBUG |
---|
108 | |
---|
109 | #else |
---|
110 | #error ad_config.h included twice |
---|
111 | #endif // AD_CONFIG_H |
---|
112 | |
---|