diff options
author | olpc user <olpc@xo-5d-f7-86.localdomain> | 2019-11-24 13:22:55 -0800 |
---|---|---|
committer | olpc user <olpc@xo-5d-f7-86.localdomain> | 2019-11-24 13:22:55 -0800 |
commit | 9a14918abec434d8463e07635daef380ad630649 (patch) | |
tree | fa1a5200da88ad6065092b05dc063a8a80df8faa /starts/meaning-vm/concept.cpp | |
parent | 50be8bb8697b23ff469de142eaebe9666c2a9537 (diff) | |
download | standingwithresilience-9a14918abec434d8463e07635daef380ad630649.tar.gz standingwithresilience-9a14918abec434d8463e07635daef380ad630649.zip |
breaking into levels
Diffstat (limited to 'starts/meaning-vm/concept.cpp')
-rw-r--r-- | starts/meaning-vm/concept.cpp | 79 |
1 files changed, 0 insertions, 79 deletions
diff --git a/starts/meaning-vm/concept.cpp b/starts/meaning-vm/concept.cpp deleted file mode 100644 index 993ac62..0000000 --- a/starts/meaning-vm/concept.cpp +++ /dev/null @@ -1,79 +0,0 @@ -#include "concept.hpp" - -ref concept::id() -{ - return this; -} - -bool concept::linked(ref const & type) const -{ - return links.count(type.ptr) > 0; -} - -bool concept::linked(ref const & type, ref const & target) const -{ - for (ref const & t : getAll(type)) { - if (t == target) { - return true; - } - } - return false; -} - -ref concept::get(ref const & type, bool quick) const -{ - // this is called by name(), so it passes quick=true - auto result = links.equal_range(type.ptr); - if (result.first == result.second) { - if (quick) { - throw std::out_of_range("no such concept link to get"); - } else { - throw std::out_of_range("no such concept link to get: " + (std::string)type.name()); - } - } - return result.first->second; -} - -concept::array concept::getAll(ref const & type) const -{ - array ret; - for ( - auto range = links.equal_range(type.ptr); - range.first != range.second; - ++ range.first - ) { - ret.emplace_back(range.first->second); - } - return ret; -} - -void concept::link(ref const & type, ref const & target) -{ - links.insert({type.ptr, target.ptr}); -} - -void concept::unlink(ref const & type, ref const & target) -{ - auto ls = links.equal_range(type.ptr); - for (auto l = ls.first; l != ls.second; ++ l) { - if (l->second == target.ptr) { - links.erase(l); - return; - } - } - throw std::out_of_range("no such concept link to erase"); -} - -void concept::unlink(ref const & type) -{ - auto ls = links.equal_range(type.ptr); - if (ls.first == ls.second) { - throw std::out_of_range("no such concept link to erase"); - } - auto mid = ls.first; - ++ mid; - if (mid != ls.second) { - throw std::out_of_range("more than one link of type to erase"); - } - links.erase(ls.first); -} |