[enco] Extract string-manipulating rotuines (#1311)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Tue, 4 Sep 2018 01:51:13 +0000 (10:51 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Tue, 4 Sep 2018 01:51:13 +0000 (10:51 +0900)
This commit extracts concat method (for string manipulation) from
Subnet.cpp, and introduces String.h for future reuse.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/enco/core/src/CppGen/Subnet.cpp
contrib/enco/core/src/String.h [new file with mode: 0644]

index ea9391d..332ed67 100644 (file)
@@ -1,6 +1,7 @@
 #include "CppGen/Subnet.h"
 
 #include "Dims.h"
+#include "String.h"
 
 #include <pp/LinearDocument.h>
 
@@ -9,6 +10,7 @@
 #include <sstream>
 
 using nncc::foundation::make_unique;
+using enco::concat;
 
 #define S(content) #content
 
@@ -23,33 +25,6 @@ static std::ostream &operator<<(std::ostream &os, const ann::OperandID &id)
 
 namespace
 {
-template <typename It> void concat(std::ostream &os, const std::string &sep, It beg, It end)
-{
-  uint32_t count = 0;
-
-  for (auto it = beg; it != end; ++it, ++count)
-  {
-    if (count == 0)
-    {
-      os << *it;
-    }
-    else
-    {
-      os << sep << *it;
-    }
-  }
-}
-
-template <typename It> std::string concat(const std::string &sep, It beg, It end)
-{
-  std::stringstream ss;
-  concat(ss, sep, beg, end);
-  return ss.str();
-}
-} // namespace
-
-namespace
-{
 
 class SubnetStructImpl final : public enco::SubnetStruct
 {
diff --git a/contrib/enco/core/src/String.h b/contrib/enco/core/src/String.h
new file mode 100644 (file)
index 0000000..e03987f
--- /dev/null
@@ -0,0 +1,41 @@
+#ifndef __ENCO_STRING_H__
+#define __ENCO_STRING_H__
+
+//
+// String-manipulating routines
+//
+#include <ostream>
+#include <sstream>
+
+#include <string>
+
+namespace enco
+{
+
+template <typename It> void concat(std::ostream &os, const std::string &sep, It beg, It end)
+{
+  uint32_t count = 0;
+
+  for (auto it = beg; it != end; ++it, ++count)
+  {
+    if (count == 0)
+    {
+      os << *it;
+    }
+    else
+    {
+      os << sep << *it;
+    }
+  }
+}
+
+template <typename It> std::string concat(const std::string &sep, It beg, It end)
+{
+  std::stringstream ss;
+  concat(ss, sep, beg, end);
+  return ss.str();
+}
+
+} // namespace enco
+
+#endif // __ENCO_STRING_H__