From: 박천교/On-Device Lab(SR)/Engineer/삼성전자 Date: Mon, 13 May 2019 02:12:01 +0000 (+0900) Subject: [locomotiv] Use macro to iterate supported Nodes (#3429) X-Git-Tag: nncc_backup~621 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fe4277a9b25d7c699a95726e702da5afdb43bebe;p=platform%2Fcore%2Fml%2Fnnfw.git [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 --- 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