diff options
author | olpc user <olpc@xo-5d-f7-86.localdomain> | 2019-11-21 13:37:18 -0500 |
---|---|---|
committer | olpc user <olpc@xo-5d-f7-86.localdomain> | 2019-11-21 13:37:18 -0500 |
commit | 6e81ffa9f5baabe8d4b16fa927ce423fbe26771e (patch) | |
tree | 3abbf34ccf1cb05d26f4a83a8dcf3455aebe1c90 /starts/meaning-vm/concept.cpp | |
parent | 302fc80f638783d17cd3b496284a535044241297 (diff) | |
download | standingwithresilience-6e81ffa9f5baabe8d4b16fa927ce423fbe26771e.tar.gz standingwithresilience-6e81ffa9f5baabe8d4b16fa927ce423fbe26771e.zip |
direct cast concept from string
Diffstat (limited to 'starts/meaning-vm/concept.cpp')
-rw-r--r-- | starts/meaning-vm/concept.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
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"); +} |