[coco] Record a backing bag for each object (#758)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Mon, 23 Jul 2018 05:28:46 +0000 (14:28 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Mon, 23 Jul 2018 05:28:46 +0000 (14:28 +0900)
This commit revises 'Object' class to record a backing bag.

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

index e678e05..521dc50 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef __COCO_IR_OBJECT_H__
 #define __COCO_IR_OBJECT_H__
 
+#include "coco/IR/Bag.h"
+
 namespace coco
 {
 
@@ -10,7 +12,17 @@ namespace coco
 class Object
 {
 public:
+  Object();
+
+public:
   virtual ~Object() = default;
+
+private:
+  coco::Bag *_bag;
+
+public:
+  coco::Bag *bag(void) const { return _bag; }
+  void bag(coco::Bag *bag);
 };
 
 } // namespace coco
index c83a9ec..8c3f864 100644 (file)
@@ -1,3 +1,18 @@
 #include "coco/IR/Object.h"
 
-// NOTE Do NOT delete this file; this file checks the completeness of 'Object.h'
+namespace coco
+{
+
+Object::Object() : _bag{nullptr}
+{
+  // DO NOTHING
+}
+
+void Object::bag(coco::Bag *bag)
+{
+  // TODO Update bag-object relation
+  // Q: Should descendant (such as FeatureObject) be aware of bag changes?
+  _bag = bag;
+}
+
+} // namespace coco
diff --git a/contrib/coco/core/src/IR/Object.test.cpp b/contrib/coco/core/src/IR/Object.test.cpp
new file mode 100644 (file)
index 0000000..8d02e77
--- /dev/null
@@ -0,0 +1,22 @@
+#include "coco/IR/Object.h"
+
+#include <gtest/gtest.h>
+
+TEST(IR_OBJECT, ctor)
+{
+  coco::Object obj{};
+
+  // Newly created object should not have a backing bag
+  ASSERT_EQ(obj.bag(), nullptr);
+}
+
+TEST(IR_OBJECT, bag_update)
+{
+  coco::Bag bag{1};
+  coco::Object obj{};
+
+  obj.bag(&bag);
+
+  // 'bag(Bag *)' should affect the return of 'bag(void)'
+  ASSERT_EQ(obj.bag(), &bag);
+}