From c8bb547bea279af2bb48c13260f98aa8add07131 Mon Sep 17 00:00:00 2001 From: olpc user Date: Fri, 10 Jan 2020 14:55:19 -0800 Subject: move intellect-framework-from-internet into folder --- starts/meaning-vm/level-0/baseref.hpp | 169 ---------------------------------- 1 file changed, 169 deletions(-) delete mode 100644 starts/meaning-vm/level-0/baseref.hpp (limited to 'starts/meaning-vm/level-0/baseref.hpp') diff --git a/starts/meaning-vm/level-0/baseref.hpp b/starts/meaning-vm/level-0/baseref.hpp deleted file mode 100644 index 5c84279..0000000 --- a/starts/meaning-vm/level-0/baseref.hpp +++ /dev/null @@ -1,169 +0,0 @@ -#pragma once - -#include "common.hpp" -#include "errors.hpp" -#include "memorystore.hpp" - -#include -#include - -namespace intellect { -namespace level0 { - -template -class baseref -{ -public: - struct array; struct links_t; - baseref(concept *p) - : p(p) - { - if (p == 0) { - throw null_reference(); - } - } - - baseref & operator=(concept *p) - { - self.p = p; - return self; - } - - ref link(ref const & type, ref const & target) { p->link(type.p, target.p); return ptr(); } - void unlink(ref const & type, ref const & target) { p->unlink(type.p, target.p); } - void unlink(ref const & type) { p->unlink(type.p); } - - bool linked(ref const & type) const { return p->linked(type.p); } - bool linked(ref const & type, ref const & target) const { return p->linked(type.p, target.p); } - - ref get(ref const & type) const { return p->get(type.p); } - void set(ref const & type, ref const & target) { p->set(type.p, target.p); } - - array getAll(ref const & type) const; - links_t links() const; - - template - ref link(Ref... refspack) - { - std::initializer_list refs{refspack...}; - for (auto it = refs.begin(); it != refs.end();) { - ref type = *it++; - ref target = *it++; - link(type, target); - } - return ptr(); - } - - template - T& vget(ref const & type) const { return p->vget(type.p); } - template - void vset(ref const & type, T const & v) { p->set(type.p, level0::alloc(self, v)); } - - template - T& val() { return p->val(); } - template - void val(T const & v) { p->val(v); } - bool hasval() { return p->hasval(); } - template - bool hasvalof() { return p->hasvalof(); } - - operator concept*() const { return p; } - concept*& ptr() { return p; } - concept* const & ptr() const { return p; } - - operator level0::ref const &() const { return *reinterpret_cast(this); } - operator level1::ref const &() const { return *reinterpret_cast(this); } - operator level2::ref const &() const { return *reinterpret_cast(this); } - operator level3::ref const &() const { return *reinterpret_cast(this); } - operator level4::ref const &() const { return *reinterpret_cast(this); } - operator level5::ref const &() const { return *reinterpret_cast(this); } - operator level6::ref const &() const { return *reinterpret_cast(this); } - operator level7::ref const &() const { return *reinterpret_cast(this); } - operator level8::ref const &() const { return *reinterpret_cast(this); } - operator level9::ref const &() const { return *reinterpret_cast(this); } - - operator level0::ref &() { return *reinterpret_cast(this); } - operator level1::ref &() { return *reinterpret_cast(this); } - operator level2::ref &() { return *reinterpret_cast(this); } - operator level3::ref &() { return *reinterpret_cast(this); } - operator level4::ref &() { return *reinterpret_cast(this); } - operator level5::ref &() { return *reinterpret_cast(this); } - operator level6::ref &() { return *reinterpret_cast(this); } - operator level7::ref &() { return *reinterpret_cast(this); } - operator level8::ref &() { return *reinterpret_cast(this); } - operator level9::ref &() { return *reinterpret_cast(this); } - - 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; } - - bool crucial() { return self.p->crucial(); } - bool crucial(ref type, ref target) { return self.p->crucial(type.p, target.p); } - - void setcrucial() { self.p->setcrucial(); } - void setcrucial(ref type, ref target) { self.p->setcrucial(type.p, target.p); } - -protected: - concept * p; - -private: - template - struct mutated_it - { - mutated_it(It const & it) : it(it) { } - - using mutit = mutated_it; - - mutit & operator++() { ++ self.it; return self; } - mutit operator++(int i) { return self.it.operator++(i); } - mutit & operator--() { -- self.it; return self; } - mutit operator--(int i) { return self.it.operator--(i); } - bool operator==(mutit const & other) const { return self.it == other.it; } - bool operator!=(mutit const & other) const { return self.it != other.it; } - - val & operator*() { return *(val*)&self.it.operator*(); } - val * operator->() { return (val*)self.it.operator->(); } - - It & underlying() { return it; } - - private: - It it; - }; - -public: - struct array - { - using iterator = mutated_it; - iterator begin() { return array.begin(); } - iterator end() { return array.end(); } - - typename concept::array array; - }; - - struct links_t - { - using iterator = mutated_it,typename decltype(concept::links)::iterator>; - iterator begin() { return links.begin(); } - iterator end() { return links.end(); } - - decltype(concept::links) & links; - }; - - void unlink(typename links_t::iterator it) { p->unlink(it.underlying()); } - bool crucial(typename links_t::iterator it) { return self.p->crucial(it.underlying()); } - void setcrucial(typename links_t::iterator it) { self.p->setcrucial(it.underlying()); } -}; - -template -typename baseref::array baseref::getAll(ref const & type) const -{ - return {p->getAll(type.p)}; -} -template -typename baseref::links_t baseref::links() const -{ - return {p->links}; -} - -} -} -- cgit v1.2.3