From: 김수진/동작제어Lab(SR)/Engineer/삼성전자 Date: Fri, 19 Oct 2018 00:53:15 +0000 (+0900) Subject: [neurun][dotdumper] Introduce NodeAttr class (#3244) X-Git-Tag: 0.3~571 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=69c99db7024fc3b4317b98030f90ee5742b77588;p=platform%2Fcore%2Fml%2Fnnfw.git [neurun][dotdumper] Introduce NodeAttr class (#3244) This commit introduces `NodeAttr` class that can be more easier to add attributes of node. - ASIS ``` _dot << dotinfo.index_str() << " [shape=" << dotinfo.dot_shape() << " " << "label=\"" << dotinfo.label() << "\" " << "style=\"filled\" " << "fillcolor=\"" << dotinfo.bg_color() << "\"];\n"; - TOBE ``` 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(); ``` Signed-off-by: sjsujinkim --- diff --git a/runtimes/neurun/src/dumper/dot/DotBuilder.cc b/runtimes/neurun/src/dumper/dot/DotBuilder.cc index 728a9b9..0ee203a 100644 --- a/runtimes/neurun/src/dumper/dot/DotBuilder.cc +++ b/runtimes/neurun/src/dumper/dot/DotBuilder.cc @@ -23,6 +23,26 @@ namespace dumper 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) @@ -43,10 +63,15 @@ void DotBuilder::writeDot(std::ostream &os) 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) diff --git a/runtimes/neurun/src/dumper/dot/DotBuilder.h b/runtimes/neurun/src/dumper/dot/DotBuilder.h index ae3ef83..5d9c42d 100644 --- a/runtimes/neurun/src/dumper/dot/DotBuilder.h +++ b/runtimes/neurun/src/dumper/dot/DotBuilder.h @@ -38,6 +38,23 @@ namespace dumper 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> _attrs; + std::stringstream _attr_stream; +}; + class DotBuilder { public: