• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2021 Huawei Technologies Co., Ltd
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef MINDSPORE_LITE_INCLUDE_REGISTRY_MODEL_PARSER_REGISTRY_H_
18 #define MINDSPORE_LITE_INCLUDE_REGISTRY_MODEL_PARSER_REGISTRY_H_
19 
20 #include <memory>
21 #include "include/registry/converter_context.h"
22 
23 using mindspore::converter::FmkType;
24 namespace mindspore {
25 namespace converter {
26 class ModelParser;
27 }  // namespace converter
28 namespace registry {
29 /// \brief ModelParserCreator defined function pointer to get a ModelParser class.
30 typedef converter::ModelParser *(*ModelParserCreator)();
31 
32 /// \brief ModelParserRegistry defined registration and storage of ModelParser.
33 class MS_API ModelParserRegistry {
34  public:
35   /// \brief Constructor of ModelParserRegistry.
36   ///
37   /// \param[in] fmk Define identification of a certain framework.
38   /// \param[in] creator Define function pointer of creating ModelParser.
39   ModelParserRegistry(FmkType fmk, ModelParserCreator creator);
40 
41   /// \brief Destructor of ModelParserRegistry.
42   ~ModelParserRegistry() = default;
43 
44   /// \brief Static Method to get a model parser.
45   ///
46   /// \param[in] fmk Define identification of a certain framework.
47   ///
48   /// \return Pointer of ModelParser.
49   static converter::ModelParser *GetModelParser(FmkType fmk);
50 };
51 
52 /// \brief Defined registering macro to register ModelParser, which called by user directly.
53 ///
54 /// \param[in] fmk Define identification of a certain framework.
55 /// \param[in] parserCreator Define function pointer of creating ModelParser.
56 #define REG_MODEL_PARSER(fmk, parserCreator) \
57   static mindspore::registry::ModelParserRegistry g_##type##fmk##ModelParserReg(fmk, parserCreator);
58 }  // namespace registry
59 }  // namespace mindspore
60 
61 #endif  // MINDSPORE_LITE_INCLUDE_REGISTRY_MODEL_PARSER_REGISTRY_H_
62