aboutsummaryrefslogtreecommitdiff
path: root/src/backends/BackendRegistry.cpp
diff options
context:
space:
mode:
authorDavid Beck <david.beck@arm.com>2018-10-09 15:46:08 +0100
committerMatthew Bentham <matthew.bentham@arm.com>2018-10-22 16:57:53 +0100
commit32cbb0c7cd99786191c080f5a619b3dab23b4cd0 (patch)
tree0e7db143cdf3faa6430a1ffa5e948165ff60c045 /src/backends/BackendRegistry.cpp
parent43095f31edf103d71a8e2420b549d21fd349b49e (diff)
downloadarmnn-32cbb0c7cd99786191c080f5a619b3dab23b4cd0.tar.gz
IVGCVSW-1987 : registry for backend creation functions (factories)
Change-Id: I13d2d3dc763e1d05dffddb34472bd4f9e632c776
Diffstat (limited to 'src/backends/BackendRegistry.cpp')
-rw-r--r--src/backends/BackendRegistry.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/backends/BackendRegistry.cpp b/src/backends/BackendRegistry.cpp
new file mode 100644
index 0000000000..68336c45b9
--- /dev/null
+++ b/src/backends/BackendRegistry.cpp
@@ -0,0 +1,45 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "BackendRegistry.hpp"
+#include <armnn/Exceptions.hpp>
+
+namespace armnn
+{
+
+BackendRegistry& BackendRegistry::Instance()
+{
+ static BackendRegistry instance;
+ return instance;
+}
+
+void BackendRegistry::Register(const std::string& name, FactoryFunction factory)
+{
+ if (m_BackendFactories.count(name) > 0)
+ {
+ throw InvalidArgumentException(name + " already registered as backend");
+ }
+
+ m_BackendFactories[name] = factory;
+}
+
+BackendRegistry::FactoryFunction BackendRegistry::GetFactory(const std::string& name) const
+{
+ auto it = m_BackendFactories.find(name);
+ if (it == m_BackendFactories.end())
+ {
+ throw InvalidArgumentException(name + " has no backend factory registered");
+ }
+
+ return it->second;
+}
+
+void BackendRegistry::Swap(BackendRegistry::FactoryStorage& other)
+{
+ BackendRegistry& instance = Instance();
+ std::swap(instance.m_BackendFactories, other);
+}
+
+}