From fe4277a9b25d7c699a95726e702da5afdb43bebe Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=B2=9C=EA=B5=90/On-Device=20Lab=28SR=29/Enginee?= =?utf8?q?r/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Mon, 13 May 2019 11:12:01 +0900 Subject: [PATCH] [locomotiv] Use macro to iterate supported Nodes (#3429) * [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 * clang-format off for comment indentation --- contrib/locomotiv/src/Node.lst | 8 ++++++++ contrib/locomotiv/src/NodeExecution.cpp | 17 +++++++---------- contrib/locomotiv/src/NodeExecution.h | 7 +++++-- 3 files changed, 20 insertions(+), 12 deletions(-) create mode 100644 contrib/locomotiv/src/Node.lst diff --git a/contrib/locomotiv/src/Node.lst b/contrib/locomotiv/src/Node.lst new file mode 100644 index 0000000..0754a22 --- /dev/null +++ b/contrib/locomotiv/src/Node.lst @@ -0,0 +1,8 @@ +#ifndef NODE +#error Define NODE first +#endif // NODE + +// NODE(Name) : alphabetic order please + +NODE(Pull) +NODE(Push) diff --git a/contrib/locomotiv/src/NodeExecution.cpp b/contrib/locomotiv/src/NodeExecution.cpp index 5cdf787..b45a9f6 100644 --- a/contrib/locomotiv/src/NodeExecution.cpp +++ b/contrib/locomotiv/src/NodeExecution.cpp @@ -24,17 +24,14 @@ namespace locomotiv // TODO Use visitor pattern of loco when available void NodeExecution::run(loco::Node *node) { - if (as(node)) - { - execute(as(node)); - return; - } - - if (as(node)) - { - execute(as(node)); - return; +#define NODE(Name) \ + if (as(node)) \ + { \ + execute(as(node)); \ + return; \ } +#include "Node.lst" +#undef NODE throw std::runtime_error("Not supported loco::Node type"); } diff --git a/contrib/locomotiv/src/NodeExecution.h b/contrib/locomotiv/src/NodeExecution.h index 0b3e7a3..c104c0f 100644 --- a/contrib/locomotiv/src/NodeExecution.h +++ b/contrib/locomotiv/src/NodeExecution.h @@ -45,14 +45,17 @@ private: return dynamic_cast(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 -- 2.7.4