[coco] Non-template UseSlot (#1482)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Thu, 13 Sep 2018 02:20:52 +0000 (11:20 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 13 Sep 2018 02:20:52 +0000 (11:20 +0900)
This commit rewrites UseSlot as a non-template version. This is a step
to support Object-to-Object substitution.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/coco/core/include/coco/IR/Conv2D.h
contrib/coco/core/include/coco/IR/Instr.h
contrib/coco/core/include/coco/IR/UseSlot.h
contrib/coco/core/src/IR/Conv2D.cpp
contrib/coco/core/src/IR/Instr.cpp
contrib/coco/core/src/IR/UseSlot.test.cpp

index 8cb4676..dd7ce5b 100644 (file)
@@ -35,10 +35,10 @@ public:
   Instr *loc(void) override { return parent(); }
 
 private:
-  UseSlot<KernelObject> _ker;
+  UseSlot _ker;
 
 public:
-  KernelObject *ker(void) const { return _ker.value(); }
+  KernelObject *ker(void) const;
   void ker(KernelObject *ker);
 
 public:
index 46eeacb..f11aa30 100644 (file)
@@ -165,10 +165,10 @@ public:
   virtual ~FeatureInstr() = default;
 
 private:
-  UseSlot<FeatureObject> _ifm;
+  UseSlot _ifm;
 
 public:
-  FeatureObject *ifm(void) const { return _ifm.value(); }
+  FeatureObject *ifm(void) const;
   void ifm(FeatureObject *ifm);
 
 private:
index 9499551..578f772 100644 (file)
@@ -8,7 +8,7 @@
 namespace coco
 {
 
-template <typename T> class UseSlot final
+class UseSlot final
 {
 public:
   UseSlot(const PtrLink<Object, ObjectInfo> *obj_link, Object::Consumer *use)
@@ -18,10 +18,10 @@ public:
   }
 
 public:
-  T *value(void) const { return _value; }
+  Object *value(void) const { return _value; }
 
 public:
-  void value(T *value)
+  void value(Object *value)
   {
     if (_value)
     {
@@ -42,7 +42,7 @@ public:
 
 private:
   UseHook _hook;
-  T *_value;
+  Object *_value;
 };
 
 } // namespace coco
index 3f3972b..29570a8 100644 (file)
@@ -1,5 +1,7 @@
 #include "coco/IR/Conv2D.h"
 
+#include <cassert>
+
 namespace coco
 {
 
@@ -29,4 +31,15 @@ std::set<Object *> Conv2D::uses(void) const
 
 void Conv2D::ker(KernelObject *ker) { _ker.value(ker); }
 
+KernelObject *Conv2D::ker(void) const
+{
+  if (auto obj = _ker.value())
+  {
+    assert(obj->asKernel() != nullptr);
+    return obj->asKernel();
+  }
+
+  return nullptr;
+}
+
 } // namespace coco
index 7da448d..60e7b8e 100644 (file)
@@ -23,6 +23,18 @@ FeatureInstr::FeatureInstr(const PtrLink<Object, ObjectInfo> *obj_link)
 }
 
 void FeatureInstr::ifm(FeatureObject *ifm) { _ifm.value(ifm); }
+
+FeatureObject *FeatureInstr::ifm(void) const
+{
+  if (auto obj = _ifm.value())
+  {
+    assert(obj->asFeature() != nullptr);
+    return obj->asFeature();
+  }
+
+  return nullptr;
+}
+
 void FeatureInstr::ofm(FeatureObject *ofm) { _ofm.value(ofm); }
 
 FeatureObject *FeatureInstr::ofm(void) const
index 1f7773b..0558276 100644 (file)
@@ -26,7 +26,7 @@ TEST_F(UseSlotTest, constructor)
 
   ::mock::Use use;
 
-  coco::UseSlot<coco::FeatureObject> slot{&obj_link, &use};
+  coco::UseSlot slot{&obj_link, &use};
 
   ASSERT_EQ(slot.value(), nullptr);
 }
@@ -37,7 +37,7 @@ TEST_F(UseSlotTest, value)
 
   ::mock::Use use;
 
-  coco::UseSlot<coco::FeatureObject> slot{&obj_link, &use};
+  coco::UseSlot slot{&obj_link, &use};
 
   slot.value(o);