Beast - Music Synthesizer and Composer  0.11.1+10.g2da35
bsecxxarg.hh
Go to the documentation of this file.
1  // Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html
2 #ifndef __BSE_CXX_ARG_H__
3 #define __BSE_CXX_ARG_H__
4 
5 #include <bse/bsecxxvalue.hh>
6 
7 /* Closure Argument implementation. For a given type, these templates
8  * provide a class Arg with get() and set() functions on class Value,
9  * and a token() function which returns a single character string to
10  * identify the argument type.
11  */
12 
13 namespace Bse {
14 
15 /* default Arg type, this either supports a CxxBase* pointer or errors out */
16 template<typename T>
17 struct Arg {
18  T get (const Value *v) { return (T) v->get_base(); }
19  void set (Value *v, T t) { v->set_base (t); }
20  const String token () { void (*f) (T) = 0; return tokenize (f); }
21 private:
22  template<typename U> static const String
23  ptokenize (CxxBase*)
24  { // CxxBase* is a supported pointer type
25  return "X";
26  }
27  template<typename U> static const String
28  ptokenize (void const *)
29  { // other pointer types are not supported
30  return "?";
31  static_assert (0 == sizeof (U*), "unsupported pointer type");
32  }
33  template<typename U> const String
34  tokenize (void (*) (U*))
35  { // relay to pointer type tokenizer
36  U *p = 0;
37  return ptokenize<U> (p);
38  }
39  template<typename U> const String
40  tokenize (void (*) (U))
41  { // non-pointer type, not supported
42  return "?";
43  static_assert (sizeof (U) != sizeof (U), "unsupported non-pointer type");
44  }
45 };
46 const String tokenize_gtype (GType t);
47 
48 
49 /* specialize Arg template for standard primitive types */
50 #define BSE__SPECIALIZE(TYPE, vtype, tok, GCast, SCast) \
51 template<> struct Arg<TYPE> { \
52  TYPE get (const Value *v) \
53  { return GCast (v->get_##vtype ()); } \
54  void set (Value *v, TYPE t) \
55  { v->set_##vtype (SCast (t)); } \
56  const String token () \
57  { return tok; } \
58 private: \
59  template<typename T> static inline T no_cast (T t) \
60  { return t; } \
61 }
62 BSE__SPECIALIZE(bool, bool, "b", no_cast, no_cast);
63 // BSE__SPECIALIZE(char, int, "i", no_cast, no_cast);
64 // BSE__SPECIALIZE(signed char, int, "i", no_cast, no_cast);
65 // BSE__SPECIALIZE(unsigned char, int, "i", no_cast, no_cast);
66 // BSE__SPECIALIZE(signed short, int, "i", no_cast, no_cast);
67 // BSE__SPECIALIZE(unsigned short, int, "i", no_cast, no_cast);
68 BSE__SPECIALIZE(signed int, int, "i", no_cast, no_cast);
69 BSE__SPECIALIZE(uint, int, "i", no_cast, no_cast);
70 BSE__SPECIALIZE(signed long, int, "i", no_cast, no_cast);
71 BSE__SPECIALIZE(unsigned long, int, "i", no_cast, no_cast);
72 BSE__SPECIALIZE(signed long long, num, "n", no_cast, no_cast);
73 BSE__SPECIALIZE(unsigned long long, num, "n", no_cast, no_cast);
74 BSE__SPECIALIZE(float, real, "r", no_cast, no_cast);
75 BSE__SPECIALIZE(double, real, "r", no_cast, no_cast);
76 BSE__SPECIALIZE(gpointer, pointer,"*", no_cast, no_cast);
77 BSE__SPECIALIZE(GParamSpec*, pspec, "P", no_cast, no_cast);
78 //BSE__SPECIALIZE(unsigned char*, string, "s", no_cast, no_cast);
79 //BSE__SPECIALIZE(signed char*, string, "s", no_cast, no_cast);
80 BSE__SPECIALIZE(String, string, "s", no_cast, no_cast);
81 //BSE__SPECIALIZE(const unsigned char*, string, "s", no_cast, no_cast);
82 //BSE__SPECIALIZE(const signed char*, string, "s", no_cast, no_cast);
83 //BSE__SPECIALIZE(const char*, string, "s", no_cast, no_cast);
84 BSE__SPECIALIZE(const String, string, "s", no_cast, no_cast);
85 BSE__SPECIALIZE(char*, string, "s", const_cast<char*>, no_cast);
86 BSE__SPECIALIZE(GObject*, object, "O", no_cast, no_cast);
87 BSE__SPECIALIZE(BseObject*, object, "O", reinterpret_cast<BseObject*>, reinterpret_cast<GObject*>);
88 BSE__SPECIALIZE(BseItem*, object, "O", reinterpret_cast<BseItem*>, reinterpret_cast<GObject*>);
89 BSE__SPECIALIZE(BseSource*, object, "O", reinterpret_cast<BseSource*>, reinterpret_cast<GObject*>);
90 #undef BSE__SPECIALIZE
91 
92 } // Bse
93 
94 
95 #endif /* __BSE_CXX_ARG_H__ */
The Bse namespace contains all functions of the synthesis engine.
Definition: bstbseutils.cc:91
Definition: bsecxxvalue.hh:13
STL class.
Definition: bsecxxbase.hh:43
Definition: bseobject.hh:57
Definition: bsesource.hh:82
Definition: bsecxxarg.hh:17
Definition: bseitem.hh:32