ARB
rootAsWin.h
Go to the documentation of this file.
1 // ============================================================ //
2 // //
3 // File : rootAsWin.h //
4 // Purpose : //
5 // //
6 // Coded by Ralf Westram (coder@reallysoft.de) in July 2013 //
7 // Institute of Microbiology (Technical University Munich) //
8 // http://www.arb-home.de/ //
9 // //
10 // ============================================================ //
11 
12 #ifndef ROOTASWIN_H
13 #define ROOTASWIN_H
14 
15 #ifndef CB_H
16 #include <cb.h>
17 #endif
18 
20  // Allows to use any RootCallback where a WindowCallback is expected.
21 
22  RootCallback rcb;
23  void call(AW_window *aww) const { rcb(aww->get_root()); }
24  RootAsWindowCallback(const RootCallback& rcb_) : rcb(rcb_) {}
25 
26  static void window_cb(AW_window *aww, const RootAsWindowCallback *rawcb) { rawcb->call(aww); }
27  static void delete_raw_cb(RootAsWindowCallback *raw_cb) { delete raw_cb; }
28 
29  template<typename T>
30  static void call_root_as_win(AW_window *aww, void (*root_cb)(AW_root*, T), T t) { root_cb(aww->get_root(), t); }
31 
32  static void call_root_as_win(AW_window *aww, void (*root_cb)(AW_root*)) { root_cb(aww->get_root()); }
33 
34 public:
35 
36  static WindowCallback reuse(const RootCallback& rcb) {
37  // It's not recommended to use this widely, mainly this is a helper for refactoring.
38  // Normally you should better adapt your callback-type.
39  //
40  // Use it in cases where a user-provided callback has to be used
41  // both as RootCallback and as WindowCallback.
42 
43  return makeWindowCallback(window_cb, delete_raw_cb, new RootAsWindowCallback(rcb));
44  }
45 
46  template<typename T>
47  static WindowCallback simple(void (*root_cb)(AW_root*, T), T t) {
48  // usable for simple root callbacks with only one argument
49  // (automatically creates one general wrapper function for each type T)
50  return makeWindowCallback(call_root_as_win, root_cb, t);
51  }
52 
53  static WindowCallback simple(void (*root_cb)(AW_root*)) {
54  // usable for simple root callbacks with no argument
55  return makeWindowCallback(call_root_as_win, root_cb);
56  }
57 };
58 
59 #else
60 #error rootAsWin.h included twice
61 #endif // ROOTASWIN_H
static WindowCallback reuse(const RootCallback &rcb)
Definition: rootAsWin.h:36
static WindowCallback simple(void(*root_cb)(AW_root *, T), T t)
Definition: rootAsWin.h:47
AW_root * get_root()
Definition: aw_window.hxx:348
Definition: trnsprob.h:20
static WindowCallback simple(void(*root_cb)(AW_root *))
Definition: rootAsWin.h:53