• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef USCRIPT_INSTRUCTION_HELPER_H
17 #define USCRIPT_INSTRUCTION_HELPER_H
18 
19 #include <unordered_map>
20 #include "script_instruction.h"
21 #include "script_manager_impl.h"
22 #include "script_utils.h"
23 
24 namespace Uscript {
25 class ScriptInstructionHelper {
26 public:
ScriptInstructionHelper(ScriptManagerImpl * impl)27     explicit ScriptInstructionHelper(ScriptManagerImpl *impl) : scriptManager_(impl) {}
28 
29     ~ScriptInstructionHelper();
30 
31     int32_t RegisterInstructions() const;
32 
33     bool IsReservedInstruction(const std::string &scriptName) const;
34 
35     int32_t AddScript(const std::string &scriptName, int32_t priority) const;
36 
37     int32_t AddInstruction(const std::string &instrName, const UScriptInstructionPtr instr);
38 
39     int32_t RegisterUserInstruction(const std::string &libName, const std::string &instrName);
40 
41     int32_t RegisterUserInstruction(const std::string &instrName, Uscript::UScriptInstructionFactory *factory);
42 
43     static ScriptInstructionHelper* GetBasicInstructionHelper(ScriptManagerImpl *impl = nullptr);
44 
45     static void ReleaseBasicInstructionHelper();
46 private:
47     int32_t RegisterAddInstruction(const Uscript::UScriptInstructionFactoryPtr factory,
48     	const std::string &instrName);
49 
50     void* instrLib_ = nullptr;
51     std::string userInstrLibName_ {};
52     ScriptManagerImpl* scriptManager_ {};
53 };
54 } // namespace Uscript
55 #endif // USCRIPT_INSTRUCTION_HELPER_H
56