From 6e81ffa9f5baabe8d4b16fa927ce423fbe26771e Mon Sep 17 00:00:00 2001 From: olpc user Date: Thu, 21 Nov 2019 13:37:18 -0500 Subject: direct cast concept from string --- starts/meaning-vm/concept.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 starts/meaning-vm/concept.cpp (limited to 'starts/meaning-vm/concept.cpp') diff --git a/starts/meaning-vm/concept.cpp b/starts/meaning-vm/concept.cpp new file mode 100644 index 0000000..dc9ecca --- /dev/null +++ b/starts/meaning-vm/concept.cpp @@ -0,0 +1,45 @@ +#include "concept.hpp" + +ref concept::id() +{ + return this; +} + +ref concept::get(ref type) +{ + auto result = links.equal_range(type); + if (result.first == result.second) { + throw std::out_of_range("no such concept link to get"); + } + return result.first->second; +} + +concept::array concept::getAll(ref type) +{ + array ret; + for ( + auto range = links.equal_range(type); + range.first != range.second; + ++ range.first + ) { + ret.push_back(range.first->second); + } + return ret; +} + +void concept::link(ref type, ref target) +{ + links.insert({type, target}); +} + +void concept::unlink(ref type, ref target) +{ + auto ls = links.equal_range(type); + for (auto l = ls.first; l != ls.second; ++ l) { + if (l->second == target) { + links.erase(l); + return; + } + } + throw std::out_of_range("no such concept link to erase"); +} -- cgit v1.2.3