LV2 Toolkit  1.2.0
urimap.hpp
1 
36 #ifndef LVTK_URIMAP_HPP
37 #define LVTK_URIMAP_HPP
38 
39 #include <lv2/lv2plug.in/ns/ext/uri-map/uri-map.h>
40 #include <lvtk/private/types.hpp>
41 
42 #warning "this header uses the deprecated lv2 extension uri-map. \
43  please use URID instead."
44 
45 namespace lvtk
46 {
47 
55  template<bool Required = true>
56  struct URIMap
57  {
58  template<class Derived>
59  struct I : Extension<Required>
60  {
61 
62  I() : m_callback_data(0), m_func(0)
63  {
64  }
65 
67  static void
69  {
70  hmap[LV2_URI_MAP_URI] = &I<Derived>::handle_feature;
71  }
72 
74  static void
75  handle_feature(void* instance, void* data)
76  {
77  Derived* d = reinterpret_cast<Derived*>(instance);
78  I<Derived>* fe = static_cast<I<Derived>*>(d);
79  LV2_URI_Map_Feature* umf =
80  reinterpret_cast<LV2_URI_Map_Feature*>(data);
81  fe->m_callback_data = umf->callback_data;
82  fe->m_func = umf->uri_to_id;
83  fe->m_ok = (fe->m_func != 0);
84  }
85 
87  bool
89  {
90  if (LVTK_DEBUG)
91  {
92  std::clog << " [LV2::URIMap] Validation "
93  << (this->m_ok ? "succeeded" : "failed")
94  << "." << std::endl;
95  }
96 
97  return this->m_ok;
98  }
99 
100  protected:
101 
109  uint32_t
110  uri_to_id(const char* map, const char* uri) const
111  {
112  if (LVTK_DEBUG)
113  {
114  uint32_t result = m_func(m_callback_data, map, uri);
115  std::clog << "[LV2::URIMap] uri_to_id(\"" << uri
116  << "\") -> " << result << std::endl;
117  return result;
118  }
119  return m_func(m_callback_data, map, uri);
120  }
121 
122  LV2_URI_Map_Callback_Data m_callback_data;
123  uint32_t (*m_func)(LV2_URI_Map_Callback_Data, const char*, const char*);
124 
125  };
126  };
127 } /* namespace lvtk */
128 
129 #endif /* LVTK_URIMAP_HPP */
Definition: urimap.hpp:59
static void handle_feature(void *instance, void *data)
Definition: urimap.hpp:75
bool check_ok()
Definition: urimap.hpp:88
Definition: feature.hpp:34
Definition: urimap.hpp:56
uint32_t uri_to_id(const char *map, const char *uri) const
Definition: urimap.hpp:110
static void map_feature_handlers(FeatureHandlerMap &hmap)
Definition: urimap.hpp:68
map< string, FeatureHandler > FeatureHandlerMap
Definition: feature.hpp:57