LV2 Toolkit  1.1.1
 All Classes Namespaces Functions Typedefs Enumerations Enumerator Groups Pages
instance_access.hpp
1 
26 #ifndef LVTK_LV2_INSTANCE_ACCESS_HPP
27 #define LVTK_LV2_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 
53  /* ================= Mixin API ========================= */
54 
56  static void
57  map_feature_handlers(FeatureHandlerMap& hmap)
58  {
59  hmap[LV2_INSTANCE_ACCESS_URI] =
61  }
62 
64  static void
65  handle_feature(LV2UI_Handle instance, FeatureData data)
66  {
67  Derived* derived = reinterpret_cast<Derived*>(instance);
68  I<Derived>* mixin = static_cast<I<Derived>*>(derived);
69 
70  mixin->p_plugin_instance =
71  reinterpret_cast<LV2_Handle>(data);
72 
73  mixin->m_ok = (mixin->p_plugin_instance != NULL);
74  }
75 
76  bool
77  check_ok()
78  {
79  if (!Required)
80  this->m_ok = true;
81 
82  if (LVTK_DEBUG)
83  {
84  std::clog << " [InstanceAccess] Validation "
85  << (this->m_ok ? "succeeded" : "failed")
86  << "." << std::endl;
87  }
88 
89  return this->m_ok;
90  }
91 
92  protected:
93 
95  LV2_Handle
97  {
98  return p_plugin_instance;
99  }
100 
102  LV2_Handle p_plugin_instance;
103  };
104  };
105 } /* namespace lvtk */
106 
107 #endif /* LVTK_LV2_INSTANCE_ACCESS_HPP */