source: tags/old_import_filter/WINDOW/aw_awar.hxx

Last change on this file was 9744, checked in by westram, 11 years ago
  • toggle temporary state of awars after each change
    • fixes #266
    • slows down AWAR write access
File size: 5.5 KB
Line 
1// ================================================================= //
2//                                                                   //
3//   File      : aw_awar.hxx                                         //
4//   Purpose   :                                                     //
5//                                                                   //
6//   Coded by Ralf Westram (coder@reallysoft.de) in September 2010   //
7//   Institute of Microbiology (Technical University Munich)         //
8//   http://www.arb-home.de/                                         //
9//                                                                   //
10// ================================================================= //
11
12#ifndef AW_AWAR_HXX
13#define AW_AWAR_HXX
14
15#ifndef AW_BASE_HXX
16#include "aw_base.hxx"
17#endif
18#ifndef CB_H
19#include <cb.h>
20#endif
21#ifndef ARBDB_BASE_H
22#include <arbdb_base.h>
23#endif
24#ifndef ARB_ASSERT_H
25#include <arb_assert.h>
26#endif
27#ifndef ATTRIBUTES_H
28#include <attributes.h>
29#endif
30#ifndef ARBTOOLS_H
31#include <arbtools.h>
32#endif
33
34// --------------
35//      AWARS
36
37class  AW_root_cblist;
38struct AW_var_target;
39struct AW_widget_refresh_cb;
40
41typedef AW_RCB  Awar_CB;
42typedef Awar_CB Awar_CB2;
43typedef void (*Awar_CB1)(AW_root *, AW_CL);
44typedef void (*Awar_CB0)(AW_root *);
45
46enum AW_widget_type {
47    AW_WIDGET_INPUT_FIELD,
48    AW_WIDGET_TEXT_FIELD,
49    AW_WIDGET_LABEL_FIELD,
50    AW_WIDGET_CHOICE_MENU,
51    AW_WIDGET_TOGGLE_FIELD,
52    AW_WIDGET_SELECTION_LIST,
53    AW_WIDGET_TOGGLE
54};
55
56
57class AW_awar : virtual Noncopyable {
58    struct {
59        struct {
60            float min;
61            float max;
62        } f;
63        const char *srt;
64    } pp;
65
66    AW_root_cblist       *callback_list;
67    AW_var_target        *target_list;
68    AW_widget_refresh_cb *refresh_list;
69
70    union {
71        char   *s;
72        double  d;
73        long    l;
74        GBDATA *p;
75    } default_value;
76
77    bool in_tmp_branch;
78
79    static bool allowed_to_run_callbacks;
80
81#if defined(DEBUG)
82    bool is_global;
83#endif // DEBUG
84
85    void remove_all_callbacks();
86    void remove_all_target_vars();
87
88    void assert_var_type(AW_VARIABLE_TYPE target_var_type);
89
90    bool has_managed_tmp_state() const { return !in_tmp_branch && gb_origin; }
91
92    void update_tmp_state_during_change();
93
94public:
95    // read only
96    class AW_root *root;
97
98    GBDATA *gb_var;                                 // if unmapped, points to same DB elem as 'gb_origin'
99    GBDATA *gb_origin;                              // this is set ONCE on creation of awar
100
101    // read only
102
103    AW_VARIABLE_TYPE  variable_type;                // type of the awar
104    char             *awar_name;                    // name of the awar
105
106    void unlink();                                  // unconditionally unlink from DB
107
108    bool unlink_from_DB(GBDATA *gb_main);
109   
110    void run_callbacks();
111    void update_target(AW_var_target*pntr);
112    void update_targets();
113
114    AW_awar(AW_VARIABLE_TYPE var_type, const char *var_name, const char *var_value, double var_double_value, AW_default default_file, AW_root *root);
115    ~AW_awar();
116
117    void tie_widget(AW_CL cd1, Widget widget, AW_widget_type type, AW_window *aww);
118    void untie_all_widgets();
119
120    AW_awar *add_callback(Awar_CB2 f, AW_CL cd1, AW_CL cd2);
121    AW_awar *add_callback(Awar_CB1 f, AW_CL cd1);
122    AW_awar *add_callback(Awar_CB0 f);
123
124    AW_awar *remove_callback(Awar_CB2 f, AW_CL cd1, AW_CL cd2);   // remove a callback
125    AW_awar *remove_callback(Awar_CB1 f, AW_CL cd1);
126    AW_awar *remove_callback(Awar_CB0 f);
127
128    AW_awar *add_target_var(char **ppchr);
129    AW_awar *add_target_var(long *pint);
130    AW_awar *add_target_var(float *pfloat);
131    void    update();       // awar has changed
132
133    AW_awar *set_minmax(float min, float max);
134    AW_awar *set_srt(const char *srt);
135
136    AW_awar *map(const char *awarn);
137    AW_awar *map(AW_default dest); // map to new address
138    AW_awar *map(AW_awar *dest); // map to new address
139    AW_awar *unmap();           // map to original address
140
141#if defined(ASSERTION_USED)
142    bool is_valid() const { return correlated(gb_var, gb_origin); } // both or none NULL
143#endif // ASSERTION_USED
144
145    void get(char **p_string)  { freeset(*p_string, read_string()); } // deletes existing targets !!!
146    void get(long *p_int)      { *p_int = (long)read_int(); }
147    void get(double *p_double) { *p_double = read_float(); }
148    void get(float *p_float)   { *p_float = read_float(); }
149
150    AW_VARIABLE_TYPE get_type() const;
151
152    char       *read_string();
153    const char *read_char_pntr();
154    char       *read_as_string();
155    long        read_int();
156    double      read_float();
157    GBDATA     *read_pointer();
158
159    GB_ERROR write_string(const char *aw_string);
160    GB_ERROR write_as_string(const char *aw_string);
161    GB_ERROR write_int(long aw_int);
162    GB_ERROR write_float(double aw_double);
163    GB_ERROR write_pointer(GBDATA *aw_pointer);
164
165    GB_ERROR write_as(char *aw_value) { return write_as_string(aw_value); };
166
167    // same as write_-versions above, but always touches the database field
168    GB_ERROR rewrite_string(const char *aw_string);
169    GB_ERROR rewrite_as_string(const char *aw_string);
170    GB_ERROR rewrite_int(long aw_int);
171    GB_ERROR rewrite_float(double aw_double);
172    GB_ERROR rewrite_pointer(GBDATA *aw_pointer);
173
174    GB_ERROR rewrite_as(char *aw_value) { return rewrite_as_string(aw_value); };
175
176    GB_ERROR toggle_toggle();   // switches between 1/0
177    void     touch();
178
179    GB_ERROR make_global() __ATTR__USERESULT;       // should be used by ARB_init_global_awars only
180    void set_temp_if_is_default(GBDATA *gb_db);
181};
182
183
184
185#else
186#error aw_awar.hxx included twice
187#endif // AW_AWAR_HXX
188
Note: See TracBrowser for help on using the repository browser.