From 32cbb0c7cd99786191c080f5a619b3dab23b4cd0 Mon Sep 17 00:00:00 2001 From: David Beck Date: Tue, 9 Oct 2018 15:46:08 +0100 Subject: IVGCVSW-1987 : registry for backend creation functions (factories) Change-Id: I13d2d3dc763e1d05dffddb34472bd4f9e632c776 --- src/backends/BackendRegistry.hpp | 52 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/backends/BackendRegistry.hpp (limited to 'src/backends/BackendRegistry.hpp') diff --git a/src/backends/BackendRegistry.hpp b/src/backends/BackendRegistry.hpp new file mode 100644 index 0000000000..ff01d21715 --- /dev/null +++ b/src/backends/BackendRegistry.hpp @@ -0,0 +1,52 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// +#pragma once + +#include +#include +#include +#include +#include + +namespace armnn +{ + +class IBackend; + +class BackendRegistry +{ +public: + using FactoryFunction = std::function; + + static BackendRegistry& Instance(); + void Register(const std::string& name, FactoryFunction factory); + FactoryFunction GetFactory(const std::string& name) const; + + struct Helper + { + Helper(const std::string& name, FactoryFunction factory) + { + BackendRegistry::Instance().Register(name, factory); + } + }; + + size_t Size() const { return m_BackendFactories.size(); } + +protected: + using FactoryStorage = std::unordered_map; + + // For testing only + static void Swap(FactoryStorage& other); + BackendRegistry() {} + ~BackendRegistry() {} + +private: + BackendRegistry(const BackendRegistry&) = delete; + BackendRegistry& operator=(const BackendRegistry&) = delete; + + FactoryStorage m_BackendFactories; +}; + +} // namespace armnn -- cgit v1.2.1