[coco] Initialize BagLink via non-virtual method (#1390)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Thu, 6 Sep 2018 10:37:00 +0000 (19:37 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 6 Sep 2018 10:37:00 +0000 (19:37 +0900)
This commit deprecates virtual get method, and introduces non-virtual
setBagLink method.

This will allows us to use Bag Link inside destructor.

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

index 5f11e9c..0beba33 100644 (file)
@@ -27,7 +27,6 @@ public:
 
 private:
   void get(ObjectInfo **) const override;
-  void get(const PtrLink<Bag, BagInfo> **out) const override;
 
 public:
   FeatureObject *asFeature(void) override { return this; }
@@ -46,7 +45,6 @@ public:
 
 private:
   std::unique_ptr<FeatureObjectInfo> _info;
-  const PtrLink<Bag, BagInfo> *const _link;
 
   std::vector<ElemID> _map;
 };
index 1b50bcb..88c9f2a 100644 (file)
@@ -27,7 +27,6 @@ public:
 
 private:
   void get(ObjectInfo **) const override;
-  void get(const PtrLink<Bag, BagInfo> **out) const override;
 
 public:
   KernelObject *asKernel(void) override { return this; }
@@ -46,7 +45,6 @@ public:
 
 private:
   std::unique_ptr<KernelObjectInfo> _info;
-  const PtrLink<Bag, BagInfo> *const _link;
 
   std::vector<ElemID> _map;
 };
index 2d36d9a..cde9132 100644 (file)
@@ -40,7 +40,7 @@ public:
 
 protected:
   virtual void get(ObjectInfo **) const = 0;
-  virtual void get(const PtrLink<Bag, BagInfo> **) const = 0;
+  void setBagLink(const PtrLink<Bag, BagInfo> *);
 
 private:
   coco::Bag *_bag;
@@ -63,6 +63,9 @@ private:
 public:
   Def *def(void) const;
   const User *user(void) const;
+
+private:
+  const PtrLink<Bag, BagInfo> *_bag_link;
 };
 
 } // namespace coco
index 42967c4..41aba73 100644 (file)
@@ -15,8 +15,9 @@ namespace coco
 
 FeatureObject::FeatureObject(std::unique_ptr<FeatureObjectInfo> &&info,
                              const PtrLink<Bag, BagInfo> *link)
-    : _info(std::move(info)), _link{link}
+    : _info(std::move(info))
 {
+  setBagLink(link);
   _map.resize(nncc::core::ADT::feature::num_elements(shape()));
 }
 
@@ -26,7 +27,6 @@ FeatureObject::~FeatureObject()
 }
 
 void FeatureObject::get(ObjectInfo **out) const { *out = _info.get(); }
-void FeatureObject::get(const PtrLink<Bag, BagInfo> **out) const { *out = _link; }
 
 const nncc::core::ADT::feature::Shape &FeatureObject::shape(void) const { return _info->shape(); }
 
index fcd2c25..d05c9a9 100644 (file)
@@ -15,8 +15,9 @@ namespace coco
 
 KernelObject::KernelObject(std::unique_ptr<KernelObjectInfo> &&info,
                            const PtrLink<Bag, BagInfo> *link)
-    : _info{std::move(info)}, _link{link}
+    : _info{std::move(info)}
 {
+  setBagLink(link);
   _map.resize(nncc::core::ADT::kernel::num_elements(shape()));
 }
 
@@ -26,7 +27,6 @@ KernelObject::~KernelObject()
 }
 
 void KernelObject::get(ObjectInfo **out) const { *out = _info.get(); }
-void KernelObject::get(const PtrLink<Bag, BagInfo> **out) const { *out = _link; }
 
 const nncc::core::ADT::kernel::Shape &KernelObject::shape(void) const { return _info->shape(); }
 
index eba9529..838c06c 100644 (file)
@@ -13,6 +13,8 @@ Object::Object() : _bag{nullptr}
   // DO NOTHING
 }
 
+void Object::setBagLink(const PtrLink<Bag, BagInfo> *bag_link) { _bag_link = bag_link; }
+
 void Object::bag(coco::Bag *bag)
 {
   if (_bag != nullptr)
@@ -48,11 +50,8 @@ ObjectInfo *Object::info(void) const
 
 BagInfo *Object::info(const Bag *bag) const
 {
-  const PtrLink<Bag, BagInfo> *link = nullptr;
-  get(&link);
-  assert(link != nullptr);
-
-  return link->find(bag);
+  assert(_bag_link != nullptr);
+  return _bag_link->find(bag);
 }
 
 Object::Def *Object::def(void) const { return info()->def(); }
index 99ba140..2305bbe 100644 (file)
@@ -34,11 +34,12 @@ public:
 
 public:
   std::unique_ptr<coco::ObjectInfo> info;
-  const coco::PtrLink<coco::Bag, coco::BagInfo> *link;
+
+public:
+  void link(const coco::PtrLink<coco::Bag, coco::BagInfo> *link) { setBagLink(link); }
 
 private:
   void get(coco::ObjectInfo **out) const override { *out = info.get(); }
-  void get(const coco::PtrLink<coco::Bag, coco::BagInfo> **out) const override { *out = link; }
 };
 } // namespace mock
 } // namespace
@@ -66,7 +67,7 @@ TEST_F(ObjectTest, bag_update)
   ::mock::Object obj;
 
   obj.info = make_unique<coco::ObjectInfo>();
-  obj.link = &link;
+  obj.link(&link);
 
   obj.bag(bag);