comparison utilities/json-to-capnp.cpp @ 40:55d69b26d4db

Pull out CountingPluginHandleMapper; consts
author Chris Cannam <c.cannam@qmul.ac.uk>
date Mon, 22 Aug 2016 17:16:44 +0100
parents d678cd00e593
children a98ef4c2616b
comparison
equal deleted inserted replaced
39:183be3bc9d7b 40:55d69b26d4db
3 #include "VampnProto.h" 3 #include "VampnProto.h"
4 4
5 #include <iostream> 5 #include <iostream>
6 #include <sstream> 6 #include <sstream>
7 #include <stdexcept> 7 #include <stdexcept>
8
9 #include "bits/PreservingPluginHandleMapper.h"
8 10
9 using namespace std; 11 using namespace std;
10 using namespace json11; 12 using namespace json11;
11 using namespace vampipe; 13 using namespace vampipe;
12 14
32 if (!j["payload"].is_object()) { 34 if (!j["payload"].is_object()) {
33 throw VampJson::Failure("object expected for payload field"); 35 throw VampJson::Failure("object expected for payload field");
34 } 36 }
35 return j; 37 return j;
36 } 38 }
37
38 class PreservingPluginHandleMapper : public PluginHandleMapper
39 {
40 public:
41 PreservingPluginHandleMapper() : m_handle(0), m_plugin(0) { }
42
43 virtual int32_t pluginToHandle(Vamp::Plugin *p) {
44 if (p == m_plugin) return m_handle;
45 else throw NotFound();
46 }
47
48 virtual Vamp::Plugin *handleToPlugin(int32_t h) {
49 m_handle = h;
50 m_plugin = reinterpret_cast<Vamp::Plugin *>(h);
51 return m_plugin;
52 }
53
54 private:
55 int32_t m_handle;
56 Vamp::Plugin *m_plugin;
57 };
58 39
59 void 40 void
60 handle_input(::capnp::MallocMessageBuilder &message, string input) 41 handle_input(::capnp::MallocMessageBuilder &message, string input)
61 { 42 {
62 string err; 43 string err;