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/lite_utils.h" 22 #include "include/registry/converter_context.h" 23 24 using mindspore::converter::FmkType; 25 namespace mindspore { 26 namespace converter { 27 class ModelParser; 28 } // namespace converter 29 namespace registry { 30 /// \brief ModelParserCreator defined function pointer to get a ModelParser class. 31 typedef converter::ModelParser *(*ModelParserCreator)(); 32 33 /// \brief ModelParserRegistry defined registration and storage of ModelParser. 34 class MS_API ModelParserRegistry { 35 public: 36 /// \brief Constructor of ModelParserRegistry. 37 /// 38 /// \param[in] fmk Define identification of a certain framework. 39 /// \param[in] creator Define function pointer of creating ModelParser. 40 ModelParserRegistry(FmkType fmk, ModelParserCreator creator); 41 42 /// \brief Destructor of ModelParserRegistry. 43 ~ModelParserRegistry() = default; 44 45 /// \brief Static Method to get a model parser. 46 /// 47 /// \param[in] fmk Define identification of a certain framework. 48 /// 49 /// \return Pointer of ModelParser. 50 static converter::ModelParser *GetModelParser(FmkType fmk); 51 }; 52 53 /// \brief Defined registering macro to register ModelParser, which called by user directly. 54 /// 55 /// \param[in] fmk Define identification of a certain framework. 56 /// \param[in] parserCreator Define function pointer of creating ModelParser. 57 #define REG_MODEL_PARSER(fmk, parserCreator) \ 58 static mindspore::registry::ModelParserRegistry g_##type##fmk##ModelParserReg(fmk, parserCreator); 59 } // namespace registry 60 } // namespace mindspore 61 62 #endif // MINDSPORE_LITE_INCLUDE_REGISTRY_MODEL_PARSER_REGISTRY_H 63