11 #include <boost/uuid/uuid_io.hpp> 16 auto jsonData = nlohmann::json{};
18 jsonData[
"type"] =
"function";
19 jsonData[
"name"] = func.
name();
22 auto& datainputsjson = jsonData[
"data_inputs"];
23 datainputsjson = nlohmann::json::array();
26 datainputsjson.push_back({{in.name, in.type.qualifiedName()}});
30 auto& localsjson = jsonData[
"local_variables"];
31 localsjson = nlohmann::json::object();
33 localsjson[local.name] = local.type.qualifiedName();
36 auto& dataoutputsjson = jsonData[
"data_outputs"];
37 dataoutputsjson = nlohmann::json::array();
40 dataoutputsjson.push_back({{out.name, out.type.qualifiedName()}});
43 auto& execinputsjson = jsonData[
"exec_inputs"];
44 execinputsjson = nlohmann::json::array();
46 for (
auto& in : func.
execInputs()) { execinputsjson.push_back(in); }
48 auto& execoutputsjson = jsonData[
"exec_outputs"];
49 execoutputsjson = nlohmann::json::array();
51 for (
auto& out : func.
execOutputs()) { execoutputsjson.push_back(out); }
54 auto& jsonNodes = jsonData[
"nodes"];
55 jsonNodes = nlohmann::json::object();
56 auto& jsonConnections = jsonData[
"connections"];
57 jsonConnections = nlohmann::json::array();
59 for (
const auto& nodepair : func.
nodes()) {
60 auto& node = nodepair.second;
61 std::string nodeID = boost::uuids::to_string(nodepair.first);
63 nlohmann::json nodeJson = node->type().toJSON();
64 jsonNodes[nodeID] = {{
"type", node->type().qualifiedName()},
65 {
"location", {node->x(), node->y()}},
70 for (
auto conn_id = 0ull; conn_id < node->outputExecConnections.size(); ++conn_id) {
71 auto& conn = node->outputExecConnections[conn_id];
73 if (conn.first !=
nullptr) {
74 jsonConnections.push_back(
76 {
"input", {nodeID, conn_id}},
77 {
"output", {boost::uuids::to_string(conn.first->id()), conn.second}}});
82 for (
auto conn_id = 0ull; conn_id < node->inputDataConnections.size(); ++conn_id) {
84 auto& connpair = node->inputDataConnections[conn_id];
85 if (connpair.first !=
nullptr) {
86 jsonConnections.push_back(
88 {
"input", {boost::uuids::to_string(connpair.first->id()), connpair.second}},
89 {
"output", {nodeID, conn_id}}});
100 auto& depsjson = data[
"dependencies"];
101 depsjson = nlohmann::json::array();
102 for (
const auto& dep : mod.
dependencies()) { depsjson.push_back(dep.generic_string()); }
104 auto& graphsjson = data[
"graphs"];
105 graphsjson = nlohmann::json::array();
108 auto& structsJson = data[
"types"];
109 structsJson = nlohmann::json::object();
110 for (
const auto& str : mod.structs()) { structsJson[str->name()] =
graphStructToJson(*str); }
112 data[
"has_c_support"] = mod.
cEnabled();
118 nlohmann::json ret = nlohmann::json::array();
120 for (
const auto& elem : struc.
types()) {
121 ret.push_back({{elem.name, elem.type.qualifiedName()}});
nlohmann::json graphFunctionToJson(const GraphFunction &func)
Serialize a GraphFunction to json.
Define json serialization functions.
const std::vector< NamedDataType > & dataOutputs() const
Get the function data outputs in the format {type, docstring}.
this is an AST-like representation of a function in a graph It is used for IDE-like behavior...
const std::vector< std::string > & execInputs() const
Get the function exec inputs.
A class holding a compound type defined in a GraphModule.
const std::vector< std::string > & execOutputs() const
Get the function exec outputs.
const std::vector< std::unique_ptr< GraphFunction > > & functions() const
Get functions.
std::string name() const
Get the name of the function.
nlohmann::json graphStructToJson(const GraphStruct &struc)
Serialize a GraphStruct to json.
bool cEnabled() const
Gets if C support is enabled.
std::unordered_map< boost::uuids::uuid, std::unique_ptr< NodeInstance > > & nodes()
Get the nodes in the function Usually called by connectData or connectExec or GraphFunction.
Defines the NodeType class.
nlohmann::json graphModuleToJson(const GraphModule &mod)
Serialize a JsonModule to json.
const std::vector< NamedDataType > & types() const
Get the types the struct contains.
const std::set< boost::filesystem::path > & dependencies() const
Get the dependencies.
Defines the DataType class.
const std::vector< NamedDataType > & localVariables() const
Get the local variables.
Module that holds graph functions.
Defines the GraphModule class.
The namespace where chigraph lives.
const std::vector< NamedDataType > & dataInputs() const
Get the function data inputs in the format {type, docstring}.
Declares the GraphFunction class.
Defines the NodeInstance class and related functions.
const std::string & description() const
Get the description of the function.