00001 #ifndef GATE_H
00002 #define GATE_H
00003
00004 #include <memory>
00005 #include <vector>
00006 #include <string>
00007 #include <unordered_map>
00008 #include <QJsonObject>
00009
00010 #include "NodeData.h"
00011
00012 namespace Elve {
00013
00014 class Node;
00015
00016
00017
00018
00019 typedef std::vector<Node*> Nodes;
00020 typedef int Index;
00021 typedef long NodeLevel;
00022 class Graph;
00023 typedef std::shared_ptr<Graph> SharedGraph;
00024
00025
00026 class Node
00027 {
00028 public:
00029 typedef Nodes Children;
00030 typedef Nodes Ancestors;
00031
00032 struct Connexion {
00033 Node* node;
00034 Index from;
00035 Index to;
00036 };
00037
00038 typedef std::vector<Connexion> Fan;
00039
00040 Node(const NodeData& data);
00041 void addChild(Node* child, Index from, Index to);
00042 void addAncestor(Node* anc, Index from, Index to);
00043 const Index& IOIndex() const;
00044 const Ancestors& ancestors() const;
00045 const Children& children() const;
00046 const NodeID& id() const;
00047 const NodeName& name() const;
00048 size_t ancestorCount() const;
00049 size_t childCount() const;
00050 int inputCount() const;
00051 int outputCount() const;
00052 Name inputName(Index i) const;
00053 Name outputName(Index i) const;
00054 const Fan& fanIn() const;
00055 const Fan& fanOut() const;
00056 bool isInput() const;
00057 bool isOutput() const;
00058 const NodeType& type() const;
00059 bool isCluster() const;
00060 const NodeLevel& level() const;
00061 const SharedGraph getClusteredGraph() const;
00062 void setClusteredGraph(SharedGraph graph);
00063 const QJsonObject& properties() const;
00064 QJsonObject json() const;
00065 const NodeData& data() const;
00066
00067 private:
00068 void _addChild(Node* child, Index from, Index to);
00069 void _addAncestor(Node* anc, Index from, Index to);
00070
00071 mutable NodeLevel mLevel;
00072 SharedGraph mGraph;
00073 Ancestors mAncestors;
00074 Children mChildren;
00075 Fan mFanIn;
00076 Fan mFanOut;
00077 const NodeData& mData;
00078 };
00079
00080 }
00081
00082 #endif // GATE_H