From: 박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 Date: Fri, 7 Sep 2018 07:38:51 +0000 (+0900) Subject: [coco] Use 'Dep' inside 'Object' (#1406) X-Git-Tag: nncc_backup~1887 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=158b9faeccb22cc8f7267f03884c8017f259fb11;p=platform%2Fcore%2Fml%2Fnnfw.git [coco] Use 'Dep' inside 'Object' (#1406) This commit replaces Bag * inside Object with 'Dep'. Signed-off-by: Jonghyun Park --- diff --git a/contrib/coco/core/include/coco/IR/Object.h b/contrib/coco/core/include/coco/IR/Object.h index cde9132..308e3f7 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/Dep.h" #include "coco/IR/ObjectInfo.forward.h" #include "coco/IR/FeatureObject.forward.h" @@ -42,12 +43,9 @@ protected: virtual void get(ObjectInfo **) const = 0; void setBagLink(const PtrLink *); -private: - coco::Bag *_bag; - public: - coco::Bag *bag(void) const { return _bag; } - void bag(coco::Bag *bag); + coco::Bag *bag(void) const { return _dep.bag(); } + void bag(coco::Bag *bag) { _dep.bag(bag); } public: virtual FeatureObject *asFeature(void) { return nullptr; } @@ -58,14 +56,13 @@ public: private: ObjectInfo *info(void) const; - BagInfo *info(const Bag *) const; public: Def *def(void) const; const User *user(void) const; private: - const PtrLink *_bag_link; + Dep _dep; }; } // namespace coco diff --git a/contrib/coco/core/src/IR/Object.cpp b/contrib/coco/core/src/IR/Object.cpp index 838c06c..2fca0cc 100644 --- a/contrib/coco/core/src/IR/Object.cpp +++ b/contrib/coco/core/src/IR/Object.cpp @@ -8,38 +8,13 @@ namespace coco { -Object::Object() : _bag{nullptr} +Object::Object() { - // DO NOTHING + // Register self to Dep + _dep.object(this); } -void Object::setBagLink(const PtrLink *bag_link) { _bag_link = bag_link; } - -void Object::bag(coco::Bag *bag) -{ - if (_bag != nullptr) - { - auto bag_info = info(_bag); - assert(bag_info != nullptr); - assert(bag_info->object()->find(this) != bag_info->object()->end()); - - bag_info->object()->erase(this); - - _bag = nullptr; - } - - assert(_bag == nullptr); - - if (bag != nullptr) - { - // TODO Update bag-object relation - _bag = bag; - - auto bag_info = info(_bag); - assert(bag_info != nullptr); - bag_info->object()->insert(this); - } -} +void Object::setBagLink(const PtrLink *bag_link) { _dep.link(bag_link); } ObjectInfo *Object::info(void) const { @@ -48,12 +23,6 @@ ObjectInfo *Object::info(void) const return res; } -BagInfo *Object::info(const Bag *bag) const -{ - assert(_bag_link != nullptr); - return _bag_link->find(bag); -} - Object::Def *Object::def(void) const { return info()->def(); } const Object::User *Object::user(void) const { return info()->user(); } diff --git a/contrib/coco/core/src/IR/Object.test.cpp b/contrib/coco/core/src/IR/Object.test.cpp index 2305bbe..6a236c8 100644 --- a/contrib/coco/core/src/IR/Object.test.cpp +++ b/contrib/coco/core/src/IR/Object.test.cpp @@ -91,3 +91,21 @@ TEST_F(ObjectTest, bag_update) ASSERT_EQ(bag->object()->size(), 0); } + +TEST_F(ObjectTest, destructor) +{ + auto bag = bag_mgr.create(1); + + // Destruct Object after proper initialization + { + ::mock::Object obj; + + obj.info = make_unique(); + obj.link(&link); + + obj.bag(bag); + } + + // Object SHOULD be unlinked from Bag on destruction + ASSERT_EQ(bag->object()->size(), 0); +}