LV2 Toolkit  1.2.0
log.hpp
1 /*
2  log.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 */
20 
21 #ifndef LVTK_LOG_HPP
22 #define LVTK_LOG_HPP
23 
24 #include <stdio.h>
25 #include <lv2/lv2plug.in/ns/ext/log/log.h>
26 
27 namespace lvtk
28 {
29 
36  template<bool Required = true>
37  struct Log
38  {
39  template<class Derived>
40  struct I : Extension<Required>
41  {
43  I() : p_log(NULL) { }
44 
46  static void
48  {
49  hmap[LV2_LOG__log] = &I<Derived>::handle_feature;
50  }
51 
53  static void
54  handle_feature(void* instance, FeatureData data)
55  {
56  Derived* d = reinterpret_cast<Derived*>(instance);
57  I<Derived>* mixin = static_cast<I<Derived>*>(d);
58 
59  mixin->p_log = reinterpret_cast<LV2_Log_Log*>(data);
60  mixin->m_ok = true;
61  }
62 
64  bool
66  {
67  if (LVTK_DEBUG)
68  {
69  std::clog << " [Log] Validation "
70  << (this->m_ok ? "succeeded" : "failed")
71  << "." << std::endl;
72  }
73  return this->m_ok;
74  }
75 
76  protected:
77 
85  int
86  vprintf (LV2_URID type, const char* fmt, va_list ap)
87  {
88  if (p_log != NULL)
89  return p_log->vprintf(p_log->handle, type, fmt, ap);
90  return ::vprintf (fmt, ap);
91  }
92 
100  int
101  printf (LV2_URID type, const char* fmt, ...)
102  {
103  va_list argptr;
104  va_start(argptr, fmt);
105 
106  int res (this->vprintf(type, fmt, argptr));
107  va_end(argptr);
108 
109  return res;
110  }
111 
112  LV2_Log_Log * p_log;
113 
114  };
115  };
116 }
117 
118 #endif /* LVTK_LOG_HPP */
Definition: log.hpp:40
void * FeatureData
Definition: feature.hpp:47
bool check_ok()
Definition: log.hpp:65
static void handle_feature(void *instance, FeatureData data)
Definition: log.hpp:54
int printf(LV2_URID type, const char *fmt,...)
Definition: log.hpp:101
Definition: log.hpp:37
Definition: feature.hpp:34
static void map_feature_handlers(FeatureHandlerMap &hmap)
Definition: log.hpp:47
I()
Definition: log.hpp:43
map< string, FeatureHandler > FeatureHandlerMap
Definition: feature.hpp:57
int vprintf(LV2_URID type, const char *fmt, va_list ap)
Definition: log.hpp:86