[coco] Remove ReadHook (#1433)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Tue, 11 Sep 2018 01:34:54 +0000 (10:34 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Tue, 11 Sep 2018 01:34:54 +0000 (10:34 +0900)
ReadHook was introduced to provide  common (non-template) implementation
over Read<T> classes.

This commit removes ReadHook and directly implements related operation
in Read as Read is no longer based on template.

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

index dbdb190..78f8ad8 100644 (file)
@@ -1,9 +1,10 @@
 #ifndef __COCO_IR_READ_H__
 #define __COCO_IR_READ_H__
 
-#include "coco/IR/ReadHook.h"
+#include "coco/IR/Bag.h"
+#include "coco/IR/BagInfo.forward.h"
 
-#include <cassert>
+#include "coco/ADT/PtrLink.h"
 
 namespace coco
 {
@@ -14,38 +15,30 @@ namespace coco
 class Read final
 {
 public:
-  Read(const PtrLink<Bag, BagInfo> *bag_link, Bag::Reader *read)
-      : _hook{bag_link, read}, _bag{nullptr}
+  Read(const PtrLink<Bag, BagInfo> *bag_link, Bag::Reader *r)
   {
-    // DO NOTHING
+    // Initialize link and reader
+    link(bag_link);
+    reader(r);
   }
 
 public:
   Bag *bag(void) const { return _bag; }
+  void bag(Bag *bag);
 
 public:
-  void bag(Bag *bag)
-  {
-    if (_bag)
-    {
-      _hook.onRelease(_bag);
-      _bag = nullptr;
-    }
-
-    assert(_bag == nullptr);
+  Bag::Reader *reader(void) const { return _reader; }
+  void reader(Bag::Reader *r) { _reader = r; }
 
-    if (bag)
-    {
-      _bag = bag;
-      _hook.onTake(_bag);
-    }
+public:
+  void link(const PtrLink<Bag, BagInfo> *l) { _link = l; }
 
-    assert(_bag == bag);
-  }
+private:
+  const PtrLink<Bag, BagInfo> *_link;
 
 private:
-  ReadHook _hook;
-  Bag *_bag;
+  Bag *_bag = nullptr;
+  Bag::Reader *_reader = nullptr;
 };
 
 } // namespace coco
diff --git a/contrib/coco/core/include/coco/IR/ReadHook.h b/contrib/coco/core/include/coco/IR/ReadHook.h
deleted file mode 100644 (file)
index 653530f..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-#ifndef __COCO_IR_READ_HOOK_H__
-#define __COCO_IR_READ_HOOK_H__
-
-#include "coco/IR/Bag.h"
-#include "coco/IR/BagInfo.forward.h"
-
-#include "coco/ADT/PtrLink.h"
-
-namespace coco
-{
-
-class ReadHook final
-{
-public:
-  ReadHook(const PtrLink<Bag, BagInfo> *bag_link, Bag::Reader *read)
-      : _bag_link{bag_link}, _read{read}
-  {
-    // 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::Reader *const _read;
-};
-
-} // namespace coco
-
-#endif // __COCO_IR_READ_HOOK_H__
diff --git a/contrib/coco/core/src/IR/Read.cpp b/contrib/coco/core/src/IR/Read.cpp
new file mode 100644 (file)
index 0000000..3144fc8
--- /dev/null
@@ -0,0 +1,38 @@
+#include "coco/IR/Read.h"
+#include "coco/IR/BagInfo.h"
+
+#include <cassert>
+
+namespace coco
+{
+
+void Read::bag(Bag *bag)
+{
+  if (_bag)
+  {
+    if (_link && _reader)
+    {
+      auto info = _link->find(_bag);
+      assert(info != nullptr);
+      info->reads()->erase(_reader);
+    }
+    _bag = nullptr;
+  }
+
+  assert(_bag == nullptr);
+
+  if (bag)
+  {
+    _bag = bag;
+    if (_link && _reader)
+    {
+      auto info = _link->find(_bag);
+      assert(info != nullptr);
+      info->reads()->insert(_reader);
+    }
+  }
+
+  assert(_bag == bag);
+}
+
+} // namespace coco
diff --git a/contrib/coco/core/src/IR/ReadHook.cpp b/contrib/coco/core/src/IR/ReadHook.cpp
deleted file mode 100644 (file)
index 31929db..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-#include "coco/IR/ReadHook.h"
-#include "coco/IR/BagInfo.h"
-
-#include <cassert>
-
-namespace coco
-{
-
-BagInfo *ReadHook::info(Bag *bag) const
-{
-  auto info = _bag_link->find(bag);
-  assert(info != nullptr);
-  return info;
-}
-
-void ReadHook::onTake(Bag *bag) { info(bag)->reads()->insert(_read); }
-void ReadHook::onRelease(Bag *bag) { info(bag)->reads()->erase(_read); }
-
-} // namespace coco
diff --git a/contrib/coco/core/src/IR/ReadHook.test.cpp b/contrib/coco/core/src/IR/ReadHook.test.cpp
deleted file mode 100644 (file)
index 246e270..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-#include "coco/IR/ReadHook.h"
-
-#include "coco/IR/BagInfo.h"
-#include "coco/IR/BagManager.h"
-
-#include "Read.mock.h"
-
-#include <gtest/gtest.h>
-
-namespace
-{
-class ReadHookTest : public ::testing::Test
-{
-protected:
-  coco::PtrLink<coco::Bag, coco::BagInfo> bag_link;
-
-  coco::BagManager bag_mgr{&bag_link};
-};
-} // namespace
-
-TEST_F(ReadHookTest, TakeAndRelease)
-{
-  auto bag = bag_mgr.create(16);
-
-  ::mock::Read read;
-
-  coco::ReadHook hook{&bag_link, &read};
-
-  hook.onTake(bag);
-  {
-    auto reads = bag->reads();
-
-    ASSERT_EQ(reads.size(), 1);
-    ASSERT_NE(reads.find(&read), reads.end());
-  }
-
-  hook.onRelease(bag);
-  {
-    auto reads = bag->reads();
-
-    ASSERT_EQ(reads.size(), 0);
-  }
-}