[locomotiv] Use macro to iterate supported Nodes (#3429)
author박천교/On-Device Lab(SR)/Engineer/삼성전자 <ch.bahk@samsung.com>
Mon, 13 May 2019 02:12:01 +0000 (11:12 +0900)
committer박종현/On-Device Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Mon, 13 May 2019 02:12:01 +0000 (11:12 +0900)
* [locomotiv] Use macro to iterate supported Nodes

This commit introduces list of supported Nodes for execution, and use
them with macro to iterate and do same thing through Nodes.

Signed-off-by: Cheongyo Bahk <ch.bahk@samsung.com>
* clang-format off for comment indentation

contrib/locomotiv/src/Node.lst [new file with mode: 0644]
contrib/locomotiv/src/NodeExecution.cpp
contrib/locomotiv/src/NodeExecution.h

diff --git a/contrib/locomotiv/src/Node.lst b/contrib/locomotiv/src/Node.lst
new file mode 100644 (file)
index 0000000..0754a22
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef NODE
+#error Define NODE first
+#endif // NODE
+
+// NODE(Name) : alphabetic order please
+
+NODE(Pull)
+NODE(Push)
index 5cdf787..b45a9f6 100644 (file)
@@ -24,17 +24,14 @@ namespace locomotiv
 // TODO Use visitor pattern of loco when available
 void NodeExecution::run(loco::Node *node)
 {
-  if (as<loco::Pull>(node))
-  {
-    execute(as<loco::Pull>(node));
-    return;
-  }
-
-  if (as<loco::Push>(node))
-  {
-    execute(as<loco::Push>(node));
-    return;
+#define NODE(Name)                 \
+  if (as<loco::Name>(node))        \
+  {                                \
+    execute(as<loco::Name>(node)); \
+    return;                        \
   }
+#include "Node.lst"
+#undef NODE
 
   throw std::runtime_error("Not supported loco::Node type");
 }
index 0b3e7a3..c104c0f 100644 (file)
@@ -45,14 +45,17 @@ private:
     return dynamic_cast<Derived *>(node);
   }
 
+// clang-format off
   /**
    * @brief Calculate for one specified node and update its result as NodeData.
    *        Abort program when its ingredients are not ready or not supported.
    *
    * @note Definitions of overloaded execute() are in 'Node/' directory
    */
-  void execute(loco::Pull *);
-  void execute(loco::Push *);
+// clang-format on
+#define NODE(Name) void execute(loco::Name *);
+#include "Node.lst"
+#undef NODE
 };
 
 } // namespace locomotiv