Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / samples / common / format_reader / register.h
1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 /**
5  * \brief Register for readers
6  * \file register.h
7  */
8 #pragma once
9
10 #include <format_reader.h>
11 #include <functional>
12 #include <vector>
13 #include <string>
14
15 namespace FormatReader {
16 /**
17  * \class Registry
18  * \brief Create reader from fabric
19  */
20 class Registry {
21 private:
22     typedef std::function<Reader *(const std::string &filename)> CreatorFunction;
23     static std::vector<CreatorFunction> _data;
24 public:
25     /**
26      * \brief Create reader
27      * @param filename - path to input data
28      * @return Reader for input data or nullptr
29      */
30     static Reader *CreateReader(const char *filename);
31
32     /**
33      * \brief Registers reader in fabric
34      * @param f - a creation function
35      */
36     static void RegisterReader(CreatorFunction f);
37 };
38
39 /**
40  * \class Register
41  * \brief Registers reader in fabric
42  */
43 template<typename To>
44 class Register {
45 public:
46     /**
47      * \brief Constructor creates creation function for fabric
48      * @return Register object
49      */
50     Register() {
51         Registry::RegisterReader([](const std::string &filename) -> Reader * {
52             return new To(filename);
53         });
54     }
55 };
56 }  // namespace FormatReader