🛰️航天仿真算法库 SpaceAST 0.0.1
载入中...
搜索中...
未找到
OpUnaryRegister.hpp
浏览该文件的文档.
1
20
21#pragma once
22
23#include "AstGlobal.h"
24#include "AstScript/ScriptAPI.hpp"
25#include <tuple>
26#include <unordered_map>
27
28AST_NAMESPACE_BEGIN
29
30#ifndef SWIG
32{
33public:
34// @brief 运算函数注册表键类型
35 typedef std::tuple<int, Class*> OpUnaryKey;
36
37 // @brief 运算函数注册表哈希函数
39 std::size_t operator()(const OpUnaryKey& key) const {
40 // 组合哈希值
41 std::size_t h1 = std::hash<int>()(static_cast<int>(std::get<0>(key)));
42 std::size_t h2 = std::hash<const void*>()(std::get<1>(key));
43 // 使用位运算组合哈希值
44 return h1 ^ (h2 << 1);
45 }
46 };
47 typedef std::unordered_map<OpUnaryKey, void*, OpUnaryKeyHash> OpUnaryMap;
48
49public:
50 OpUnaryRegister() = default;
51 ~OpUnaryRegister() = default;
52 void* getFunc(EOpUnaryType op, Class* type)
53 {
54 auto key = OpUnaryKey{static_cast<int>(op), type};
55 auto it = map_.find(key);
56 if(it == map_.end()){
57 return nullptr;
58 }
59 return it->second;
60 }
61 void regFunc(EOpUnaryType op, Class* type, void* func)
62 {
63 map_[OpUnaryKey{static_cast<int>(op), type}] = func;
64 }
65protected:
66 OpUnaryMap map_;
67};
68#endif
69
70AST_NAMESPACE_END
类元信息
定义 Class.hpp:40
定义 OpUnaryRegister.hpp:32
EOpUnaryType
定义 ScriptAPI.hpp:105
定义 OpUnaryRegister.hpp:38