[coco] Remove UseHook (#1493)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Fri, 14 Sep 2018 07:48:18 +0000 (16:48 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Fri, 14 Sep 2018 07:48:18 +0000 (16:48 +0900)
This commit removes UseHook and implements its functionalities in
UseSlot as in Def.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/coco/core/include/coco/IR/UseHook.h [deleted file]
contrib/coco/core/include/coco/IR/UseSlot.h
contrib/coco/core/src/IR/UseHook.cpp [deleted file]
contrib/coco/core/src/IR/UseHook.test.cpp [deleted file]
contrib/coco/core/src/IR/UseSlot.cpp [new file with mode: 0644]

diff --git a/contrib/coco/core/include/coco/IR/UseHook.h b/contrib/coco/core/include/coco/IR/UseHook.h
deleted file mode 100644 (file)
index 0bec126..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-#ifndef __COCO_IR_USE_HOOK_H__
-#define __COCO_IR_USE_HOOK_H__
-
-#include "coco/IR/Object.h"
-#include "coco/IR/ObjectInfo.forward.h"
-
-#include "coco/ADT/PtrLink.h"
-
-namespace coco
-{
-
-class UseHook final
-{
-public:
-  UseHook(const PtrLink<Object, ObjectInfo> *obj_link, Object::Consumer *use)
-      : _obj_link{obj_link}, _use{use}
-  {
-    // DO NOTHING
-  }
-
-private:
-  ObjectInfo *info(Object *o) const;
-
-public:
-  void onTake(Object *o);
-  void onRelease(Object *o);
-
-private:
-  const PtrLink<Object, ObjectInfo> *const _obj_link;
-  // TODO Rename field
-  Object::Consumer *const _use;
-};
-
-} // namespace coco
-
-#endif // __COCO_IR_USE_HOOK_H__
index 578f772..8759931 100644 (file)
@@ -1,9 +1,10 @@
 #ifndef __COCO_IR_USE_SLOT_H__
 #define __COCO_IR_USE_SLOT_H__
 
-#include "coco/IR/UseHook.h"
+#include "coco/IR/Object.h"
+#include "coco/IR/ObjectInfo.forward.h"
 
-#include <cassert>
+#include "coco/ADT/PtrLink.h"
 
 namespace coco
 {
@@ -12,7 +13,7 @@ class UseSlot final
 {
 public:
   UseSlot(const PtrLink<Object, ObjectInfo> *obj_link, Object::Consumer *use)
-      : _hook{obj_link, use}, _value{nullptr}
+      : _link{obj_link}, _value{nullptr}, _consumer{use}
   {
     // DO NOTHING
   }
@@ -21,28 +22,14 @@ public:
   Object *value(void) const { return _value; }
 
 public:
-  void value(Object *value)
-  {
-    if (_value)
-    {
-      _hook.onRelease(_value);
-      _value = nullptr;
-    }
-
-    assert(_value == nullptr);
-
-    if (value)
-    {
-      _value = value;
-      _hook.onTake(_value);
-    }
+  void value(Object *value);
 
-    assert(_value == value);
-  }
+private:
+  const PtrLink<Object, ObjectInfo> *_link = nullptr;
 
 private:
-  UseHook _hook;
   Object *_value;
+  Object::Consumer *_consumer = nullptr;
 };
 
 } // namespace coco
diff --git a/contrib/coco/core/src/IR/UseHook.cpp b/contrib/coco/core/src/IR/UseHook.cpp
deleted file mode 100644 (file)
index 9538e0a..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-#include "coco/IR/UseHook.h"
-#include "coco/IR/ObjectInfo.h"
-
-#include <cassert>
-
-namespace coco
-{
-
-ObjectInfo *UseHook::info(Object *o) const
-{
-  auto info = _obj_link->find(o);
-  assert(info != nullptr);
-  return info;
-}
-
-void UseHook::onTake(Object *o) { info(o)->user()->insert(_use); }
-void UseHook::onRelease(Object *o) { info(o)->user()->erase(_use); }
-
-} // namespace coco
diff --git a/contrib/coco/core/src/IR/UseHook.test.cpp b/contrib/coco/core/src/IR/UseHook.test.cpp
deleted file mode 100644 (file)
index 44169aa..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-#include "coco/IR/UseHook.h"
-#include "coco/IR/ObjectInfo.h"
-#include "coco/IR/ObjectManager.h"
-
-#include "coco/IR/FeatureObject.h"
-
-#include "Use.mock.h"
-
-#include <gtest/gtest.h>
-
-namespace
-{
-class UseHookTest : public ::testing::Test
-{
-protected:
-  coco::PtrLink<coco::Bag, coco::BagInfo> bag_link;
-  coco::PtrLink<coco::Object, coco::ObjectInfo> obj_link;
-
-  coco::ObjectManager obj_mgr{&obj_link, &bag_link};
-};
-} // namespace
-
-TEST_F(UseHookTest, TakeAndRelease)
-{
-  auto o = obj_mgr.create(nncc::core::ADT::feature::Shape{1, 1, 1});
-
-  ::mock::Use use;
-
-  coco::UseHook hook{&obj_link, &use};
-
-  hook.onTake(o);
-  hook.onRelease(o);
-}
diff --git a/contrib/coco/core/src/IR/UseSlot.cpp b/contrib/coco/core/src/IR/UseSlot.cpp
new file mode 100644 (file)
index 0000000..5e7cbe8
--- /dev/null
@@ -0,0 +1,38 @@
+#include "coco/IR/UseSlot.h"
+#include "coco/IR/ObjectInfo.h"
+
+#include <cassert>
+
+namespace coco
+{
+
+void UseSlot::value(Object *value)
+{
+  if (_value)
+  {
+    if (_link)
+    {
+      auto info = _link->find(_value);
+      assert(info != nullptr);
+      info->user()->erase(_consumer);
+    }
+    _value = nullptr;
+  }
+
+  assert(_value == nullptr);
+
+  if (value)
+  {
+    _value = value;
+    if (_link)
+    {
+      auto info = _link->find(_value);
+      assert(info != nullptr);
+      info->user()->insert(_consumer);
+    }
+  }
+
+  assert(_value == value);
+}
+
+} // namespace coco