[coco] Remove UpdateHook (#1434)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Tue, 11 Sep 2018 01:49:51 +0000 (10:49 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Tue, 11 Sep 2018 01:49:51 +0000 (10:49 +0900)
UpdateHook was introduced to isolate non-template implementation from
Update<T>.

Now, Update<T> is no longer based on template, and thus UpdateHook is no
longer necessary.

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

index 1241caf..6d2603d 100644 (file)
@@ -1,9 +1,10 @@
 #ifndef __COCO_IR_UPDATE_H__
 #define __COCO_IR_UPDATE_H__
 
-#include "coco/IR/UpdateHook.h"
+#include "coco/IR/Bag.h"
+#include "coco/IR/BagInfo.forward.h"
 
-#include <cassert>
+#include "coco/ADT/PtrLink.h"
 
 namespace coco
 {
@@ -14,38 +15,29 @@ namespace coco
 class Update final
 {
 public:
-  Update(const PtrLink<Bag, BagInfo> *bag_link, Bag::Updater *update)
-      : _hook{bag_link, update}, _bag{nullptr}
+  Update(const PtrLink<Bag, BagInfo> *bag_link, Bag::Updater *u)
   {
-    // DO NOTHING
+    link(bag_link);
+    updater(u);
   }
 
 public:
-  Bag *bag(void) const { return _bag; }
+  void link(const PtrLink<Bag, BagInfo> *l) { _link = l; }
 
 public:
-  void bag(Bag *bag)
-  {
-    if (_bag)
-    {
-      _hook.onRelease(_bag);
-      _bag = nullptr;
-    }
-
-    assert(_bag == nullptr);
+  Bag *bag(void) const { return _bag; }
+  void bag(Bag *bag);
 
-    if (bag)
-    {
-      _bag = bag;
-      _hook.onTake(_bag);
-    }
+public:
+  Bag::Updater *updater(void) const { return _updater; }
+  void updater(Bag::Updater *u) { _updater = u; }
 
-    assert(_bag == bag);
-  }
+private:
+  const PtrLink<Bag, BagInfo> *_link;
 
 private:
-  UpdateHook _hook;
-  Bag *_bag;
+  Bag *_bag = nullptr;
+  Bag::Updater *_updater = nullptr;
 };
 
 } // namespace coco
diff --git a/contrib/coco/core/include/coco/IR/UpdateHook.h b/contrib/coco/core/include/coco/IR/UpdateHook.h
deleted file mode 100644 (file)
index 004c401..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-#ifndef __COCO_IR_UPDATE_HOOK_H__
-#define __COCO_IR_UPDATE_HOOK_H__
-
-#include "coco/IR/Bag.h"
-#include "coco/IR/BagInfo.forward.h"
-
-#include "coco/ADT/PtrLink.h"
-
-namespace coco
-{
-
-class UpdateHook final
-{
-public:
-  UpdateHook(const PtrLink<Bag, BagInfo> *bag_link, Bag::Updater *update)
-      : _bag_link{bag_link}, _update{update}
-  {
-    // DO NOTHING
-  }
-
-private:
-  BagInfo *info(Bag *bag) const;
-
-public:
-  void onTake(Bag *bag);
-  void onRelease(Bag *bag);
-
-private:
-  const PtrLink<Bag, BagInfo> *const _bag_link;
-  Bag::Updater *const _update;
-};
-
-} // namespace coco
-
-#endif // __COCO_IR_UPDATE_HOOK_H__
diff --git a/contrib/coco/core/src/IR/Update.cpp b/contrib/coco/core/src/IR/Update.cpp
new file mode 100644 (file)
index 0000000..6e0cf45
--- /dev/null
@@ -0,0 +1,38 @@
+#include "coco/IR/Update.h"
+#include "coco/IR/BagInfo.h"
+
+#include <cassert>
+
+namespace coco
+{
+
+void Update::bag(Bag *bag)
+{
+  if (_bag)
+  {
+    if (_link && _updater)
+    {
+      auto info = _link->find(_bag);
+      assert(info != nullptr);
+      info->updates()->erase(_updater);
+    }
+    _bag = nullptr;
+  }
+
+  assert(_bag == nullptr);
+
+  if (bag)
+  {
+    _bag = bag;
+    if (_link && _updater)
+    {
+      auto info = _link->find(_bag);
+      assert(info != nullptr);
+      info->updates()->insert(_updater);
+    }
+  }
+
+  assert(_bag == bag);
+}
+
+} // namespace coco
diff --git a/contrib/coco/core/src/IR/UpdateHook.cpp b/contrib/coco/core/src/IR/UpdateHook.cpp
deleted file mode 100644 (file)
index 3004d71..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-#include "coco/IR/UpdateHook.h"
-#include "coco/IR/BagInfo.h"
-
-#include <cassert>
-
-namespace coco
-{
-
-BagInfo *UpdateHook::info(Bag *bag) const
-{
-  auto info = _bag_link->find(bag);
-  assert(info != nullptr);
-  return info;
-}
-
-void UpdateHook::onTake(Bag *bag) { info(bag)->updates()->insert(_update); }
-void UpdateHook::onRelease(Bag *bag) { info(bag)->updates()->erase(_update); }
-
-} // namespace coco
diff --git a/contrib/coco/core/src/IR/UpdateHook.test.cpp b/contrib/coco/core/src/IR/UpdateHook.test.cpp
deleted file mode 100644 (file)
index 2c0e6f2..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-#include "coco/IR/UpdateHook.h"
-
-#include "coco/IR/BagInfo.h"
-#include "coco/IR/BagManager.h"
-
-#include "Update.mock.h"
-
-#include <gtest/gtest.h>
-
-namespace
-{
-class UpdateHookTest : public ::testing::Test
-{
-protected:
-  coco::PtrLink<coco::Bag, coco::BagInfo> bag_link;
-
-  coco::BagManager bag_mgr{&bag_link};
-};
-} // namespace
-
-TEST_F(UpdateHookTest, TakeAndRelease)
-{
-  auto bag = bag_mgr.create(16);
-
-  ::mock::Update update;
-
-  coco::UpdateHook hook{&bag_link, &update};
-
-  hook.onTake(bag);
-  {
-    auto updates = bag->updates();
-
-    ASSERT_EQ(updates.size(), 1);
-    ASSERT_NE(updates.find(&update), updates.end());
-  }
-
-  hook.onRelease(bag);
-  {
-    auto updates = bag->updates();
-
-    ASSERT_EQ(updates.size(), 0);
-  }
-}