#include <iostream>
#include <string>
#include <unordered_map>
#include <any>
#include <tuple>
struct FunParam {
// This will be a custom identifier (string for now) "int", "string", etc...
std::string type;
// Default value for that parameter
std::any default_value;
};
struct FunDeclaration {
// Function input params
std::unordered_map<std::string, FunParam> ins;
// Function output params
std::unordered_map<std::string, FunParam> outs;
};
using FunctionsMap = std::unordered_map<std::string, FunDeclaration>;
void print(FunctionsMap &fmap) {
auto printParam = [](FunParam& p) {
if (p.type == "int") {
std::cout << "type: " << p.type << " default_value: " << std::any_cast<int>(p.default_value);
} else if (p.type == "double") {
std::cout << "type: " << p.type << " default_value: " << std::any_cast<double>(p.default_value);
} else if (p.type == "float") {
std::cout << "type: " << p.type << " default_value: " << std::any_cast<float>(p.default_value);
} else if (p.type == "std::string") {
std::cout << "type: " << p.type << " default_value: " << std::any_cast<std::string>(p.default_value);
}
};
for (auto& f : fmap) {
std::cout << "Fun: " << f.first << std::endl;
for (auto& in: f.second.ins) {
std::cout << "\t[in] name: " << in.first << " ";
printParam(in.second);
std::cout << std::endl;
}
for (auto& in : f.second.outs) {
std::cout << "\t[out] name: " << in.first << " ";
printParam(in.second);
std::cout << std::endl;
}
}
}
// Just an example function to work with, multiple inputs (default values), and multiple outputs
std::tuple<double, float> foo(int a = 10, std::string b = "HelloWorld") {
return { a * 10.0, b.size() };
}
int main() {
FunctionsMap gFuns;
gFuns["foo"].ins =
{
{"a", {"int", std::any(int(10))} },
{"b", {"std::string", std::any(std::string("HelloWorld"))} }
};
gFuns["foo"].outs = {
{"out0", {"double", std::any(double())} },
{"out1", {"float", std::any(float())} }
};
print(gFuns);
return 1;
}