annotate bits/PreservingPluginOutputIdMapper.h @ 72:16acd7d24b1a

Ensure id is passed through in adapter (still pending for server/converter)
author Chris Cannam <c.cannam@qmul.ac.uk>
date Fri, 07 Oct 2016 16:43:18 +0100
parents 8a4bcb3dc3a6
children
rev   line source
c@51 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
c@51 2
c@51 3 /*
c@51 4 Vampipe
c@51 5
c@51 6 Centre for Digital Music, Queen Mary, University of London.
c@51 7 Copyright 2006-2016 Chris Cannam and QMUL.
c@51 8
c@51 9 Permission is hereby granted, free of charge, to any person
c@51 10 obtaining a copy of this software and associated documentation
c@51 11 files (the "Software"), to deal in the Software without
c@51 12 restriction, including without limitation the rights to use, copy,
c@51 13 modify, merge, publish, distribute, sublicense, and/or sell copies
c@51 14 of the Software, and to permit persons to whom the Software is
c@51 15 furnished to do so, subject to the following conditions:
c@51 16
c@51 17 The above copyright notice and this permission notice shall be
c@51 18 included in all copies or substantial portions of the Software.
c@51 19
c@51 20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
c@51 21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
c@51 22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
c@51 23 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
c@51 24 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
c@51 25 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
c@51 26 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
c@51 27
c@51 28 Except as contained in this notice, the names of the Centre for
c@51 29 Digital Music; Queen Mary, University of London; and Chris Cannam
c@51 30 shall not be used in advertising or otherwise to promote the sale,
c@51 31 use or other dealings in this Software without prior written
c@51 32 authorization.
c@51 33 */
c@51 34
c@51 35 #ifndef VAMPIPE_PRESERVING_PLUGIN_OUTPUT_ID_MAPPER_H
c@51 36 #define VAMPIPE_PRESERVING_PLUGIN_OUTPUT_ID_MAPPER_H
c@51 37
c@51 38 #include "PluginOutputIdMapper.h"
c@51 39
c@51 40 #include <iostream>
c@51 41
c@51 42 namespace vampipe {
c@51 43
c@51 44 //!!! document -- this is a passthrough thing that invents its
c@51 45 //!!! numerical ids, they have no correspondence with any real plugin
c@51 46
c@51 47 class PreservingPluginOutputIdMapper : public PluginOutputIdMapper
c@51 48 {
c@51 49 public:
c@51 50 PreservingPluginOutputIdMapper() { }
c@51 51
c@60 52 virtual int idToIndex(std::string outputId) const noexcept {
c@51 53 int n = int(m_ids.size());
c@51 54 int i = 0;
c@51 55 while (i < n) {
c@51 56 if (outputId == m_ids[i]) {
c@51 57 return i;
c@51 58 }
c@51 59 ++i;
c@51 60 }
c@51 61 m_ids.push_back(outputId);
c@51 62 return i;
c@51 63 }
c@51 64
c@60 65 virtual std::string indexToId(int index) const noexcept {
c@60 66 if (index < 0 || size_t(index) >= m_ids.size()) return "";
c@51 67 return m_ids[index];
c@51 68 }
c@51 69
c@51 70 private:
c@51 71 mutable std::vector<std::string> m_ids;
c@51 72 };
c@51 73
c@51 74 }
c@51 75
c@51 76 #endif