[nest] Add 'Subscript' class (#672)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Tue, 17 Jul 2018 00:56:31 +0000 (09:56 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Tue, 17 Jul 2018 00:56:31 +0000 (09:56 +0900)
This commit adds 'Subsscript' class under nest::expr namespace, which
denotes a ND domain subscript expression.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/nest/include/nest/expr/Subscript.h [new file with mode: 0644]
contrib/nest/src/expr/Subscript.test.cpp [new file with mode: 0644]

diff --git a/contrib/nest/include/nest/expr/Subscript.h b/contrib/nest/include/nest/expr/Subscript.h
new file mode 100644 (file)
index 0000000..ba073d3
--- /dev/null
@@ -0,0 +1,37 @@
+#ifndef __NEST_SUBSCRIPT_H__
+#define __NEST_SUBSCRIPT_H__
+
+#include "nest/expr/Node.h"
+
+#include <vector>
+
+#include <memory>
+
+namespace nest
+{
+namespace expr
+{
+
+class Subscript
+{
+public:
+  template <typename... Args>
+  Subscript(Args &&... indicies) : _indices{std::forward<Args>(indicies)...}
+  {
+    // DO NOTHING
+  }
+
+public:
+  uint32_t rank(void) const { return _indices.size(); }
+
+public:
+  const std::shared_ptr<expr::Node> &at(uint32_t n) const { return _indices.at(n); }
+
+private:
+  std::vector<std::shared_ptr<expr::Node>> const _indices;
+};
+
+} // namespace expr
+} // namespace nest
+
+#endif // __NEST_SUBSCRIPT_H__
diff --git a/contrib/nest/src/expr/Subscript.test.cpp b/contrib/nest/src/expr/Subscript.test.cpp
new file mode 100644 (file)
index 0000000..104373a
--- /dev/null
@@ -0,0 +1,21 @@
+#include "nest/expr/Subscript.h"
+#include "nest/expr/VarNode.h"
+
+#include <memory>
+
+#include <gtest/gtest.h>
+
+TEST(SUBSCRIPT, ctor)
+{
+  nest::VarID id_0{0};
+  nest::VarID id_1{1};
+
+  auto expr_0 = std::make_shared<nest::expr::VarNode>(id_0);
+  auto expr_1 = std::make_shared<nest::expr::VarNode>(id_1);
+
+  nest::expr::Subscript sub{expr_0, expr_1};
+
+  ASSERT_EQ(sub.rank(), 2);
+  ASSERT_EQ(sub.at(0), expr_0);
+  ASSERT_EQ(sub.at(1), expr_1);
+}