LV2 Toolkit  1.2.0
urid.hpp
1 /*
2  urid.hpp - support file for writing LV2 plugins in C++
3  Copyright (C) 2012 Michael Fisher <mfisher31@gmail.com>
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 01222-1307 USA
18 */
19 
20 #ifndef LVTK_URID_HPP
21 #define LVTK_URID_HPP
22 
23 #include <lv2/lv2plug.in/ns/ext/urid/urid.h>
24 
25 namespace lvtk
26 {
28  typedef uint32_t (*MapFunc)(const char* symbol);
29 
31  typedef const char* (*UnmapFunc)(uint32_t id);
32 
39  template<bool Required = true>
40  struct URID
41  {
42  template<class Derived>
43  struct I : Extension<Required>
44  {
45  I() : p_map(0), p_unmap(0) { }
46 
48  static void
49  map_feature_handlers (FeatureHandlerMap& hmap)
50  {
51  hmap[LV2_URID__map] = &I<Derived>::handle_map_feature;
52  hmap[LV2_URID__unmap] = &I<Derived>::handle_unmap_feature;
53  }
54 
56  static void
57  handle_map_feature (void* instance, void* data)
58  {
59  Derived* d = reinterpret_cast<Derived*>(instance);
60  I<Derived>* mixin = static_cast<I<Derived>*>(d);
61 
62  mixin->p_map = reinterpret_cast<LV2_URID_Map*>(data);
63  mixin->m_ok = true;
64  }
65 
67  static void
68  handle_unmap_feature (void* instance, void* data)
69  {
70  Derived* d = reinterpret_cast<Derived*> (instance);
71  I<Derived>* mixin = static_cast<I<Derived>*>(d);
72 
73  mixin->p_unmap = reinterpret_cast<LV2_URID_Unmap*>(data);
74  mixin->m_ok = true;
75  }
76 
77  bool
78  check_ok()
79  {
80  if (LVTK_DEBUG)
81  {
82  std::clog << " [URID] Validation "
83  << (this->m_ok ? "succeeded" : "failed")
84  << "." << std::endl;
85  }
86  return this->m_ok;
87  }
88 
102  const char*
103  unmap (LV2_URID urid)
104  {
105  if (p_unmap != NULL)
106  return p_unmap->unmap(p_unmap->handle, urid);
107  return "";
108  }
109 
129  LV2_URID
130  map (const char* uri)
131  {
132  if (p_map != NULL)
133  return p_map->map(p_map->handle, uri);
134  return 0;
135  }
136 
138  LV2_URID_Map* get_urid_map() const { return p_map; }
139 
141  LV2_URID_Unmap* get_urid_unmap() const { return p_unmap; }
142 
143  protected:
144 
145  LV2_URID_Map *p_map;
146  LV2_URID_Unmap *p_unmap;
147 
148  };
149  };
150 }
151 
152 #endif /* LVTK_URID_HPP */
const char * unmap(LV2_URID urid)
Definition: urid.hpp:103
LV2_URID_Unmap * get_urid_unmap() const
Definition: urid.hpp:141
Definition: urid.hpp:40
Definition: feature.hpp:34
LV2_URID map(const char *uri)
Definition: urid.hpp:130
LV2_URID_Map * get_urid_map() const
Definition: urid.hpp:138
Definition: urid.hpp:43
uint32_t(* MapFunc)(const char *symbol)
Definition: urid.hpp:28
map< string, FeatureHandler > FeatureHandlerMap
Definition: feature.hpp:57