source: tags/arb-6.0/AWT/awt_config_manager.hxx

Last change on this file was 6867, checked in by westram, 14 years ago
  • ARB GUI (merges [6844] [6845] [6847] [6858] [6861] from refactor)
    • new central header cb.h (planned to define ALL callbacks used in ARB here later)
    • refactored callback handling for some AW_root callbacks
      • AW_root_callback hides function ptr + arguments
      • AW_root_cblist hides lists of AW_root_callback
    • DRYed AW_RCB
    • reduced tight coupling between some of WINDOW/*.hxx (omg)
    • removed AWUSE
  • 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
19#ifndef ARBDB_BASE_H
20#include <arbdb_base.h>
21#endif
22#ifndef AW_BASE_HXX
23#include <aw_base.hxx>
24#endif
25
26struct AWT_config_mapping;
27
28struct AWT_config_mapping_def {
29    const char *awar_name;
30    const char *config_name;
31};
32
33// -------------------
34//      AWT_config
35
36class AWT_config {
37    // stores one specific configuration (key->value pairs)
38    //
39    // this class allows to modify the config_string before calling AWT_config_definition::write().
40    // This is e.g. necessary if some config-entries change and you want to support
41    // automatic conversion from old format to new format.
42
43    AWT_config_mapping *mapping;
44    GB_ERROR           parse_error; // set by AWT_config(const char *)
45
46    AWT_config(const AWT_config&);
47    AWT_config& operator = (const AWT_config&);
48public:
49    AWT_config(const char *config_string);
50    AWT_config(const AWT_config_mapping *cfgname_2_awar, AW_root *root); // internal use (reads current awar values)
51    ~AWT_config();
52
53    GB_ERROR parseError() const { return parse_error; }
54
55    // props + modifiers
56    bool has_entry(const char *entry) const; // returns true if mapping contains 'entry'
57    const char *get_entry(const char *entry) const; // returns value of 'entry'
58    void set_entry(const char *entry, const char *value); // sets a (new) entry to value
59    void delete_entry(const char *entry); // deletes an existing 'entry'
60
61    // result
62    char *config_string() const; // return current state as config string
63    GB_ERROR write_to_awars(const AWT_config_mapping *cfgname_2_awar, AW_root *root) const; // internal use (write config into awars)
64};
65
66// ------------------------------
67//      AWT_config_definition
68
69class AWT_config_definition {
70private:
71    AW_root            *root;
72    AWT_config_mapping *config_mapping; // defines config-name -> awar-name relation
73
74    AWT_config_definition(const AWT_config_definition&);
75    AWT_config_definition& operator = (const AWT_config_definition&);
76public:
77    AWT_config_definition(AW_root *aw_root);
78    AWT_config_definition(AW_root *aw_root, AWT_config_mapping_def *mapping_definition); // simple definition
79    virtual ~AWT_config_definition();
80
81    void add(const char *awar_name, const char *config_name);
82    void add(const char *awar_name, const char *config_name, int counter);
83    void add(AWT_config_mapping_def *mapping_definition);
84
85    char *read() const;         // awars -> config string (heap copy)
86    void write(const char *config_string) const; // config string -> awars (use to restore a saved configuration)
87
88    AW_root *get_root() const { return root; }
89};
90
91// ----------------------------------------
92//      callbacks from config manager :
93
94typedef char *(*AWT_store_config_to_string)(AW_window *aww, AW_CL cl1, AW_CL cl2);
95typedef void (*AWT_load_config_from_string)(AW_window *aww, const char *stored_string, AW_CL cl1, AW_CL cl2);
96
97// ----------------------------------
98// the config manager itself
99// adds button at cursor position when called (from a window generator function)
100
101void 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);
102
103#else
104#error awt_config_manager.hxx included twice
105#endif // AWT_CONFIG_MANAGER_HXX
106
Note: See TracBrowser for help on using the repository browser.