summaryrefslogtreecommitdiff
path: root/starts/meaning-vm/level-0/ref-mixin.hpp
diff options
context:
space:
mode:
authorolpc user <olpc@xo-5d-f7-86.localdomain>2019-11-24 19:23:37 -0800
committerolpc user <olpc@xo-5d-f7-86.localdomain>2019-11-24 19:23:37 -0800
commitcd03e291664cb102bde61d86a15f0add11809766 (patch)
tree9afb4bc872236b95debd5e20daf00797c563c666 /starts/meaning-vm/level-0/ref-mixin.hpp
parentdbbed1e4e1d4b3f268c71236c89f1d673fa0c165 (diff)
downloadstandingwithresilience-cd03e291664cb102bde61d86a15f0add11809766.tar.gz
standingwithresilience-cd03e291664cb102bde61d86a15f0add11809766.zip
messy but works. rushing to get this done with may have been a poor investment.
Diffstat (limited to 'starts/meaning-vm/level-0/ref-mixin.hpp')
-rw-r--r--starts/meaning-vm/level-0/ref-mixin.hpp27
1 files changed, 18 insertions, 9 deletions
diff --git a/starts/meaning-vm/level-0/ref-mixin.hpp b/starts/meaning-vm/level-0/ref-mixin.hpp
index ba5fe09..15e5abe 100644
--- a/starts/meaning-vm/level-0/ref-mixin.hpp
+++ b/starts/meaning-vm/level-0/ref-mixin.hpp
@@ -1,5 +1,6 @@
#pragma once
+#include <map>
#include <vector>
namespace intellect {
@@ -7,25 +8,33 @@ namespace level0 {
template <typename ref, template<typename> typename vref>
struct refmixin {
+ using links_t = std::multimap<ref, ref>;
using array = std::vector<ref>;
- void link(ref const & type, ref const & target) { ptr()->link(type, target); }
- void unlink(ref const & type, ref const & target) { ptr()->unlink(type, target); }
- void unlink(ref const & type) { ptr()->unlink(type); }
+ void link(ref const & type, ref const & target) { p()->link(conv<r>(type), conv<r>(target)); }
+ void unlink(ref const & type, ref const & target) { p()->unlink(conv<r>(type), conv<r>(target)); }
+ void unlink(ref const & type) { p()->unlink(conv<r>(type)); }
- bool linked(ref const & type) const { return ptr()->linked(type); }
- bool linked(ref const & type, ref const & target) const { return ptr()->linked(type, target); }
+ bool linked(ref const & type) const { return p()->linked(conv<r>(type)); }
+ bool linked(ref const & type, ref const & target) const { return p()->linked(conv<r>(type), conv<r>(target)); }
- array getAll(ref const & type) const { return conv<array>(ptr()->getAll(type)); }
+ array getAll(ref const & type) const { return conv<array>(p()->getAll(conv<r>(type))); }
- ref get(ref const & type) const { return conv<ref>(ptr()->get(type)); }
- void set(ref const & type, ref const & target) { ptr()->set(type, target); }
+ links_t & links() const { return *(links_t*)&(p()->links); }
+
+ ref get(ref const & type) const { return conv<ref>(p()->get(conv<r>(type))); }
+ void set(ref const & type, ref const & target) { p()->set(conv<r>(type), conv<r>(target)); }
template <typename T>
vref<T> vget(ref const & type) const { return conv<vref<T>>(get(type)); }
+ bool operator==(ref const & other) const { return self.p() == other.p(); }
+ bool operator!=(ref const & other) const { return self.p() == other.p(); }
+ bool operator<(ref const & other) const { return self.p() < other.p(); }
+
private:
- inline concept * ptr() const { return conv<ref*>(this)->ptr; }
+ inline concept * p() const { return *conv<concept**>(this); }
+ using r = level0::ref;
template <typename OUT, typename IN>
static inline OUT conv(IN r) { return *(OUT*)&r; }
};