ARB
ad_config.h
Go to the documentation of this file.
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 
32 GBDATA *GBT_find_configuration(GBDATA *gb_main, const char *name);
33 void GBT_get_configuration_names(struct ConstStrArray& configNames, GBDATA *gb_main);
34 
35 class GBT_config : virtual Noncopyable {
36  char *top_area;
37  char *middle_area;
38  char *comment; // NULp if no comment exists
39 public:
40  GBT_config(GBDATA *gb_main, const char *name, GB_ERROR& error);
41  GBT_config() : top_area(NULp), middle_area(NULp), comment(NULp) {}
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 
74  CI_GROUP = 2,
77  CI_SAI = 16,
80 };
81 
82 struct GBT_config_item : virtual Noncopyable {
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 
93 class GBT_config_parser : virtual Noncopyable {
94  char *config_string;
95  int parse_pos;
96 
97  GBT_config_item item;
98 public:
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 
106 };
107 
108 #if defined(DEBUG)
109 void 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 
#define arb_assert(cond)
Definition: arb_assert.h:245
const char * GB_ERROR
Definition: arb_core.h:25
GBT_config_parser(const GBT_config &cfg, int area)
Definition: ad_config.h:99
static const int MIDDLE_AREA
Definition: ad_config.h:49
GBT_config_item(GBT_CONFIG_ITEM_TYPE type_, const char *name_)
Definition: ad_config.h:87
static const int TOP_AREA
Definition: ad_config.h:48
void append_to_config_string(GBS_strstruct &out) const
Definition: ad_config.cxx:189
bool exists() const
Definition: ad_config.h:51
GBT_CONFIG_ITEM_TYPE type
Definition: ad_config.h:83
const char * get_comment() const
Definition: ad_config.h:63
static void error(const char *msg)
Definition: mkptypes.cxx:96
GBT_CONFIG_ITEM_TYPE
Definition: ad_config.h:72
void set_comment(const char *newComment)
Definition: ad_config.h:64
GBDATA * GBT_find_configuration(GBDATA *gb_main, const char *name)
Definition: ad_config.cxx:58
GB_ERROR save(GBDATA *gb_main, const char *name, bool warnIfSavingDefault) const
Definition: ad_config.h:67
GB_ERROR saveAsOver(GBDATA *gb_main, const char *name, const char *oldName, bool warnIfSavingDefault) const
Definition: ad_config.cxx:101
void GBT_get_configuration_names(struct ConstStrArray &configNames, GBDATA *gb_main)
Definition: ad_config.cxx:20
const GBT_config_item & nextItem(GB_ERROR &error)
Definition: ad_config.cxx:139
~GBT_config()
Definition: ad_config.h:42
const char * get_definition(int area) const
Definition: ad_config.h:53
#define NULp
Definition: cxxforward.h:116
GBDATA * gb_main
Definition: adname.cxx:32
GBT_config()
Definition: ad_config.h:41
void set_definition(int area, char *new_def)
Definition: ad_config.h:57