From 0d5183e8a545222868855b609b8d68bb6e9dc371 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=A2=85=ED=98=84/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Staff=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Tue, 14 Aug 2018 16:42:47 +0900 Subject: [PATCH] [coco] Accessor on ObjectInfo (#1001) This commit introduces indirect accessor on ObjectInfo inside Object class. Signed-off-by: Jonghyun Park --- contrib/coco/core/include/coco/IR/FeatureObject.h | 1 + contrib/coco/core/include/coco/IR/FeatureObjectInfo.h | 4 +++- contrib/coco/core/include/coco/IR/KernelObject.h | 1 + contrib/coco/core/include/coco/IR/KernelObjectInfo.h | 4 +++- contrib/coco/core/include/coco/IR/Object.h | 2 ++ contrib/coco/core/include/coco/IR/ObjectInfo.h | 5 ++++- contrib/coco/core/src/IR/FeatureObject.cpp | 1 + contrib/coco/core/src/IR/KernelObject.cpp | 1 + contrib/coco/core/src/IR/Object.test.cpp | 8 ++++++++ 9 files changed, 24 insertions(+), 3 deletions(-) diff --git a/contrib/coco/core/include/coco/IR/FeatureObject.h b/contrib/coco/core/include/coco/IR/FeatureObject.h index d2159ef..5f11e9c 100644 --- a/contrib/coco/core/include/coco/IR/FeatureObject.h +++ b/contrib/coco/core/include/coco/IR/FeatureObject.h @@ -26,6 +26,7 @@ public: ~FeatureObject(); private: + void get(ObjectInfo **) const override; void get(const PtrLink **out) const override; public: diff --git a/contrib/coco/core/include/coco/IR/FeatureObjectInfo.h b/contrib/coco/core/include/coco/IR/FeatureObjectInfo.h index 86f659d..a5abf5a 100644 --- a/contrib/coco/core/include/coco/IR/FeatureObjectInfo.h +++ b/contrib/coco/core/include/coco/IR/FeatureObjectInfo.h @@ -1,12 +1,14 @@ #ifndef __COCO_IR_FEATURE_OBJECT_INFO_H__ #define __COCO_IR_FEATURE_OBJECT_INFO_H__ +#include "coco/IR/ObjectInfo.h" + #include namespace coco { -class FeatureObjectInfo final +class FeatureObjectInfo final : public ObjectInfo { public: FeatureObjectInfo(const nncc::core::ADT::feature::Shape &shape) : _shape{shape} diff --git a/contrib/coco/core/include/coco/IR/KernelObject.h b/contrib/coco/core/include/coco/IR/KernelObject.h index 4b35461..1b50bcb 100644 --- a/contrib/coco/core/include/coco/IR/KernelObject.h +++ b/contrib/coco/core/include/coco/IR/KernelObject.h @@ -26,6 +26,7 @@ public: virtual ~KernelObject(); private: + void get(ObjectInfo **) const override; void get(const PtrLink **out) const override; public: diff --git a/contrib/coco/core/include/coco/IR/KernelObjectInfo.h b/contrib/coco/core/include/coco/IR/KernelObjectInfo.h index 83a3079..ab03e0d 100644 --- a/contrib/coco/core/include/coco/IR/KernelObjectInfo.h +++ b/contrib/coco/core/include/coco/IR/KernelObjectInfo.h @@ -1,12 +1,14 @@ #ifndef __COCO_IR_KERNEL_OBJECT_INFO_H__ #define __COCO_IR_KERNEL_OBJECT_INFO_H__ +#include "coco/IR/ObjectInfo.h" + #include namespace coco { -class KernelObjectInfo final +class KernelObjectInfo final : public ObjectInfo { public: KernelObjectInfo(const nncc::core::ADT::kernel::Shape &shape) : _shape{shape} diff --git a/contrib/coco/core/include/coco/IR/Object.h b/contrib/coco/core/include/coco/IR/Object.h index ab31945..04bafd1 100644 --- a/contrib/coco/core/include/coco/IR/Object.h +++ b/contrib/coco/core/include/coco/IR/Object.h @@ -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 **) const = 0; protected: diff --git a/contrib/coco/core/include/coco/IR/ObjectInfo.h b/contrib/coco/core/include/coco/IR/ObjectInfo.h index 16b42e8..12c3c0b 100644 --- a/contrib/coco/core/include/coco/IR/ObjectInfo.h +++ b/contrib/coco/core/include/coco/IR/ObjectInfo.h @@ -4,10 +4,13 @@ namespace coco { -class ObjectInfo final +class ObjectInfo { public: ObjectInfo() = default; + +public: + virtual ~ObjectInfo() = default; }; } // namespace coco diff --git a/contrib/coco/core/src/IR/FeatureObject.cpp b/contrib/coco/core/src/IR/FeatureObject.cpp index 7173cd5..42967c4 100644 --- a/contrib/coco/core/src/IR/FeatureObject.cpp +++ b/contrib/coco/core/src/IR/FeatureObject.cpp @@ -25,6 +25,7 @@ FeatureObject::~FeatureObject() // DO NOTHING } +void FeatureObject::get(ObjectInfo **out) const { *out = _info.get(); } void FeatureObject::get(const PtrLink **out) const { *out = _link; } const nncc::core::ADT::feature::Shape &FeatureObject::shape(void) const { return _info->shape(); } diff --git a/contrib/coco/core/src/IR/KernelObject.cpp b/contrib/coco/core/src/IR/KernelObject.cpp index a955263..fcd2c25 100644 --- a/contrib/coco/core/src/IR/KernelObject.cpp +++ b/contrib/coco/core/src/IR/KernelObject.cpp @@ -25,6 +25,7 @@ KernelObject::~KernelObject() // DO NOTHING } +void KernelObject::get(ObjectInfo **out) const { *out = _info.get(); } void KernelObject::get(const PtrLink **out) const { *out = _link; } const nncc::core::ADT::kernel::Shape &KernelObject::shape(void) const { return _info->shape(); } diff --git a/contrib/coco/core/src/IR/Object.test.cpp b/contrib/coco/core/src/IR/Object.test.cpp index 0c34a8f..9a7b084 100644 --- a/contrib/coco/core/src/IR/Object.test.cpp +++ b/contrib/coco/core/src/IR/Object.test.cpp @@ -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 + #include #include +using nncc::foundation::make_unique; + namespace { class ObjectTest : public ::testing::Test @@ -28,9 +33,11 @@ public: virtual ~Object() = default; public: + std::unique_ptr info; const coco::PtrLink *link; private: + void get(coco::ObjectInfo **out) const override { *out = info.get(); } void get(const coco::PtrLink **out) const override { *out = link; } }; } // namespace mock @@ -71,6 +78,7 @@ TEST_F(ObjectTest, bag_update) std::vector updates; DummyObject obj{updates}; + obj.info = make_unique(); obj.link = &link; obj.bag(bag); -- 2.7.4