source: branches/profile/WINDOW/aw_awar.hxx

Last change on this file was 12358, checked in by westram, 10 years ago
  • AW_awar read access is const (effective)
File size: 6.4 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
41// @@@ [CB] eliminate decls below? just use AW_RCB instead // @@@ duplicated in cb.h
42typedef AW_RCB  Awar_CB;
43typedef Awar_CB Awar_CB2;
44typedef         void (*Awar_CB1)(AW_root *, AW_CL);
45typedef         void (*Awar_CB0)(AW_root *);
46
47enum AW_widget_type {
48    AW_WIDGET_INPUT_FIELD,
49    AW_WIDGET_TEXT_FIELD,
50    AW_WIDGET_LABEL_FIELD,
51    AW_WIDGET_CHOICE_MENU,
52    AW_WIDGET_TOGGLE_FIELD,
53    AW_WIDGET_SELECTION_LIST,
54    AW_WIDGET_TOGGLE
55};
56
57
58class AW_awar : virtual Noncopyable {
59    struct {
60        struct {
61            float min;
62            float max;
63        } f;
64        const char *srt;
65    } pp;
66
67    AW_root_cblist       *callback_list;
68    AW_var_target        *target_list;
69    AW_widget_refresh_cb *refresh_list;
70
71    union {
72        char   *s;
73        double  d;
74        long    l;
75        GBDATA *p;
76    } default_value;
77
78    bool in_tmp_branch;
79
80    static bool allowed_to_run_callbacks;
81
82#if defined(DEBUG)
83    bool is_global;
84#endif // DEBUG
85
86    void remove_all_callbacks();
87    void remove_all_target_vars();
88
89    void assert_var_type(AW_VARIABLE_TYPE target_var_type);
90
91    bool has_managed_tmp_state() const { return !in_tmp_branch && gb_origin; }
92
93    void update_tmp_state_during_change();
94
95public:
96    // read only
97    class AW_root *root;
98
99    GBDATA *gb_var;                                 // if unmapped, points to same DB elem as 'gb_origin'
100    GBDATA *gb_origin;                              // this is set ONCE on creation of awar
101
102    // read only
103
104    AW_VARIABLE_TYPE  variable_type;                // type of the awar
105    char             *awar_name;                    // name of the awar
106
107    void unlink();                                  // unconditionally unlink from DB
108
109    bool unlink_from_DB(GBDATA *gb_main);
110   
111    void run_callbacks();
112    void update_target(AW_var_target*pntr);
113    void update_targets();
114
115    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);
116    ~AW_awar();
117
118    void tie_widget(AW_CL cd1, Widget widget, AW_widget_type type, AW_window *aww);
119    void untie_all_widgets();
120
121    AW_awar *add_callback(const RootCallback& cb);
122    AW_awar *add_callback(Awar_CB0 f) { return add_callback(makeRootCallback(f)); }
123    AW_awar *add_callback(Awar_CB1 f, AW_CL cd1) __ATTR__DEPRECATED_TODO("pass RootCallback") { return add_callback(makeRootCallback(f, cd1)); }
124    AW_awar *add_callback(Awar_CB2 f, AW_CL cd1, AW_CL cd2) __ATTR__DEPRECATED_TODO("pass RootCallback") { return add_callback(makeRootCallback(f, cd1, cd2)); }
125
126    AW_awar *remove_callback(const RootCallback& cb);
127    AW_awar *remove_callback(Awar_CB0 f) { return remove_callback(makeRootCallback(f)); }
128    AW_awar *remove_callback(Awar_CB1 f, AW_CL cd1) __ATTR__DEPRECATED_TODO("pass RootCallback") { return remove_callback(makeRootCallback(f, cd1)); }
129    AW_awar *remove_callback(Awar_CB2 f, AW_CL cd1, AW_CL cd2) __ATTR__DEPRECATED_TODO("pass RootCallback") { return remove_callback(makeRootCallback(f, cd1, cd2)); }
130
131    AW_awar *add_target_var(char **ppchr);
132    AW_awar *add_target_var(long *pint);
133    AW_awar *add_target_var(float *pfloat);
134    void    update();       // awar has changed
135
136    AW_awar *set_minmax(float min, float max);
137    float    get_min() const;
138    float    get_max() const;
139    AW_awar *set_min(float min) { return set_minmax(min, get_max()); }
140    AW_awar *set_srt(const char *srt);
141
142    AW_awar *map(const char *awarn);
143    AW_awar *map(AW_default dest); // map to new address
144    AW_awar *map(AW_awar *dest); // map to new address
145    AW_awar *unmap();           // map to original address
146
147#if defined(ASSERTION_USED)
148    bool is_valid() const { return correlated(gb_var, gb_origin); } // both or none NULL
149#endif // ASSERTION_USED
150
151    void get(char **p_string)  { freeset(*p_string, read_string()); } // deletes existing targets !!!
152    void get(long *p_int)      { *p_int = (long)read_int(); }
153    void get(double *p_double) { *p_double = read_float(); }
154    void get(float *p_float)   { *p_float = read_float(); }
155
156    AW_VARIABLE_TYPE get_type() const;
157
158    char       *read_string() const;
159    const char *read_char_pntr() const;
160    char       *read_as_string() const;
161    long        read_int() const;
162    double      read_float() const;
163    GBDATA     *read_pointer() const;
164
165    GB_ERROR write_string(const char *aw_string);
166    GB_ERROR write_as_string(const char *aw_string);
167    GB_ERROR write_int(long aw_int);
168    GB_ERROR write_float(double aw_double);
169    GB_ERROR write_pointer(GBDATA *aw_pointer);
170
171    GB_ERROR write_as(char *aw_value) { return write_as_string(aw_value); };
172
173    // same as write_-versions above, but always touches the database field
174    GB_ERROR rewrite_string(const char *aw_string);
175    GB_ERROR rewrite_as_string(const char *aw_string);
176    GB_ERROR rewrite_int(long aw_int);
177    GB_ERROR rewrite_float(double aw_double);
178    GB_ERROR rewrite_pointer(GBDATA *aw_pointer);
179
180    GB_ERROR rewrite_as(char *aw_value) { return rewrite_as_string(aw_value); };
181
182    GB_ERROR toggle_toggle();   // switches between 1/0
183    void     touch();
184
185    GB_ERROR make_global() __ATTR__USERESULT;       // should be used by ARB_init_global_awars only
186    void set_temp_if_is_default(GBDATA *gb_db);
187};
188
189
190
191#else
192#error aw_awar.hxx included twice
193#endif // AW_AWAR_HXX
194
Note: See TracBrowser for help on using the repository browser.