LV2 Toolkit  1.2.0
instance_access.hpp
1 
26 #ifndef LVTK_INSTANCE_ACCESS_HPP
27 #define LVTK_INSTANCE_ACCESS_HPP
28 
29 #include <lv2/lv2plug.in/ns/ext/instance-access/instance-access.h>
30 
31 #include <lvtk/private/types.hpp>
32 
33 namespace lvtk
34 {
35 
41  template<bool Required = true>
43  {
44  template<class Derived>
45  struct I : Extension<Required>
46  {
47 
48  I() :
49  p_plugin_instance(NULL)
50  {
51  }
52 
54  static void
55  map_feature_handlers(FeatureHandlerMap& hmap)
56  {
57  hmap[LV2_INSTANCE_ACCESS_URI] =
59  }
60 
62  static void
63  handle_feature(LV2UI_Handle instance, FeatureData data)
64  {
65  Derived* derived = reinterpret_cast<Derived*>(instance);
66  I<Derived>* mixin = static_cast<I<Derived>*>(derived);
67 
68  mixin->p_plugin_instance = reinterpret_cast<LV2_Handle>(data);
69  mixin->m_ok = (mixin->p_plugin_instance != NULL);
70  }
71 
72  bool
73  check_ok()
74  {
75  if (! Required)
76  this->m_ok = true;
77 
78  if (LVTK_DEBUG)
79  {
80  std::clog << " [InstanceAccess] Validation "
81  << (this->m_ok ? "succeeded" : "failed")
82  << "." << std::endl;
83  }
84 
85  return this->m_ok;
86  }
87 
88  protected:
89 
92  LV2_Handle
94  {
95  return p_plugin_instance;
96  }
97 
98  private:
100  LV2_Handle p_plugin_instance;
101  };
102  };
103 } /* namespace lvtk */
104 
105 #endif /* LVTK_INSTANCE_ACCESS_HPP */
void * FeatureData
Definition: feature.hpp:47
Definition: instance_access.hpp:45
Definition: feature.hpp:34
Definition: instance_access.hpp:42
LV2_Handle get_instance()
Definition: instance_access.hpp:93
map< string, FeatureHandler > FeatureHandlerMap
Definition: feature.hpp:57