source: branches/properties/ARBDB/ad_config.h

Last change on this file was 19339, checked in by westram, 2 years ago
  • reintegrates 'refactor' into 'trunk'
    • eliminates old interface of GBS_strstruct
    • add a few new unittests (editor-config string + some PT-SERVER-functions)
  • adds: log:branches/refactor@19300:19338
  • 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#ifndef ARB_STRBUF_H
24#include <arb_strbuf.h>
25#endif
26
27#define CONFIG_DATA_PATH "configuration_data"
28#define CONFIG_ITEM      "configuration"
29
30#define DEFAULT_CONFIGURATION "default_configuration"
31
32GBDATA *GBT_find_configuration(GBDATA *gb_main, const char *name);
33void    GBT_get_configuration_names(struct ConstStrArray& configNames, GBDATA *gb_main);
34
35class GBT_config : virtual Noncopyable {
36    char *top_area;
37    char *middle_area;
38    char *comment; // NULp if no comment exists
39public:
40    GBT_config(GBDATA *gb_main, const char *name, GB_ERROR& error);
41    GBT_config() : top_area(NULp), middle_area(NULp), comment(NULp) {}
42    ~GBT_config() {
43        free(top_area);
44        free(middle_area);
45        free(comment);
46    }
47
48    static const int TOP_AREA    = 0;
49    static const int MIDDLE_AREA = 1;
50
51    bool exists() const { return top_area || middle_area; }
52
53    const char *get_definition(int area) const {
54        arb_assert(area == TOP_AREA || area == MIDDLE_AREA);
55        return area == TOP_AREA ? top_area : middle_area;
56    }
57    void set_definition(int area, char *new_def) {
58        arb_assert(area == TOP_AREA || area == MIDDLE_AREA);
59        char*& Area = area == TOP_AREA ? top_area : middle_area;
60        freeset(Area, new_def);
61    }
62
63    const char *get_comment() const { return comment; }
64    void set_comment(const char *newComment) { freedup(comment, newComment); }
65
66    GB_ERROR saveAsOver(GBDATA *gb_main, const char *name, const char *oldName, bool warnIfSavingDefault) const;
67    GB_ERROR save(GBDATA *gb_main, const char *name, bool warnIfSavingDefault) const {
68        return saveAsOver(gb_main, name, name, warnIfSavingDefault);
69    }
70};
71
72enum GBT_CONFIG_ITEM_TYPE {
73    CI_UNKNOWN       = 1,
74    CI_GROUP         = 2,
75    CI_FOLDED_GROUP  = 4,
76    CI_SPECIES       = 8,
77    CI_SAI           = 16,
78    CI_CLOSE_GROUP   = 32,
79    CI_END_OF_CONFIG = 64,
80};
81
82struct GBT_config_item : virtual Noncopyable {
83    GBT_CONFIG_ITEM_TYPE  type;
84    char                 *name;
85
86    GBT_config_item() : type(CI_UNKNOWN), name(NULp) {}
87    GBT_config_item(GBT_CONFIG_ITEM_TYPE type_, const char *name_) : type(type_), name(nulldup(name_)) {}
88    ~GBT_config_item() { free(name); }
89
90    void append_to_config_string(GBS_strstruct& out) const;
91};
92
93class GBT_config_parser : virtual Noncopyable {
94    char *config_string;
95    int   parse_pos;
96
97    GBT_config_item item;
98public:
99    GBT_config_parser(const GBT_config& cfg, int area)
100        : config_string(nulldup(cfg.get_definition(area))),
101          parse_pos(0)
102    {}
103    ~GBT_config_parser() { free(config_string); }
104
105    const GBT_config_item& nextItem(GB_ERROR& error);
106};
107
108#if defined(DEBUG)
109void GBT_test_config_parser(GBDATA *gb_main);
110#endif // DEBUG
111
112#else
113#error ad_config.h included twice
114#endif // AD_CONFIG_H
115
Note: See TracBrowser for help on using the repository browser.