[coco] Support unlink on Bag (#1000)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Tue, 14 Aug 2018 07:42:39 +0000 (16:42 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Tue, 14 Aug 2018 07:42:39 +0000 (16:42 +0900)
This commit revises Object::bag method to support Bag unlink.

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

index fa2e792..2f2a135 100644 (file)
@@ -16,7 +16,13 @@ void Object::bag(coco::Bag *bag)
 {
   if (_bag != nullptr)
   {
-    throw std::runtime_error{"Bag unlink is not supported, yet"};
+    auto bag_info = _link->find(_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);
index 97656bd..0c34a8f 100644 (file)
@@ -89,4 +89,11 @@ TEST_F(ObjectTest, bag_update)
   // User SHOULD be able to access dependent objects through 'bag'
   ASSERT_EQ(bag->object()->size(), 1);
   ASSERT_EQ(bag->object()->count(&obj), 1);
+
+  // Unlink Object-Bag relation
+  obj.bag(nullptr);
+
+  ASSERT_EQ(obj.bag(), nullptr);
+
+  ASSERT_EQ(bag->object()->size(), 0);
 }