ARB
aw_awar.hxx
Go to the documentation of this file.
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 
37 class AW_root_cblist;
38 struct AW_var_target;
40 
50 };
51 
52 
53 class AW_awar : virtual Noncopyable {
54  struct {
55  struct {
56  float min;
57  float max;
58  } f;
59  const char *srt;
60  } pp;
61 
62  AW_root_cblist *callback_list;
63  AW_var_target *target_list;
64  AW_widget_refresh_cb *refresh_list;
65 
66  union {
67  char *s;
68  float f;
69  long l;
71  } default_value;
72 
73  bool in_tmp_branch;
74 
75  static bool allowed_to_run_callbacks;
76 
77  double callback_time_sum; // in seconds
78  int callback_time_count; // number of callbacks traced in callback_time_sum
79 
80 #if defined(DEBUG)
81  bool is_global;
82 #endif // DEBUG
83 
84  void remove_all_callbacks();
85  void remove_all_target_vars();
86 
87  void assert_var_type(AW_VARIABLE_TYPE target_var_type);
88 
89  bool has_managed_tmp_state() const { return !in_tmp_branch && gb_origin; }
90 
91  void update_tmp_state_during_change();
92 
93 public:
94  // read only
95  class AW_root *root;
96 
97  GBDATA *gb_var; // if unmapped, points to same DB elem as 'gb_origin'
98  GBDATA *gb_origin; // this is set ONCE on creation of awar
99 
100  // read only
101 
102  AW_VARIABLE_TYPE variable_type; // type of the awar
103  char *awar_name; // name of the awar
104 
105 #if defined(ASSERTION_USED)
106  static bool deny_read; // true -> make awar reads fail
107  static bool deny_write; // true -> make awar writes fail
108 #endif
109 
110  void unlink(); // unconditionally unlink from DB
111 
113 
114  void run_callbacks();
115  double mean_callback_time() const {
116  if (callback_time_sum>0) {
117  return callback_time_sum / callback_time_count;
118  }
119  return 0.0;
120  }
121 
122  void update_target(AW_var_target*pntr);
123  void update_targets();
124 
125  AW_awar(AW_VARIABLE_TYPE var_type, const char *var_name, const char *var_value, float var_float_value, AW_default default_file, AW_root *root);
126  ~AW_awar();
127 
128  void tie_widget(AW_CL cd1, Widget widget, AW_widget_type type, AW_window *aww);
129  void untie_all_widgets();
130 
131  AW_awar *add_callback(const RootCallback& cb);
132  AW_awar *add_callback(RootCallbackSimple f) { return add_callback(makeRootCallback(f)); }
133 
134  AW_awar *remove_callback(const RootCallback& cb);
135  AW_awar *remove_callback(RootCallbackSimple f) { return remove_callback(makeRootCallback(f)); }
136 
137  AW_awar *add_target_var(char **ppchr);
138  AW_awar *add_target_var(long *pint);
139  AW_awar *add_target_var(float *pfloat);
140  void update(); // awar has changed
141 
142  AW_awar *set_minmax(float min, float max); // min<max !!!
143  float get_min() const;
144  float get_max() const;
145  AW_awar *set_min(float min) { return set_minmax(min, get_max()); }
146  AW_awar *set_max(float max) { return set_minmax(get_min(), max); }
147  AW_awar *set_srt(const char *srt);
148 
149  AW_awar *map(const char *awarn);
150  AW_awar *map(AW_default dest); // map to new address
151  AW_awar *map(AW_awar *dest); // map to new address
152  AW_awar *unmap(); // map to original address
153  bool is_mapped() const { return gb_var != gb_origin; }
154 
155 #if defined(ASSERTION_USED)
156  bool is_valid() const { return correlated(gb_var, gb_origin); } // both or none NULp
157 #endif // ASSERTION_USED
158 
159  void get(char **p_string) { freeset(*p_string, read_string()); } // deletes existing targets !!!
160  void get(long *p_int) { *p_int = (long)read_int(); }
161  void get(float *p_float) { *p_float = read_float(); }
162 
163  AW_VARIABLE_TYPE get_type() const;
164 
165  char *read_string() const;
166  const char *read_char_pntr() const;
167  char *read_as_string() const;
168  long read_int() const;
169  float read_float() const;
170  GBDATA *read_pointer() const;
171 
172  GB_ERROR write_string(const char *aw_string);
173  GB_ERROR write_as_string(const char *aw_string);
174  GB_ERROR write_int(long aw_int);
175  GB_ERROR write_float(float aw_float);
176  GB_ERROR write_pointer(GBDATA *aw_pointer);
177 
178  GB_ERROR write_as(char *aw_value) { return write_as_string(aw_value); };
179 
180  // same as write_-versions above, but always touches the database field
181  GB_ERROR rewrite_string(const char *aw_string);
182  GB_ERROR rewrite_as_string(const char *aw_string);
183  GB_ERROR rewrite_int(long aw_int);
184  GB_ERROR rewrite_float(float aw_float);
185  GB_ERROR rewrite_pointer(GBDATA *aw_pointer);
186 
187  GB_ERROR rewrite_as(char *aw_value) { return rewrite_as_string(aw_value); };
188 
189  GB_ERROR toggle_toggle(); // switches between 1/0
190  void touch();
191 
193 
194  GB_ERROR make_global() __ATTR__USERESULT; // should be used by ARB_init_global_awars only
195  void set_temp_if_is_default(GBDATA *gb_db);
196 };
197 
198 
199 
200 #else
201 #error aw_awar.hxx included twice
202 #endif // AW_AWAR_HXX
203 
GB_ERROR rewrite_pointer(GBDATA *aw_pointer)
class AW_root * root
Definition: aw_awar.hxx:95
GB_ERROR make_global() __ATTR__USERESULT
GBDATA * p
Definition: aw_awar.hxx:70
const char * GB_ERROR
Definition: arb_core.h:25
GB_TYPES type
AW_awar * set_srt(const char *srt)
Definition: AW_awar.cxx:569
AW_awar * add_callback(RootCallbackSimple f)
Definition: aw_awar.hxx:132
GBDATA * read_pointer() const
Definition: AW_awar.cxx:194
GB_ERROR write_pointer(GBDATA *aw_pointer)
AW_awar(AW_VARIABLE_TYPE var_type, const char *var_name, const char *var_value, float var_float_value, AW_default default_file, AW_root *root)
Definition: AW_awar.cxx:290
long
Definition: AW_awar.cxx:154
GB_ERROR rewrite_as_string(const char *aw_string)
AW_VARIABLE_TYPE variable_type
Definition: aw_awar.hxx:102
long read_int() const
Definition: AW_awar.cxx:187
AW_awar * set_minmax(float min, float max)
Definition: AW_awar.cxx:532
void unlink()
Definition: AW_awar.cxx:644
void run_callbacks()
Definition: AW_awar.cxx:602
void(* RootCallbackSimple)(AW_root *)
Definition: cb.h:28
bool is_mapped() const
Definition: aw_awar.hxx:153
AW_VARIABLE_TYPE get_type() const
Definition: AW_awar.cxx:265
GB_ERROR toggle_toggle()
Definition: AW_awar.cxx:575
AW_awar * set_max(float max)
Definition: aw_awar.hxx:146
#define cb(action)
AW_awar * add_callback(const RootCallback &cb)
Definition: AW_awar.cxx:234
const char * read_char_pntr() const
Definition: AW_awar.cxx:171
static bool deny_read
Definition: aw_awar.hxx:106
GB_ERROR write_as(char *aw_value)
Definition: aw_awar.hxx:178
GB_ERROR rewrite_int(long aw_int)
AW_VARIABLE_TYPE
Definition: aw_base.hxx:53
GB_ERROR rewrite_as(char *aw_value)
Definition: aw_awar.hxx:187
long l
Definition: aw_awar.hxx:69
bool is_valid() const
Definition: aw_awar.hxx:156
void update()
Definition: AW_awar.cxx:393
float get_max() const
Definition: AW_awar.cxx:557
double mean_callback_time() const
Definition: aw_awar.hxx:115
void touch()
Definition: AW_awar.cxx:210
GBDATA * gb_origin
Definition: aw_awar.hxx:98
bool unlink_from_DB(GBDATA *gb_main)
Definition: AW_awar.cxx:653
char * read_as_string() const
float f
Definition: aw_awar.hxx:68
GB_ERROR reset_to_default()
Definition: AW_awar.cxx:217
void set_temp_if_is_default(GBDATA *gb_db)
Definition: AW_awar.cxx:714
char * read_string() const
Definition: AW_awar.cxx:201
float max
Definition: aw_awar.hxx:57
AW_awar * unmap()
Definition: AW_awar.cxx:598
float get_min() const
Definition: AW_awar.cxx:546
AW_awar * remove_callback(const RootCallback &cb)
Definition: AW_awar.cxx:527
float read_float() const
Definition: AW_awar.cxx:180
GB_ERROR write_as_string(const char *aw_string)
char * awar_name
Definition: aw_awar.hxx:103
const char * srt
Definition: aw_awar.hxx:59
~AW_awar()
Definition: AW_awar.cxx:727
AW_awar * add_target_var(char **ppchr)
Definition: AW_awar.cxx:239
long AW_CL
Definition: cb.h:21
GB_ERROR rewrite_float(float aw_float)
GBDATA * gb_var
Definition: aw_awar.hxx:97
AW_awar * remove_callback(RootCallbackSimple f)
Definition: aw_awar.hxx:135
#define __ATTR__USERESULT
Definition: attributes.h:58
float min
Definition: aw_awar.hxx:56
AW_awar * map(const char *awarn)
Definition: AW_awar.cxx:523
void update_target(AW_var_target *pntr)
Definition: AW_awar.cxx:461
static bool deny_write
Definition: aw_awar.hxx:107
void update_targets()
Definition: AW_awar.cxx:625
AW_widget_type
Definition: aw_awar.hxx:41
GB_ERROR write_string(const char *aw_string)
void untie_all_widgets()
Definition: AW_awar.cxx:230
struct AW_awar::@60::@62 f
GBDATA * gb_main
Definition: adname.cxx:33
GB_ERROR write_float(float aw_float)
GB_ERROR write_int(long aw_int)
struct _WidgetRec * Widget
Definition: aw_base.hxx:48
char * s
Definition: aw_awar.hxx:67
void tie_widget(AW_CL cd1, Widget widget, AW_widget_type type, AW_window *aww)
Definition: AW_awar.cxx:260
AW_awar * set_min(float min)
Definition: aw_awar.hxx:145
GB_ERROR rewrite_string(const char *aw_string)