source: tags/ms_r16q2/AWT/awt_config_manager.hxx

Last change on this file was 15040, checked in by westram, 8 years ago
  • allow to build AWT_config from mapping in AWT_config_definition
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.5 KB
Line 
1//  ==================================================================== //
2//                                                                       //
3//    File      : awt_config_manager.hxx                                 //
4//    Purpose   : general interface to store/restore                     //
5//                a set of related awars                                 //
6//                                                                       //
7//                                                                       //
8//  Coded by Ralf Westram (coder@reallysoft.de) in January 2002          //
9//  Copyright Department of Microbiology (Technical University Munich)   //
10//                                                                       //
11//  Visit our web site at: http://www.arb-home.de/                       //
12//                                                                       //
13//                                                                       //
14//  ==================================================================== //
15
16#ifndef AWT_CONFIG_MANAGER_HXX
17#define AWT_CONFIG_MANAGER_HXX
18
19#ifndef AW_BASE_HXX
20#include <aw_base.hxx>
21#endif
22#ifndef CB_H
23#include <cb.h>
24#endif
25
26struct AWT_config_mapping;
27class  AWT_config_definition;
28
29struct AWT_config_mapping_def {
30    const char *awar_name;
31    const char *config_name;
32};
33
34struct AWT_predefined_config {
35    const char *name;        // of predefined config (has to begin with '*')
36    const char *description;
37    const char *config;      // config string (as generated by AWT_config::config_string)
38};
39
40// -------------------
41//      AWT_config
42
43class AWT_config : virtual Noncopyable {
44    // stores one specific configuration (key->value pairs)
45    //
46    // this class allows to modify the config_string before calling AWT_config_definition::write().
47    // This is e.g. necessary if some config-entries change and you want to support
48    // automatic conversion from old format to new format.
49
50    AWT_config_mapping *mapping;
51    GB_ERROR           parse_error; // set by AWT_config(const char *)
52
53    void init_from_awars(const AWT_config_mapping *cfgname_2_awar);
54
55public:
56    AWT_config(const char *config_string);
57    AWT_config(const AWT_config_mapping *cfgname_2_awar); // internal use (reads current awar values)
58    AWT_config(const AWT_config_definition *cfg_def);     // internal use (reads current awar values)
59    ~AWT_config();
60
61    GB_ERROR parseError() const { return parse_error; }
62
63    // props + modifiers
64    bool has_entry(const char *entry) const; // returns true if mapping contains 'entry'
65    const char *get_entry(const char *entry) const; // returns value of 'entry'
66    void set_entry(const char *entry, const char *value); // sets a (new) entry to value
67    void delete_entry(const char *entry); // deletes an existing 'entry'
68
69    // result
70    char *config_string() const; // return current state as config string
71    void write_to_awars(const AWT_config_mapping *cfgname_2_awar, bool warn) const; // internal use (write config into awars)
72
73    void get_entries(class ConstStrArray& to_array);
74};
75
76// ------------------------------
77//      AWT_config_definition
78
79class AWT_config_definition : virtual Noncopyable {
80    AWT_config_mapping *config_mapping; // defines config-name -> awar-name relation
81
82public:
83    AWT_config_definition();
84    AWT_config_definition(AWT_config_mapping_def *mapping_definition); // simple definition
85    ~AWT_config_definition();
86
87    void add(const char *awar_name, const char *config_name);
88    void add(const char *awar_name, const char *config_name, int counter);
89    void add(const AWT_config_mapping_def *mapping_definition);
90
91    char *read() const;                          // awars -> config string (heap copy)
92    void write(const char *config_string) const; // config string -> awars (use to restore a saved configuration)
93    void reset() const;                          // reset awars to defaults
94
95    const AWT_config_mapping *get_mapping() const { return config_mapping; }
96};
97
98// ----------------------------------------
99//      callbacks from config manager :
100
101DECLARE_CBTYPE_FVV_AND_BUILDERS(ConfigSetupCallback,   void, AWT_config_definition&); // defines makeConfigSetupCallback
102DECLARE_CBTYPE_VV_AND_BUILDERS (StoreConfigCallback,   char*);                        // defines makeStoreConfigCallback
103DECLARE_CBTYPE_FVV_AND_BUILDERS(RestoreConfigCallback, void, const char *);           // defines makeRestoreConfigCallback
104
105// ----------------------------------
106// the config manager itself
107// adds button at cursor position when called (from a window generator function)
108
109void AWT_insert_config_manager(AW_window *aww, AW_default default_file_, const char *id, const StoreConfigCallback& store, const RestoreConfigCallback& load_or_reset, const char *macro_id = NULL, const AWT_predefined_config *predef = NULL);
110void AWT_insert_config_manager(AW_window *aww, AW_default default_file_, const char *id, ConfigSetupCallback setup_cb, const char *macro_id = NULL, const AWT_predefined_config *predef = NULL);
111void AWT_insert_config_manager(AW_window *aww, AW_default default_file_, const char *id, const AWT_config_mapping_def *mapping, const char *macro_id = NULL, const AWT_predefined_config *predef = NULL);
112
113// -------------------------------
114//      modify stored configs
115
116typedef char *(*ConfigModifyCallback)(const char *key, const char *value, AW_CL cl_user);
117void AWT_modify_managed_configs(AW_default default_file_, const char *id, ConfigModifyCallback mod_cb, AW_CL cl_user);
118
119#else
120#error awt_config_manager.hxx included twice
121#endif // AWT_CONFIG_MANAGER_HXX
122
Note: See TracBrowser for help on using the repository browser.