[coco] Add 'ElemID' class (#773)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Tue, 24 Jul 2018 06:00:01 +0000 (15:00 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Tue, 24 Jul 2018 06:00:01 +0000 (15:00 +0900)
This commit adds 'ElemID' class to distinguish element IDs from
usual numeric values.

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

diff --git a/contrib/coco/core/include/coco/IR/ElemID.h b/contrib/coco/core/include/coco/IR/ElemID.h
new file mode 100644 (file)
index 0000000..de5676b
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef __COCO_IR_ELEM_ID_H__
+#define __COCO_IR_ELEM_ID_H__
+
+#include <cstdint>
+
+namespace coco
+{
+
+class ElemID final
+{
+public:
+  explicit ElemID(uint32_t value) : _value{value}
+  {
+    // DO NOTHING
+  }
+
+public:
+  uint32_t value(void) const { return _value; }
+
+private:
+  uint32_t const _value;
+};
+
+} // namespace coco
+
+#endif // __COCO_IR_ELEM_ID_H__
diff --git a/contrib/coco/core/src/IR/ElemID.test.cpp b/contrib/coco/core/src/IR/ElemID.test.cpp
new file mode 100644 (file)
index 0000000..188e860
--- /dev/null
@@ -0,0 +1,22 @@
+#include "coco/IR/ElemID.h"
+
+#include <vector>
+
+#include <gtest/gtest.h>
+
+TEST(IR_ELEM_ID, constructor)
+{
+  coco::ElemID id{128};
+
+  ASSERT_EQ(id.value(), 128);
+}
+
+TEST(IR_ELEM_ID, std_vector_compatible)
+{
+  // ElemID SHOULD be compatible with standard container (including std::vector)
+  std::vector<coco::ElemID> vec;
+
+  vec.emplace_back(coco::ElemID{128});
+
+  ASSERT_EQ(vec.at(0).value(), 128);
+}