[locop] Default-contructible NodeDesc (#4134)
author박종현/On-Device Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Mon, 8 Jul 2019 07:21:49 +0000 (16:21 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Mon, 8 Jul 2019 07:21:49 +0000 (16:21 +0900)
This commit makes (internal) NodeDesc default-constructible.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/locop/CMakeLists.txt
contrib/locop/src/FormattedGraph.cpp

index ff60c88..8b60295 100644 (file)
@@ -13,6 +13,7 @@ target_link_libraries(locop PUBLIC loco)
 target_link_libraries(locop PRIVATE nncc_common)
 target_link_libraries(locop PUBLIC nncc_coverage)
 target_link_libraries(locop PRIVATE pp)
+target_link_libraries(locop PRIVATE stdex)
 
 if(NOT ENABLE_TEST)
   return()
index 36e49a8..00ce7ac 100644 (file)
@@ -7,6 +7,8 @@
 
 #include <pp/Format.h>
 
+#include <stdex/Memory.h>
+
 #include <map>
 #include <set>
 
@@ -111,6 +113,7 @@ std::string opname(const loco::Node *node)
 namespace
 {
 
+using OpName = std::string;
 using ArgName = std::string;
 using ArgValue = std::string;
 using ArgDesc = std::pair<ArgName, ArgValue>;
@@ -135,13 +138,14 @@ public:
   };
 
 public:
-  NodeDesc(const std::string &name) : _name{name}
-  {
-    // DO NOTHING
-  }
+  NodeDesc() = default;
+  NodeDesc(const OpName &opname) { this->opname(opname); }
 
 public:
-  const std::string &name(void) const { return _name; }
+  const OpName &name(void) const { return opname(); }
+
+  const OpName &opname(void) const;
+  void opname(const OpName &value);
 
   uint32_t arg_size(void) const { return _args.size(); }
   const ArgDesc &arg(uint32_t n) const { return _args.at(n); }
@@ -151,11 +155,20 @@ public:
   void state(const State &s) { _state = s; }
 
 private:
-  std::string _name;
+  std::unique_ptr<OpName> _name = nullptr;
   std::vector<ArgDesc> _args;
   State _state = State::Invalid;
 };
 
+const std::string &NodeDesc::opname(void) const
+{
+  // _name SHOULD BE set before use
+  assert(_name != nullptr);
+  return *_name;
+}
+
+void NodeDesc::opname(const std::string &v) { _name = stdex::make_unique<std::string>(v); }
+
 std::ostream &operator<<(std::ostream &os, const NodeDesc &d)
 {
   assert(d.state() != NodeDesc::State::Invalid);