[coco] Accessor on ObjectInfo (#1001)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Tue, 14 Aug 2018 07:42:47 +0000 (16:42 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Tue, 14 Aug 2018 07:42:47 +0000 (16:42 +0900)
This commit introduces indirect accessor on ObjectInfo inside Object
class.

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

index d2159ef..5f11e9c 100644 (file)
@@ -26,6 +26,7 @@ public:
   ~FeatureObject();
 
 private:
+  void get(ObjectInfo **) const override;
   void get(const PtrLink<Bag, BagInfo> **out) const override;
 
 public:
index 86f659d..a5abf5a 100644 (file)
@@ -1,12 +1,14 @@
 #ifndef __COCO_IR_FEATURE_OBJECT_INFO_H__
 #define __COCO_IR_FEATURE_OBJECT_INFO_H__
 
+#include "coco/IR/ObjectInfo.h"
+
 #include <nncc/core/ADT/feature/Shape.h>
 
 namespace coco
 {
 
-class FeatureObjectInfo final
+class FeatureObjectInfo final : public ObjectInfo
 {
 public:
   FeatureObjectInfo(const nncc::core::ADT::feature::Shape &shape) : _shape{shape}
index 4b35461..1b50bcb 100644 (file)
@@ -26,6 +26,7 @@ public:
   virtual ~KernelObject();
 
 private:
+  void get(ObjectInfo **) const override;
   void get(const PtrLink<Bag, BagInfo> **out) const override;
 
 public:
index 83a3079..ab03e0d 100644 (file)
@@ -1,12 +1,14 @@
 #ifndef __COCO_IR_KERNEL_OBJECT_INFO_H__
 #define __COCO_IR_KERNEL_OBJECT_INFO_H__
 
+#include "coco/IR/ObjectInfo.h"
+
 #include <nncc/core/ADT/kernel/Shape.h>
 
 namespace coco
 {
 
-class KernelObjectInfo final
+class KernelObjectInfo final : public ObjectInfo
 {
 public:
   KernelObjectInfo(const nncc::core::ADT::kernel::Shape &shape) : _shape{shape}
index ab31945..04bafd1 100644 (file)
@@ -2,6 +2,7 @@
 #define __COCO_IR_OBJECT_H__
 
 #include "coco/IR/Bag.h"
+#include "coco/IR/ObjectInfo.forward.h"
 
 #include "coco/IR/FeatureObject.forward.h"
 #include "coco/IR/KernelObject.forward.h"
@@ -23,6 +24,7 @@ public:
   virtual ~Object() = default;
 
 protected:
+  virtual void get(ObjectInfo **) const = 0;
   virtual void get(const PtrLink<Bag, BagInfo> **) const = 0;
 
 protected:
index 16b42e8..12c3c0b 100644 (file)
@@ -4,10 +4,13 @@
 namespace coco
 {
 
-class ObjectInfo final
+class ObjectInfo
 {
 public:
   ObjectInfo() = default;
+
+public:
+  virtual ~ObjectInfo() = default;
 };
 
 } // namespace coco
index 7173cd5..42967c4 100644 (file)
@@ -25,6 +25,7 @@ FeatureObject::~FeatureObject()
   // DO NOTHING
 }
 
+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 a955263..fcd2c25 100644 (file)
@@ -25,6 +25,7 @@ KernelObject::~KernelObject()
   // DO NOTHING
 }
 
+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 0c34a8f..9a7b084 100644 (file)
@@ -1,11 +1,16 @@
 #include "coco/IR/Object.h"
+#include "coco/IR/ObjectInfo.h"
 #include "coco/IR/BagManager.h"
 #include "coco/IR/BagInfo.h"
 
+#include <nncc/foundation/Memory.h>
+
 #include <vector>
 
 #include <gtest/gtest.h>
 
+using nncc::foundation::make_unique;
+
 namespace
 {
 class ObjectTest : public ::testing::Test
@@ -28,9 +33,11 @@ public:
   virtual ~Object() = default;
 
 public:
+  std::unique_ptr<coco::ObjectInfo> info;
   const coco::PtrLink<coco::Bag, coco::BagInfo> *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
@@ -71,6 +78,7 @@ TEST_F(ObjectTest, bag_update)
   std::vector<coco::Bag *> updates;
   DummyObject obj{updates};
 
+  obj.info = make_unique<coco::ObjectInfo>();
   obj.link = &link;
 
   obj.bag(bag);