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 16:15:08 -0800
committerolpc user <olpc@xo-5d-f7-86.localdomain>2019-11-24 16:15:08 -0800
commitdbbed1e4e1d4b3f268c71236c89f1d673fa0c165 (patch)
treefd12a1f4bcb2fe9cc1695787f5e3d992117b9edc /starts/meaning-vm/level-0/ref-mixin.hpp
parentf80b3ce2b52f568bb04005c24ad11c3a05cf7a15 (diff)
downloadstandingwithresilience-dbbed1e4e1d4b3f268c71236c89f1d673fa0c165.tar.gz
standingwithresilience-dbbed1e4e1d4b3f268c71236c89f1d673fa0c165.zip
add a linking mixin for use by ref classes
Diffstat (limited to 'starts/meaning-vm/level-0/ref-mixin.hpp')
-rw-r--r--starts/meaning-vm/level-0/ref-mixin.hpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/starts/meaning-vm/level-0/ref-mixin.hpp b/starts/meaning-vm/level-0/ref-mixin.hpp
new file mode 100644
index 0000000..ba5fe09
--- /dev/null
+++ b/starts/meaning-vm/level-0/ref-mixin.hpp
@@ -0,0 +1,33 @@
+#pragma once
+
+#include <vector>
+
+namespace intellect {
+namespace level0 {
+
+template <typename ref, template<typename> typename vref>
+struct refmixin {
+ 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); }
+
+ bool linked(ref const & type) const { return ptr()->linked(type); }
+ bool linked(ref const & type, ref const & target) const { return ptr()->linked(type, target); }
+
+ array getAll(ref const & type) const { return conv<array>(ptr()->getAll(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); }
+
+ template <typename T>
+ vref<T> vget(ref const & type) const { return conv<vref<T>>(get(type)); }
+
+private:
+ inline concept * ptr() const { return conv<ref*>(this)->ptr; }
+ template <typename OUT, typename IN>
+ static inline OUT conv(IN r) { return *(OUT*)&r; }
+};
+}
+}