00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef LV2TYPES_HPP
00027 #define LV2TYPES_HPP
00028
00029 #include <map>
00030 #include <string>
00031
00032
00033 namespace LV2 {
00034
00036 typedef LV2_Feature Feature;
00037
00039 typedef void(*FeatureHandler)(void*, void*);
00040
00042 typedef std::map<std::string, FeatureHandler> FeatureHandlerMap;
00043
00044
00045 struct Empty {
00046
00047 };
00048
00049
00053 struct End {
00054 typedef Empty C;
00055 };
00056
00057
00066 template <class A,
00067 class E1 = End,
00068 class E2 = End,
00069 class E3 = End,
00070 class E4 = End,
00071 class E5 = End,
00072 class E6 = End,
00073 class E7 = End,
00074 class E8 = End,
00075 class E9 = End>
00076 struct MixinTree
00077 : E1::template I<A>, MixinTree<A, E2, E3, E4, E5, E6, E7, E8, E9> {
00078
00079 typedef MixinTree<A, E2, E3, E4, E5, E6, E7, E8, E9> Parent;
00080
00083 static void map_feature_handlers(FeatureHandlerMap& hmap) {
00084 E1::template I<A>::map_feature_handlers(hmap);
00085 Parent::map_feature_handlers(hmap);
00086 }
00087
00089 bool check_ok() {
00090 return E1::template I<A>::check_ok() && Parent::check_ok();
00091 }
00092
00094 static const void* extension_data(const char* uri) {
00095 const void* result = E1::template I<A>::extension_data(uri);
00096 if (result)
00097 return result;
00098 return Parent::extension_data(uri);
00099 }
00100
00101 };
00102
00103
00107 template <class A>
00108 struct MixinTree<A, End, End, End, End, End, End, End, End, End> {
00109 static void map_feature_handlers(FeatureHandlerMap& hmap) { }
00110 bool check_ok() const { return true; }
00111 static const void* extension_data(const char* uri) { return 0; }
00112 };
00113
00114
00119 template <bool Required>
00120 struct Extension {
00121
00124 Extension() : m_ok(!Required) { }
00125
00129 static void map_feature_handlers(FeatureHandlerMap& hmap) { }
00130
00134 bool check_ok() { return m_ok; }
00135
00140 static const void* extension_data(const char* uri) { return 0; }
00141
00142 protected:
00143
00144 bool m_ok;
00145
00146 };
00147
00148
00156 template <bool Required = true>
00157 struct URIMap {
00158
00163 template <class Derived> struct I : Extension<Required> {
00164
00166 I() : m_callback_data(0), m_func(0) { }
00167
00169 static void map_feature_handlers(FeatureHandlerMap& hmap) {
00170 hmap[LV2_URI_MAP_URI] = &I<Derived>::handle_feature;
00171 }
00172
00174 static void handle_feature(void* instance, void* data) {
00175 Derived* d = reinterpret_cast<Derived*>(instance);
00176 I<Derived>* fe = static_cast<I<Derived>*>(d);
00177 LV2_URI_Map_Feature* umf = reinterpret_cast<LV2_URI_Map_Feature*>(data);
00178 fe->m_callback_data = umf->callback_data;
00179 fe->m_func = umf->uri_to_id;
00180 fe->m_ok = (fe->m_func != 0);
00181 }
00182
00183 protected:
00184
00192 uint32_t uri_to_id(const char* map, const char* uri) const {
00193 return m_func(m_callback_data, map, uri);
00194 }
00195
00196 LV2_URI_Map_Callback_Data m_callback_data;
00197 uint32_t (*m_func)(LV2_URI_Map_Callback_Data, const char*, const char*);
00198
00199 };
00200
00201 };
00202
00203
00204
00205 }
00206
00207
00208 #endif