diff options
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"); +} |