From eed4c697da8b0d3039d925e3cf96045817e80517 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=A2=85=ED=98=84/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Staff=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Tue, 24 Jul 2018 15:00:01 +0900 Subject: [PATCH] [coco] Add 'ElemID' class (#773) This commit adds 'ElemID' class to distinguish element IDs from usual numeric values. Signed-off-by: Jonghyun Park --- contrib/coco/core/include/coco/IR/ElemID.h | 26 ++++++++++++++++++++++++++ contrib/coco/core/src/IR/ElemID.test.cpp | 22 ++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 contrib/coco/core/include/coco/IR/ElemID.h create mode 100644 contrib/coco/core/src/IR/ElemID.test.cpp diff --git a/contrib/coco/core/include/coco/IR/ElemID.h b/contrib/coco/core/include/coco/IR/ElemID.h new file mode 100644 index 0000000..de5676b --- /dev/null +++ b/contrib/coco/core/include/coco/IR/ElemID.h @@ -0,0 +1,26 @@ +#ifndef __COCO_IR_ELEM_ID_H__ +#define __COCO_IR_ELEM_ID_H__ + +#include + +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 index 0000000..188e860 --- /dev/null +++ b/contrib/coco/core/src/IR/ElemID.test.cpp @@ -0,0 +1,22 @@ +#include "coco/IR/ElemID.h" + +#include + +#include + +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 vec; + + vec.emplace_back(coco::ElemID{128}); + + ASSERT_EQ(vec.at(0).value(), 128); +} -- 2.7.4