Go to the documentation of this file.00001
00014 #include "OutputBuilderDOT.hpp"
00015 #include <string>
00016
00017 std::string filter(const std::string &cpsource,const std::string &find,const std::string &replace )
00018 {
00019 std::string source = cpsource;
00020 size_t i = source.find(find);
00021 while (i != std::string::npos) {
00022 source.replace(i, find.length(), replace);
00023 i = source.find(find, i + replace.length());
00024 }
00025 return source;
00026 }
00027
00028 namespace OA {
00029
00030 OutputBuilderDOT::OutputBuilderDOT() :
00031 OutputBuilderText(std::cout)
00032 {
00033 }
00034
00035 OutputBuilderDOT::OutputBuilderDOT(std::ostream& stream) :
00036 OutputBuilderText(stream)
00037 {
00038 }
00039
00040 void OutputBuilderDOT::outputString(const std::string &str)
00041 {
00042 mStream << filter(filter(str, "\n", "\\n"), "\"", "\\\"");
00043 }
00044
00045 void OutputBuilderDOT::graphStart(const std::string &label)
00046 {
00047 mStream << indt << "digraph " << filter(label, "\n", "\\n")
00048 << " {" << pushIndt;
00049 mStream << indt << "node [shape=rectangle];";
00050 }
00051
00052 void OutputBuilderDOT::graphEnd(const std::string &label)
00053 {
00054
00055 mStream << popIndt << "}" << std::endl;
00056 }
00057
00058 void OutputBuilderDOT::graphSubStart(const std::string & label)
00059 {
00060
00061
00062
00063 int len = label.length();
00064
00065 int lastColonPos = -1;
00066 int i;
00067 for (i = len-1; i >= 0; i--) {
00068 if (label[i]==':') {
00069 lastColonPos = i;
00070 break;
00071 }
00072 }
00073 if (lastColonPos == -1) {
00074
00075 mStream << indt << "subgraph cluster_" << label << " {"
00076 << pushIndt;
00077 } else {
00078
00079 mStream << indt << "subgraph cluster_" << label.substr(i+1,len-i) << " {"
00080 << pushIndt;
00081 }
00082
00083
00084 mStream << indt << "label=\"" << filter(filter(label, "\n", "\\n"), "\"", "\\\"") << "\"";
00085 }
00086
00087 void OutputBuilderDOT::graphSubEnd(const std::string &label)
00088 {
00089 mStream << popIndt << indt << "}";
00090 }
00091
00092 void OutputBuilderDOT::graphNodeStart(int id)
00093 {
00094 mStream << indt << id << " [ ";
00095 }
00096
00097 void OutputBuilderDOT::graphNodeLabel(const std::string &label)
00098 {
00099 mStream << "label=\"" << filter(filter(label, "\n", "\\n"), "\"", "\\\"") << "\"";
00100 }
00101
00102 void OutputBuilderDOT::graphNodeLabelStart()
00103 {
00104 mStream << "label=\"";
00105 }
00106
00107 void OutputBuilderDOT::graphNodeLabelEnd()
00108 {
00109 mStream << "\"";
00110 }
00111
00112 void OutputBuilderDOT::graphNodeEnd()
00113 {
00114 mStream << " ];";
00115 }
00116
00117 void OutputBuilderDOT::graphEdgeStart()
00118 {
00119 }
00120
00121 void OutputBuilderDOT::graphEdgeSourceNode(int id)
00122 {
00123 mStream << indt << id << " -> ";
00124 }
00125
00126 void OutputBuilderDOT::graphEdgeSinkNode(int id)
00127 {
00128 mStream << id << " [";
00129 }
00130
00131 void OutputBuilderDOT::graphEdgeLabelStart()
00132 {
00133 mStream << " label=\"";
00134 }
00135
00136 void OutputBuilderDOT::graphEdgeLabelEnd()
00137 {
00138 mStream << "\"";
00139 }
00140
00141 void OutputBuilderDOT::graphEdgeEnd()
00142 {
00143 mStream << " ];";
00144 }
00145
00146 }
00147