1 #pragma once 2 3 #include "Value.h" 4 5 namespace actions { 6 namespace expression { 7 8 using FunctionImplementation = std::function<Value(const SCP_vector<Value>& parameters)>; 9 10 struct FunctionDefinition { 11 SCP_string name; 12 13 SCP_vector<ValueType> parameterTypes; 14 15 ValueType returnType; 16 17 FunctionImplementation implementation; 18 }; 19 20 class FunctionManager { 21 public: 22 // This type is supposed to be global so it may not be copied 23 FunctionManager(const FunctionManager&) = delete; 24 FunctionManager& operator=(const FunctionManager&) = delete; 25 26 FunctionManager(FunctionManager&&) noexcept = default; 27 FunctionManager& operator=(FunctionManager&&) noexcept = default; 28 29 void addOperator(const SCP_string& name, 30 std::initializer_list<ValueType> parameterTypes, 31 ValueType returnType, 32 FunctionImplementation implementation); 33 34 const FunctionDefinition* findOperator(const SCP_string& name, const SCP_vector<ValueType>& parameterTypes) const; 35 36 static const FunctionManager& instance(); 37 38 private: 39 FunctionManager(); 40 41 SCP_unordered_map<SCP_string, SCP_vector<FunctionDefinition>> m_operators; 42 }; 43 44 } // namespace expression 45 } // namespace actions 46