LV2 Toolkit  1.2.0
data_access.hpp
1 /*
2  data_access.hpp - support file for writing LV2 plugins in C++
3 
4  Copyright (C) 2012 Michael Fisher <mfisher31@gmail.com>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 01222-1307 USA
19  */
30 #ifndef LVTK_DATA_ACCESS_HPP
31 #define LVTK_DATA_ACCESS_HPP
32 
33 #include <lv2/lv2plug.in/ns/ext/data-access/data-access.h>
34 
35 #include <lvtk/private/types.hpp>
36 
37 namespace lvtk
38 {
39 
46  template<bool Required = true>
47  struct DataAccess
48  {
49  template<class Derived>
50  struct I : Extension<Required>
51  {
52  I() : p_da(NULL) { }
53 
55  static void
56  map_feature_handlers(FeatureHandlerMap& hmap)
57  {
58  hmap[LV2_DATA_ACCESS_URI] = &I<Derived>::handle_feature;
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_da =
69  reinterpret_cast<LV2_Extension_Data_Feature*>(data);
70  mixin->m_ok = (mixin->p_da != NULL);
71  }
72 
73  bool
74  check_ok()
75  {
76  if (!Required)
77  return true;
78 
79  if (LVTK_DEBUG)
80  {
81  std::clog << " [DataAccess] Validation "
82  << (this->m_ok ? "succeeded" : "failed")
83  << "." << std::endl;
84  }
85  return this->m_ok;
86  }
87 
102  const void*
103  data_access(const char *uri)
104  {
105  if (NULL != p_da)
106  return p_da->data_access(uri);
107  return NULL;
108  }
109 
110  protected:
112  LV2_Extension_Data_Feature *p_da;
113  };
114  };
115 
116 } /* namespace lvtk */
117 
118 #endif /* LVTK_DATA_ACCESS_HPP */
Definition: data_access.hpp:50
void * FeatureData
Definition: feature.hpp:47
const void * data_access(const char *uri)
Definition: data_access.hpp:103
Definition: feature.hpp:34
Definition: data_access.hpp:47
map< string, FeatureHandler > FeatureHandlerMap
Definition: feature.hpp:57