[coco] Use std::set to record dependent objects (#968)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Mon, 13 Aug 2018 02:21:17 +0000 (11:21 +0900)
committer오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Mon, 13 Aug 2018 02:21:17 +0000 (11:21 +0900)
This commit revises Bag and BagInfo to use std::set (instead of PtrList)
to record dependent objects.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/coco/core/include/coco/IR/Bag.h
contrib/coco/core/include/coco/IR/BagInfo.h
contrib/coco/core/include/coco/IR/ObjectSet.h [new file with mode: 0644]
contrib/coco/core/src/IR/Bag.cpp
contrib/coco/core/src/IR/Object.test.cpp

index 651550b..38e9a72 100644 (file)
@@ -3,7 +3,7 @@
 
 #include "coco/IR/BagInfo.forward.h"
 
-#include "coco/IR/ObjectList.h"
+#include "coco/IR/ObjectSet.h"
 
 #include <memory>
 
@@ -33,7 +33,7 @@ public:
   uint32_t size(void) const;
 
 public:
-  const ObjectList *object(void) const;
+  const ObjectSet *object(void) const;
 
 public:
   bool isInput(void) const;
index 7f37a13..85ba53b 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef __COCO_IR_BAG_INFO_H__
 #define __COCO_IR_BAG_INFO_H__
 
-#include "coco/IR/ObjectList.h"
+#include "coco/IR/ObjectSet.h"
 
 #include <cstdint>
 
@@ -36,11 +36,11 @@ private:
   uint32_t const _size;
 
 public:
-  ObjectList *object(void) { return &_object; }
-  const ObjectList *object(void) const { return &_object; }
+  ObjectSet *object(void) { return &_object; }
+  const ObjectSet *object(void) const { return &_object; }
 
 private:
-  ObjectList _object;
+  ObjectSet _object;
 
 public:
   BagType type(void) const { return _type; }
diff --git a/contrib/coco/core/include/coco/IR/ObjectSet.h b/contrib/coco/core/include/coco/IR/ObjectSet.h
new file mode 100644 (file)
index 0000000..5b4eb28
--- /dev/null
@@ -0,0 +1,15 @@
+#ifndef __COCO_IR_OBJECT_SET_H__
+#define __COCO_IR_OBJECT_SET_H__
+
+#include "coco/IR/Object.forward.h"
+
+#include <set>
+
+namespace coco
+{
+
+using ObjectSet = std::set<Object *>;
+
+} // namespace coco
+
+#endif // __COCO_IR_OBJECT_SET_H__
index e260b61..fbeb943 100644 (file)
@@ -18,7 +18,7 @@ Bag::~Bag()
 
 uint32_t Bag::size(void) const { return _info->size(); }
 
-const ObjectList *Bag::object(void) const { return _info->object(); }
+const ObjectSet *Bag::object(void) const { return _info->object(); }
 
 bool Bag::isInput(void) const { return _info->type() == BagType::Input; }
 bool Bag::isOutput(void) const { return _info->type() == BagType::Output; }
index 5b0b13a..4403f7c 100644 (file)
@@ -59,9 +59,9 @@ TEST(IR_OBJECT, bag_update)
   auto bag_info = link.find(bag);
 
   ASSERT_EQ(bag_info->object()->size(), 1);
-  ASSERT_EQ(bag_info->object()->at(0), &obj);
+  ASSERT_EQ(bag_info->object()->count(&obj), 1);
 
   // User SHOULD be able to access dependent objects through 'bag'
   ASSERT_EQ(bag->object()->size(), 1);
-  ASSERT_EQ(bag->object()->at(0), &obj);
+  ASSERT_EQ(bag->object()->count(&obj), 1);
 }