From c699a8913c5c1e53e0b701109dabe2b8fc70b644 Mon Sep 17 00:00:00 2001 From: olpc user Date: Fri, 22 Nov 2019 16:56:03 -0800 Subject: while wip, moved concept storage off of helpers --- starts/meaning-vm/concept.hpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'starts/meaning-vm/concept.hpp') diff --git a/starts/meaning-vm/concept.hpp b/starts/meaning-vm/concept.hpp index 2b05f44..7c8fd6d 100644 --- a/starts/meaning-vm/concept.hpp +++ b/starts/meaning-vm/concept.hpp @@ -5,12 +5,14 @@ #include #include +template struct vref; struct concept; template struct value; struct ref { - ref(concept *p) : ptr(p) { } + ref(concept *p) : ptr(p) { if (p == 0) throw std::logic_error("null reference"); } + ref(ref const &) = default; concept* operator->() { return ptr; } // for use by containers @@ -33,6 +35,22 @@ struct ref concept * ptr; }; +template +struct vref +{ + vref(value *p) : ptr(p) { } + value* operator->() { return ptr; } + operator T const &() const { return *ptr; } + + vref(ref const & other) : ptr(static_cast*>(other.ptr)) { } + operator ref() { return ptr; } + + // for use by containers + bool operator<(ref const & other) const { return ptr < other.ptr; } + + value * ptr; +}; + struct concept { // a concept is made of concept-typed links to other concepts @@ -43,6 +61,8 @@ struct concept bool linked(ref type); bool linked(ref type, ref target); ref get(ref type); // returns first + template + vref vget(ref type) { return get(type); } array getAll(ref type); void link(ref type, ref target); void unlink(ref type, ref target); -- cgit v1.2.3