source: tags/arb_5.2/AWT/awt_config_manager.hxx

Last change on this file was 6121, checked in by westram, 15 years ago
  • fixed macro ids for merge species window
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 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
19struct AWT_config_mapping;
20
21struct AWT_config_mapping_def { 
22    const char *awar_name;
23    const char *config_name;
24};
25
26// ----------------------------------------
27//      class AWT_config
28// ----------------------------------------
29class AWT_config {
30    // stores one specific configuration (key->value pairs)
31    //
32    // this class allows to modify the config_string before calling AWT_config_definition::write().
33    // This is e.g. neccessary if some config-entries change and you want to support
34    // automatic conversion from old format to new format.
35
36    AWT_config_mapping *mapping;
37    GB_ERROR           parse_error; // set by AWT_config(const char *)
38
39    AWT_config(const AWT_config&);
40    AWT_config& operator = (const AWT_config&);
41public:
42    AWT_config(const char *config_string);
43    AWT_config(const AWT_config_mapping *cfgname_2_awar, AW_root *root); // internal use (reads current awar values)
44    ~AWT_config();
45
46    GB_ERROR parseError() const { return parse_error; }
47
48    // props + modifiers
49    bool has_entry(const char *entry) const; // returns true if mapping contains 'entry'
50    const char *get_entry(const char *entry) const; // returns value of 'entry'
51    void set_entry(const char *entry, const char *value); // sets a (new) entry to value
52    void delete_entry(const char *entry); // deletes an existing 'entry'
53
54    // result
55    char *config_string() const; // return current state as config string
56    GB_ERROR write_to_awars(const AWT_config_mapping *cfgname_2_awar, AW_root *root) const; // internal use (write config into awars)
57};
58
59//  ------------------------------------
60//      class AWT_config_definition
61//  ------------------------------------
62class AWT_config_definition {
63private:
64    AW_root            *root;
65    AWT_config_mapping *config_mapping; // defines config-name -> awar-name relation
66
67    AWT_config_definition(const AWT_config_definition&);
68    AWT_config_definition& operator = (const AWT_config_definition&);
69public:
70    AWT_config_definition(AW_root *aw_root);
71    AWT_config_definition(AW_root *aw_root, AWT_config_mapping_def *mapping_definition); // simple definition
72    virtual ~AWT_config_definition();
73
74    void add(const char *awar_name, const char *config_name);
75    void add(const char *awar_name, const char *config_name, int counter);
76    void add(AWT_config_mapping_def *mapping_definition);
77
78    char *read() const;         // awars -> config string (heap copy)
79    void write(const char *config_string) const; // config string -> awars (use to restore a saved configuration)
80
81    AW_root *get_root() const { return root; }
82};
83
84// callbacks from config manager :
85typedef char *(*AWT_store_config_to_string)(AW_window *aww, AW_CL cl1, AW_CL cl2);
86typedef void (*AWT_load_config_from_string)(AW_window *aww, const char *stored_string, AW_CL cl1, AW_CL cl2);
87
88// the config manager itself -> adds button at cursor position when called (from a window generator function)
89void AWT_insert_config_manager(AW_window *aww, AW_default default_file_, const char *id, AWT_store_config_to_string store, AWT_load_config_from_string load, AW_CL cl1, AW_CL cl2, const char *macro_id = NULL);
90
91#else
92#error awt_config_manager.hxx included twice
93#endif // AWT_CONFIG_MANAGER_HXX
94
Note: See TracBrowser for help on using the repository browser.