namespace dot
{
+// NodeAttr
+NodeAttr &NodeAttr::addAttr(const std::string &name, const std::string &attr)
+{
+ _attrs.emplace_back(name, attr);
+
+ return *this;
+}
+
+void NodeAttr::finish()
+{
+ _attr_stream << "[";
+ for (auto attr : _attrs)
+ {
+ _attr_stream << attr.first << "="
+ << "\"" << attr.second << "\" ";
+ }
+ _attr_stream << "];\n";
+}
+
+// DotDumper
DotBuilder::DotBuilder() {}
void DotBuilder::update(const IDotInfo &node_info)
void DotBuilder::addNode(const IDotInfo &dotinfo)
{
- _dot << dotinfo.index_str() << " [shape=" << dotinfo.dot_shape() << " "
- << "label=\"" << dotinfo.label() << "\" "
- << "style=\"filled\" "
- << "fillcolor=\"" << dotinfo.bg_color() << "\"];\n";
+ NodeAttr attr;
+ attr.addAttr("shape", dotinfo.dot_shape())
+ .addAttr("label", dotinfo.label())
+ .addAttr("style", "filled")
+ .addAttr("fillcolor", dotinfo.bg_color());
+
+ attr.finish();
+
+ _dot << dotinfo.index_str() << attr.attr_stream();
}
void DotBuilder::addEdge(const IDotInfo &dotinfo1, const IDotInfo &dotinfo2)
namespace dot
{
+class NodeAttr
+{
+public:
+ NodeAttr() = default;
+
+public:
+ void finish();
+ NodeAttr &addAttr(const std::string &name, const std::string &attr);
+
+public:
+ std::stringbuf *attr_stream() { return _attr_stream.rdbuf(); }
+
+private:
+ std::vector<std::pair<std::string, std::string>> _attrs;
+ std::stringstream _attr_stream;
+};
+
class DotBuilder
{
public: