22 #ifndef GRAPHS_GRAPHWRITER_H
23 #define GRAPHS_GRAPHWRITER_H
31 #include <type_traits>
47 namespace GraphProgram
61 template<
typename GraphType>
74 static_assert(std::is_pointer<NodeRef>::value,
75 "FIXME: Currently GraphWriter requires the NodeRef type to be "
76 "a pointer.\nThe pointer usage should be moved to "
77 "DOTGraphTraits, and removed from GraphWriter itself.");
85 bool hasEdgeSourceLabels =
false;
87 for (
unsigned i = 0; EI != EE && i != 64; ++EI, ++i)
94 hasEdgeSourceLabels =
true;
102 if (EI != EE && hasEdgeSourceLabels)
103 O2 <<
"|<s64>truncated...";
105 return hasEdgeSourceLabels;
135 else if (!GraphName.empty())
138 O <<
"digraph unnamed {\n";
141 O <<
"\trankdir=\"BT\";\n";
145 else if (!GraphName.empty())
160 for (
const auto Node : nodes<GraphType>(
G))
174 O <<
"\tNode" <<
static_cast<const void*
>(Node) <<
" [shape=record,";
175 if (!NodeAttributes.empty())
O << NodeAttributes <<
",";
188 if (!NodeDesc.empty())
193 std::stringstream EdgeSourceLabels(edgeSourceLabels);
196 if (hasEdgeSourceLabels)
200 O <<
"{" << EdgeSourceLabels.str() <<
"}";
215 if (!NodeDesc.empty())
224 for (; i != e && i != 64; ++i)
227 O <<
"<d" << i <<
">"
232 O <<
"|<d64>truncated...";
241 for (
unsigned i = 0; EI != EE && i != 64; ++EI, ++i)
244 for (; EI != EE; ++EI)
260 (unsigned)std::distance(GTraits::child_begin(TargetNode), TargetIt);
261 DestPort =
static_cast<int>(Offset);
267 emitEdge(
static_cast<const void*
>(Node), edgeidx,
268 static_cast<const void*
>(TargetNode), DestPort,
276 const std::vector<std::string> *EdgeSourceLabels =
nullptr)
278 O <<
"\tNode" << ID <<
"[ ";
282 if (NumEdgeSources)
O <<
"{";
288 for (
unsigned i = 0; i != NumEdgeSources; ++i)
291 O <<
"<s" << i <<
">";
300 void emitEdge(
const void *SrcNodeID,
int SrcNodePort,
301 const void *DestNodeID,
int DestNodePort,
304 if (SrcNodePort > 64)
return;
305 if (DestNodePort > 64) DestNodePort = 64;
307 O <<
"\tNode" << SrcNodeID;
308 if (SrcNodePort >= 0)
309 O <<
":s" << SrcNodePort;
310 O <<
" -> Node" << DestNodeID;
312 O <<
":d" << DestNodePort;
315 O <<
"[" << Attrs <<
"]";
327 template<
typename GraphType>
328 std::ofstream &
WriteGraph(std::ofstream &O,
const GraphType &G,
329 bool ShortNames =
false)
344 template <
typename GraphType>
346 bool ShortNames =
false,
350 std::ofstream O(Filename);
354 std::cerr <<
"error opening file '" << Filename <<
"' for writing!\n";
362 std::cerr <<
" done. \n";
370 template<
typename GraphType>
372 bool ShortNames =
false,
void emitSimpleNode(const void *ID, const std::string &Attr, const std::string &Label, unsigned NumEdgeSources=0, const std::vector< std::string > *EdgeSourceLabels=nullptr)
emitSimpleNode - Outputs a simple (non-record) node
void writeNode(NodeRef Node)
DOTGraphTraits< GraphType > DOTTraits
void emitEdge(const void *SrcNodeID, int SrcNodePort, const void *DestNodeID, int DestNodePort, const std::string &Attrs)
emitEdge - Output an edge from a simple node into the graph...
void writeEdge(NodeRef Node, unsigned edgeidx, child_iterator EI)
bool isNodeHidden(NodeRef Node)
bool getEdgeSourceLabels(std::stringstream &O2, NodeRef Node)
typename GTraits::nodes_iterator node_iterator
void writeHeader(const std::string &Title)
typename GTraits::NodeRef NodeRef
typename GTraits::ChildIteratorType child_iterator
void writeGraph(const std::string &Title="")
std::ofstream & getOStream()
GraphWriter(std::ofstream &o, const GraphType &g, bool SN)
std::string EscapeStr(const std::string &Label)
void ViewGraph(const GraphType &G, const std::string &name, bool ShortNames=false, GraphProgram::Name Program=GraphProgram::DOT)
std::ofstream & WriteGraph(std::ofstream &O, const GraphType &G, bool ShortNames=false)
std::string getNodeLabel(const void *, const GraphType &)
static std::string getNodeIdentifierLabel(const void *, const GraphType &)
static std::string getNodeAttributes(const void *, const GraphType &)
static std::string getGraphName(const GraphType &)
static void addCustomGraphFeatures(const GraphType &, GraphWriter &)
static std::string getEdgeDestLabel(const void *, unsigned)
static std::string getEdgeSourceLabel(const void *, EdgeIter)
static bool edgeTargetsEdgeSource(const void *, EdgeIter)
static bool hasEdgeDestLabels()
static unsigned numEdgeDestLabels(const void *)
static EdgeIter getEdgeTarget(const void *, EdgeIter I)
static std::string getEdgeAttributes(const void *, EdgeIter, const GraphType &)
static bool isNodeHidden(const void *, const GraphType &)
static bool renderGraphFromBottomUp()
static std::string getNodeDescription(const void *, const GraphType &)
static std::string getGraphProperties(const GraphType &)
typename GraphType::UnknownGraphTypeError NodeRef