source: tags/ms_r16q3/ARBDB/ad_config.h

Last change on this file was 14256, checked in by westram, 9 years ago
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.8 KB
Line 
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
29GBDATA *GBT_find_configuration(GBDATA *gb_main, const char *name);
30GBDATA *GBT_findOrCreate_configuration(GBDATA *gb_main, const char *name);
31
32void GBT_get_configuration_names(struct ConstStrArray& configNames, GBDATA *gb_main);
33
34class GBT_config : virtual Noncopyable {
35    char *top_area;
36    char *middle_area;
37    char *comment; // NULL if no comment exists
38public:
39    GBT_config(GBDATA *gb_main, const char *name, GB_ERROR& error);
40    GBT_config() : top_area(NULL), middle_area(NULL), comment(NULL) {}
41    ~GBT_config() {
42        free(top_area);
43        free(middle_area);
44        free(comment);
45    }
46
47    static const int TOP_AREA    = 0;
48    static const int MIDDLE_AREA = 1;
49
50    bool exists() const { return top_area || middle_area; }
51
52    const char *get_definition(int area) const {
53        arb_assert(area == 0 || area == 1);
54        return area ? middle_area : top_area;
55    }
56    void set_definition(int area, char *new_def) {
57        arb_assert(area == 0 || area == 1);
58        char*& Area = area ? middle_area : top_area;
59        freeset(Area, new_def);
60    }
61
62    const char *get_comment() const { return comment; }
63    void set_comment(const char *newComment) { freedup(comment, newComment); }
64
65    GB_ERROR saveAsOver(GBDATA *gb_main, const char *name, const char *oldName, bool warnIfSavingDefault) const;
66    GB_ERROR save(GBDATA *gb_main, const char *name, bool warnIfSavingDefault) const {
67        return saveAsOver(gb_main, name, name, warnIfSavingDefault);
68    }
69};
70
71enum GBT_CONFIG_ITEM_TYPE {
72    CI_UNKNOWN       = 1,
73    CI_GROUP         = 2,
74    CI_FOLDED_GROUP  = 4,
75    CI_SPECIES       = 8,
76    CI_SAI           = 16,
77    CI_CLOSE_GROUP   = 32,
78    CI_END_OF_CONFIG = 64,
79};
80
81struct GBT_config_item : virtual Noncopyable {
82    GBT_CONFIG_ITEM_TYPE  type;
83    char                 *name;
84
85    GBT_config_item() : type(CI_UNKNOWN), name(NULL) {}
86    GBT_config_item(GBT_CONFIG_ITEM_TYPE type_, const char *name_) : type(type_), name(nulldup(name_)) {}
87    ~GBT_config_item() { free(name); }
88};
89
90class GBT_config_parser : virtual Noncopyable {
91    char *config_string;
92    int   parse_pos;
93
94    GBT_config_item item;
95public:
96    GBT_config_parser(const GBT_config& cfg, int area)
97        : config_string(nulldup(cfg.get_definition(area))),
98          parse_pos(0)
99    {}
100    ~GBT_config_parser() { free(config_string); }
101
102    const GBT_config_item& nextItem(GB_ERROR& error);
103};
104
105void GBT_append_to_config_string(const GBT_config_item& item, struct GBS_strstruct *strstruct);
106
107#if defined(DEBUG)
108void GBT_test_config_parser(GBDATA *gb_main);
109#endif // DEBUG
110
111#else
112#error ad_config.h included twice
113#endif // AD_CONFIG_H
114
Note: See TracBrowser for help on using the repository browser.