[nest] Add 'Var' class (#670)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Tue, 17 Jul 2018 00:36:53 +0000 (09:36 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Tue, 17 Jul 2018 00:36:53 +0000 (09:36 +0900)
This commit adds 'Var' class which users will actually use to contruct
nest expression.

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

index 8c84c06..66b2e43 100644 (file)
@@ -6,4 +6,13 @@
 
 #include "nest/expr/VarNode.h"
 
+#include <memory>
+
+namespace nest
+{
+
+using Expr = std::shared_ptr<nest::expr::Node>;
+
+} // namespace nest
+
 #endif // __NEST_EXPR_H__
diff --git a/contrib/nest/include/nest/Var.h b/contrib/nest/include/nest/Var.h
new file mode 100644 (file)
index 0000000..6549e45
--- /dev/null
@@ -0,0 +1,33 @@
+#ifndef __NEST_VAR_H__
+#define __NEST_VAR_H__
+
+#include "nest/VarID.h"
+#include "nest/Expr.h"
+
+namespace nest
+{
+
+class Var
+{
+public:
+  Var() = default;
+
+public:
+  Var(const VarID &id) : _id{id}
+  {
+    // DO NOTHING
+  }
+
+public:
+  const VarID &id(void) const { return _id; }
+
+public:
+  operator Expr(void) const;
+
+private:
+  VarID const _id;
+};
+
+} // namespace nest
+
+#endif // __NEST_VAR_H__
diff --git a/contrib/nest/src/Var.cpp b/contrib/nest/src/Var.cpp
new file mode 100644 (file)
index 0000000..1b519ca
--- /dev/null
@@ -0,0 +1,8 @@
+#include "nest/Var.h"
+
+namespace nest
+{
+
+Var::operator Expr(void) const { return std::make_shared<expr::VarNode>(_id); }
+
+} // namespace nest
diff --git a/contrib/nest/src/Var.test.cpp b/contrib/nest/src/Var.test.cpp
new file mode 100644 (file)
index 0000000..8e15c63
--- /dev/null
@@ -0,0 +1,22 @@
+#include "nest/Var.h"
+
+#include <gtest/gtest.h>
+
+TEST(VAR, ctor)
+{
+  nest::VarID id{0};
+  nest::Var var{id};
+
+  ASSERT_EQ(var.id(), id);
+}
+
+TEST(VAR, cast)
+{
+  nest::VarID id{0};
+  nest::Var var{id};
+
+  nest::Expr expr = var;
+
+  ASSERT_NE(expr->asVar(), nullptr);
+  ASSERT_EQ(expr->asVar()->id(), id);
+}