From: 박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 Date: Tue, 17 Jul 2018 06:01:51 +0000 (+0900) Subject: [nest] Add 'Block' class (#684) X-Git-Tag: nncc_backup~2402 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a5e287f4dcf982ab0263b2dffacb16a84429ff58;p=platform%2Fcore%2Fml%2Fnnfw.git [nest] Add 'Block' class (#684) This commit adds 'Block' class which maintains a sequence of nest statements. Signed-off-by: Jonghyun Park --- diff --git a/contrib/nest/include/nest/Block.h b/contrib/nest/include/nest/Block.h new file mode 100644 index 0000000..7e733d4 --- /dev/null +++ b/contrib/nest/include/nest/Block.h @@ -0,0 +1,30 @@ +#ifndef __NEST_BLOCK_H__ +#define __NEST_BLOCK_H__ + +#include "nest/Stmt.h" + +#include + +#include + +namespace nest +{ + +struct Block +{ +public: + uint32_t size(void) const { return _stmts.size(); } + +public: + const Stmt &at(uint32_t n) const { return _stmts.at(n); } + +public: + void append(const Stmt &stmt) { _stmts.emplace_back(stmt); } + +private: + std::vector _stmts; +}; + +} // namespace nest + +#endif // __NEST_BLOCK_H__ diff --git a/contrib/nest/include/nest/Stmt.h b/contrib/nest/include/nest/Stmt.h index fb8d8dc..e47d07c 100644 --- a/contrib/nest/include/nest/Stmt.h +++ b/contrib/nest/include/nest/Stmt.h @@ -4,4 +4,13 @@ #include "nest/stmt/Node.h" #include "nest/stmt/Visitor.h" +#include + +namespace nest +{ + +using Stmt = std::shared_ptr; + +} // namespace nest + #endif // __NEST_STMT_H__ diff --git a/contrib/nest/src/Block.test.cpp b/contrib/nest/src/Block.test.cpp new file mode 100644 index 0000000..045a659 --- /dev/null +++ b/contrib/nest/src/Block.test.cpp @@ -0,0 +1,25 @@ +#include "nest/Block.h" + +#include + +namespace +{ +struct DummyNode final : public nest::stmt::Node +{ + // Dummy Node for testing +}; +} + +TEST(BLOCK, use_case_1) +{ + nest::Block block; + + ASSERT_EQ(block.size(), 0); + + auto stmt = std::make_shared(); + + block.append(stmt); + + ASSERT_EQ(block.size(), 1); + ASSERT_EQ(block.at(0), stmt); +}