diff options
author | olpc user <olpc@xo-5d-f7-86.localdomain> | 2019-11-22 16:56:03 -0800 |
---|---|---|
committer | olpc user <olpc@xo-5d-f7-86.localdomain> | 2019-11-22 16:56:03 -0800 |
commit | c699a8913c5c1e53e0b701109dabe2b8fc70b644 (patch) | |
tree | b8e9d21a28c3ce310ce78ab91a9ce5bdb34ea1c2 /starts/meaning-vm/concept.hpp | |
parent | 8565b47b9e8a59ac06e4f739d63218b0f1e5cb05 (diff) | |
download | standingwithresilience-c699a8913c5c1e53e0b701109dabe2b8fc70b644.tar.gz standingwithresilience-c699a8913c5c1e53e0b701109dabe2b8fc70b644.zip |
while wip, moved concept storage off of helpers
Diffstat (limited to 'starts/meaning-vm/concept.hpp')
-rw-r--r-- | starts/meaning-vm/concept.hpp | 22 |
1 files changed, 21 insertions, 1 deletions
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 <string> #include <vector> +template <typename T> struct vref; struct concept; template <typename T> 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 <typename T> +struct vref +{ + vref(value<T> *p) : ptr(p) { } + value<T>* operator->() { return ptr; } + operator T const &() const { return *ptr; } + + vref(ref const & other) : ptr(static_cast<value<T>*>(other.ptr)) { } + operator ref() { return ptr; } + + // for use by containers + bool operator<(ref const & other) const { return ptr < other.ptr; } + + value<T> * 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 <typename T> + vref<T> vget(ref type) { return get(type); } array getAll(ref type); void link(ref type, ref target); void unlink(ref type, ref target); |