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 
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) {}
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 
71  CI_GROUP = 2,
74  CI_SAI = 16,
77 };
78 
79 struct GBT_config_item : virtual Noncopyable {
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 
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 
#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:94
static const int MIDDLE_AREA
Definition: ad_config.h:46
void GBT_append_to_config_string(const GBT_config_item &item, struct GBS_strstruct *strstruct)
Definition: ad_config.cxx:190
GBT_config_item(GBT_CONFIG_ITEM_TYPE type_, const char *name_)
Definition: ad_config.h:84
static const int TOP_AREA
Definition: ad_config.h:45
bool exists() const
Definition: ad_config.h:48
GBT_CONFIG_ITEM_TYPE type
Definition: ad_config.h:80
const char * get_comment() const
Definition: ad_config.h:60
static void error(const char *msg)
Definition: mkptypes.cxx:96
GBT_CONFIG_ITEM_TYPE
Definition: ad_config.h:69
void set_comment(const char *newComment)
Definition: ad_config.h:61
GBDATA * GBT_find_configuration(GBDATA *gb_main, const char *name)
Definition: ad_config.cxx:59
GB_ERROR save(GBDATA *gb_main, const char *name, bool warnIfSavingDefault) const
Definition: ad_config.h:64
GB_ERROR saveAsOver(GBDATA *gb_main, const char *name, const char *oldName, bool warnIfSavingDefault) const
Definition: ad_config.cxx:102
void GBT_get_configuration_names(struct ConstStrArray &configNames, GBDATA *gb_main)
Definition: ad_config.cxx:21
const GBT_config_item & nextItem(GB_ERROR &error)
Definition: ad_config.cxx:140
~GBT_config()
Definition: ad_config.h:39
const char * get_definition(int area) const
Definition: ad_config.h:50
#define NULp
Definition: cxxforward.h:97
GBDATA * gb_main
Definition: adname.cxx:33
GBT_config()
Definition: ad_config.h:38
void set_definition(int area, char *new_def)
Definition: ad_config.h:54