🛰️航天仿真算法库 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
31{
32public:
33// @brief 运算函数注册表键类型
34 typedef std::tuple<int, Class*> OpUnaryKey;
35
36 // @brief 运算函数注册表哈希函数
38 std::size_t operator()(const OpUnaryKey& key) const {
39 // 组合哈希值
40 std::size_t h1 = std::hash<int>()(static_cast<int>(std::get<0>(key)));
41 std::size_t h2 = std::hash<const void*>()(std::get<1>(key));
42 // 使用位运算组合哈希值
43 return h1 ^ (h2 << 1);
44 }
45 };
46 typedef std::unordered_map<OpUnaryKey, void*, OpUnaryKeyHash> OpUnaryMap;
47
48public:
49 OpUnaryRegister() = default;
50 ~OpUnaryRegister() = default;
51 void* getFunc(EOpUnaryType op, Class* type)
52 {
53 auto key = OpUnaryKey{static_cast<int>(op), type};
54 auto it = map_.find(key);
55 if(it == map_.end()){
56 return nullptr;
57 }
58 return it->second;
59 }
60 void regFunc(EOpUnaryType op, Class* type, void* func)
61 {
62 map_[OpUnaryKey{static_cast<int>(op), type}] = func;
63 }
64protected:
65 OpUnaryMap map_;
66};
67
68AST_NAMESPACE_END
类元信息
定义 Class.hpp:37
定义 OpUnaryRegister.hpp:31
EOpUnaryType
定义 ScriptAPI.hpp:102
定义 OpUnaryRegister.hpp:37