My Project 1.0.5
lv2types.hpp
1/****************************************************************************
2
3 lv2types.hpp - support file for writing LV2 plugins in C++
4
5 Copyright (C) 2006-2008 Lars Luthman <lars.luthman@gmail.com>
6
7 The first version of the URIMap class was written by Dave Robillard.
8 It has since been modified.
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 01222-1307 USA
23
24****************************************************************************/
25
26#ifndef LV2TYPES_HPP
27#define LV2TYPES_HPP
28
29#include <map>
30#include <string>
31
32
33namespace LV2 {
34
36 typedef LV2_Feature Feature;
37
39 typedef void(*FeatureHandler)(void*, void*);
40
42 typedef std::map<std::string, FeatureHandler> FeatureHandlerMap;
43
44
45 struct Empty {
46
47 };
48
49
53 struct End {
54 typedef Empty C;
55 };
56
57
66 template <class A,
67 class E1 = End,
68 class E2 = End,
69 class E3 = End,
70 class E4 = End,
71 class E5 = End,
72 class E6 = End,
73 class E7 = End,
74 class E8 = End,
75 class E9 = End>
76 struct MixinTree
77 : E1::template I<A>, MixinTree<A, E2, E3, E4, E5, E6, E7, E8, E9> {
78
79 typedef MixinTree<A, E2, E3, E4, E5, E6, E7, E8, E9> Parent;
80
83 static void map_feature_handlers(FeatureHandlerMap& hmap) {
84 E1::template I<A>::map_feature_handlers(hmap);
85 Parent::map_feature_handlers(hmap);
86 }
87
89 bool check_ok() {
90 return E1::template I<A>::check_ok() && Parent::check_ok();
91 }
92
94 static const void* extension_data(const char* uri) {
95 const void* result = E1::template I<A>::extension_data(uri);
96 if (result)
97 return result;
98 return Parent::extension_data(uri);
99 }
100
101 };
102
103
107 template <class A>
108 struct MixinTree<A, End, End, End, End, End, End, End, End, End> {
109 static void map_feature_handlers(FeatureHandlerMap& hmap) { }
110 bool check_ok() const { return true; }
111 static const void* extension_data(const char* uri) { return 0; }
112 };
113
114
119 template <bool Required>
120 struct Extension {
121
124 Extension() : m_ok(!Required) { }
125
129 static void map_feature_handlers(FeatureHandlerMap& hmap) { }
130
134 bool check_ok() { return m_ok; }
135
140 static const void* extension_data(const char* uri) { return 0; }
141
142 protected:
143
144 bool m_ok;
145
146 };
147
148
156 template <bool Required = true>
157 struct URIMap {
158
163 template <class Derived> struct I : Extension<Required> {
164
166 I() : m_callback_data(0), m_func(0) { }
167
169 static void map_feature_handlers(FeatureHandlerMap& hmap) {
170 hmap[LV2_URI_MAP_URI] = &I<Derived>::handle_feature;
171 }
172
174 static void handle_feature(void* instance, void* data) {
175 Derived* d = reinterpret_cast<Derived*>(instance);
176 I<Derived>* fe = static_cast<I<Derived>*>(d);
177 LV2_URI_Map_Feature* umf = reinterpret_cast<LV2_URI_Map_Feature*>(data);
178 fe->m_callback_data = umf->callback_data;
179 fe->m_func = umf->uri_to_id;
180 fe->m_ok = (fe->m_func != 0);
181 }
182
183 protected:
184
192 uint32_t uri_to_id(const char* map, const char* uri) const {
193 return m_func(m_callback_data, map, uri);
194 }
195
196 LV2_URI_Map_Callback_Data m_callback_data;
197 uint32_t (*m_func)(LV2_URI_Map_Callback_Data, const char*, const char*);
198
199 };
200
201 };
202
203
204
205}
206
207
208#endif
Definition lv2types.hpp:163
uint32_t uri_to_id(const char *map, const char *uri) const
Definition lv2types.hpp:192
Definition lv2types.hpp:157