[nest] Add 'Domain' class (#697)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Wed, 18 Jul 2018 04:03:57 +0000 (13:03 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Wed, 18 Jul 2018 04:03:57 +0000 (13:03 +0900)
This commit adds 'Domain' class which allows users to easily build
dereference expression with pre-allocated domain.

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

diff --git a/contrib/nest/include/nest/Domain.h b/contrib/nest/include/nest/Domain.h
new file mode 100644 (file)
index 0000000..5f2ddd5
--- /dev/null
@@ -0,0 +1,38 @@
+#ifndef __NEST_DOMAIN_H__
+#define __NEST_DOMAIN_H__
+
+#include "nest/Closure.h"
+
+namespace nest
+{
+
+class Domain
+{
+public:
+  Domain() = default;
+
+public:
+  Domain(const DomainID &id) : _id{id}
+  {
+    // DO NOTHING
+  }
+
+public:
+  Domain(const Domain &) = default;
+
+public:
+  template <typename... Args> Closure operator()(Args &&... indices)
+  {
+    return Closure{_id, std::forward<Args>(indices)...};
+  }
+
+public:
+  const DomainID &id(void) const { return _id; }
+
+private:
+  DomainID const _id;
+};
+
+} // namespace nest
+
+#endif // __NEST_DOMAIN_H__
index ba073d3..5e5a4c8 100644 (file)
@@ -4,6 +4,7 @@
 #include "nest/expr/Node.h"
 
 #include <vector>
+#include <initializer_list>
 
 #include <memory>
 
@@ -15,8 +16,7 @@ namespace expr
 class Subscript
 {
 public:
-  template <typename... Args>
-  Subscript(Args &&... indicies) : _indices{std::forward<Args>(indicies)...}
+  Subscript(std::initializer_list<std::shared_ptr<Node>> indices) : _indices{indices}
   {
     // DO NOTHING
   }
diff --git a/contrib/nest/src/Domain.test.cpp b/contrib/nest/src/Domain.test.cpp
new file mode 100644 (file)
index 0000000..1b85360
--- /dev/null
@@ -0,0 +1,25 @@
+#include "nest/Domain.h"
+
+#include <gtest/gtest.h>
+
+namespace
+{
+namespace expr
+{
+struct DummyNode final : public nest::expr::Node
+{
+};
+} // namespace expr
+} // namespace
+
+// NOTE Build failed when DOMAIN is used instead of _DOMAIN
+TEST(_DOMAIN, base_usecase)
+{
+  nest::DomainID dom_id{0};
+  nest::Domain dom{dom_id};
+
+  nest::Closure clo = dom(std::make_shared<::expr::DummyNode>());
+
+  ASSERT_EQ(clo.id(), dom_id);
+  ASSERT_EQ(clo.sub().rank(), 1);
+}