--- /dev/null
+#ifndef __COCO_ADT_PTR_LINK_H__
+#define __COCO_ADT_PTR_LINK_H__
+
+#include <map>
+
+#include <cassert>
+
+namespace coco
+{
+
+template<typename From, typename Into> class PtrLink
+{
+public:
+ Into *find(const From *from) const
+ {
+ assert(from != nullptr);
+
+ auto it = _content.find(from);
+ if (it == _content.end())
+ {
+ return nullptr;
+ }
+
+ assert(it->second != nullptr);
+ return it->second;
+ }
+
+public:
+ void set(const From *from, Into *into)
+ {
+ assert(from != nullptr);
+ assert(into != nullptr);
+ assert(_content.find(from) == _content.end());
+
+ _content[from] = into;
+ }
+
+public:
+ void unset(const From *from)
+ {
+ assert(from != nullptr);
+ assert(_content.find(from) != _content.end());
+
+ _content.erase(from);
+ }
+
+private:
+ std::map<const From *, Into *> _content;
+};
+
+} // namespace coco
+
+#endif // __COCO_ADT_PTR_LINK_H__
--- /dev/null
+#include "coco/ADT/PtrLink.h"
+
+#include <gtest/gtest.h>
+
+namespace
+{
+
+class Parent;
+class Child;
+
+class Parent
+{
+public:
+ Parent(coco::PtrLink<Child, Parent> *link) : _link{link}
+ {
+ // DO NOTHING
+ }
+
+public:
+ void link(Child *child)
+ {
+ _link->set(child, this);
+ }
+
+public:
+ void unlink(Child *child)
+ {
+ assert(_link->find(child) == this);
+ _link->unset(child);
+ }
+
+private:
+ coco::PtrLink<Child, Parent> *_link;
+};
+
+class Child
+{
+public:
+ Child(const coco::PtrLink<Child, Parent> *link) : _link{link}
+ {
+ // DO NOTHING
+ }
+
+public:
+ Parent *parent(void) const { return _link->find(this); }
+
+private:
+ const coco::PtrLink<Child, Parent> *_link;
+};
+
+} // namespace
+
+TEST(ADT_PTR_LINK, usecase)
+{
+ // Note that Child has no setter over parent. To update Child's parent, one shuold use
+ // Parent's link and unlink method.
+ //
+ // This restriction prevents incorrect update of parent-child relation.
+ coco::PtrLink<::Child, ::Parent> link;
+
+ ::Parent parent{&link};
+ ::Child child{&link};
+
+ ASSERT_EQ(child.parent(), nullptr);
+ parent.link(&child);
+ ASSERT_EQ(child.parent(), &parent);
+ parent.unlink(&child);
+ ASSERT_EQ(child.parent(), nullptr);
+}