annotate vamp-support/PreservingPluginOutputIdMapper.h @ 296:50a0b4fea7f1 tip master

Merge pull request #8 from michel-slm/gcc15 Include headers needed to compile with GCC 15's -std=gnu23 default
author Chris Cannam <cannam@all-day-breakfast.com>
date Mon, 27 Jan 2025 08:53:58 +0000
parents 4b581a498981
children
rev   line source
c@75 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
c@75 2
c@75 3 /*
c@75 4 Piper C++
c@75 5
c@75 6 Centre for Digital Music, Queen Mary, University of London.
c@75 7 Copyright 2006-2016 Chris Cannam and QMUL.
c@75 8
c@75 9 Permission is hereby granted, free of charge, to any person
c@75 10 obtaining a copy of this software and associated documentation
c@75 11 files (the "Software"), to deal in the Software without
c@75 12 restriction, including without limitation the rights to use, copy,
c@75 13 modify, merge, publish, distribute, sublicense, and/or sell copies
c@75 14 of the Software, and to permit persons to whom the Software is
c@75 15 furnished to do so, subject to the following conditions:
c@75 16
c@75 17 The above copyright notice and this permission notice shall be
c@75 18 included in all copies or substantial portions of the Software.
c@75 19
c@75 20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
c@75 21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
c@75 22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
c@75 23 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
c@75 24 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
c@75 25 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
c@75 26 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
c@75 27
c@75 28 Except as contained in this notice, the names of the Centre for
c@75 29 Digital Music; Queen Mary, University of London; and Chris Cannam
c@75 30 shall not be used in advertising or otherwise to promote the sale,
c@75 31 use or other dealings in this Software without prior written
c@75 32 authorization.
c@75 33 */
c@75 34
c@75 35 #ifndef PIPER_PRESERVING_PLUGIN_OUTPUT_ID_MAPPER_H
c@75 36 #define PIPER_PRESERVING_PLUGIN_OUTPUT_ID_MAPPER_H
c@75 37
c@75 38 #include "PluginOutputIdMapper.h"
c@75 39
c@75 40 #include <iostream>
c@75 41
c@97 42 namespace piper_vamp {
c@75 43
cannam@265 44 /**
cannam@265 45 * A PluginOutputIdMapper that knows nothing about actual plugin IDs,
cannam@265 46 * but that accepts any string as an argument to idToIndex, returns an
cannam@265 47 * entirely invented index that is consistent for that string, and
cannam@265 48 * maps back to the same string through indexToId.
cannam@265 49 */
c@75 50 class PreservingPluginOutputIdMapper : public PluginOutputIdMapper
c@75 51 {
c@75 52 public:
c@75 53 PreservingPluginOutputIdMapper() { }
c@75 54
cannam@280 55 int idToIndex(std::string outputId) const noexcept override {
c@75 56 int n = int(m_ids.size());
c@75 57 int i = 0;
c@75 58 while (i < n) {
c@75 59 if (outputId == m_ids[i]) {
c@75 60 return i;
c@75 61 }
c@75 62 ++i;
c@75 63 }
c@75 64 m_ids.push_back(outputId);
c@75 65 return i;
c@75 66 }
c@75 67
cannam@280 68 std::string indexToId(int index) const noexcept override {
c@75 69 if (index < 0 || size_t(index) >= m_ids.size()) return "";
c@75 70 return m_ids[index];
c@75 71 }
c@75 72
c@75 73 private:
c@75 74 mutable std::vector<std::string> m_ids;
c@75 75 };
c@75 76
c@75 77 }
c@75 78
c@75 79 #endif