Mercurial > hg > piper-cpp
comparison bits/PreservingPluginOutputIdMapper.h @ 60:8a4bcb3dc3a6
Replace exceptions throughout the JSON-handling and adapter code with string-arg error handling. No longer need exception handling enabled in Emscripten (with its consequent runtime overhead - though we still need to check whether this error handling regime is actually faster).
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Tue, 20 Sep 2016 16:35:47 +0100 |
parents | f4244a2d55ac |
children |
comparison
equal
deleted
inserted
replaced
59:77833938f0f8 | 60:8a4bcb3dc3a6 |
---|---|
47 class PreservingPluginOutputIdMapper : public PluginOutputIdMapper | 47 class PreservingPluginOutputIdMapper : public PluginOutputIdMapper |
48 { | 48 { |
49 public: | 49 public: |
50 PreservingPluginOutputIdMapper() { } | 50 PreservingPluginOutputIdMapper() { } |
51 | 51 |
52 virtual int idToIndex(std::string outputId) const { | 52 virtual int idToIndex(std::string outputId) const noexcept { |
53 int n = int(m_ids.size()); | 53 int n = int(m_ids.size()); |
54 int i = 0; | 54 int i = 0; |
55 while (i < n) { | 55 while (i < n) { |
56 if (outputId == m_ids[i]) { | 56 if (outputId == m_ids[i]) { |
57 return i; | 57 return i; |
60 } | 60 } |
61 m_ids.push_back(outputId); | 61 m_ids.push_back(outputId); |
62 return i; | 62 return i; |
63 } | 63 } |
64 | 64 |
65 virtual std::string indexToId(int index) const { | 65 virtual std::string indexToId(int index) const noexcept { |
66 //!!! todo: this should in fact throw, or otherwise return an error | 66 if (index < 0 || size_t(index) >= m_ids.size()) return ""; |
67 return m_ids[index]; | 67 return m_ids[index]; |
68 } | 68 } |
69 | 69 |
70 private: | 70 private: |
71 mutable std::vector<std::string> m_ids; | 71 mutable std::vector<std::string> m_ids; |