summaryrefslogtreecommitdiff
path: root/starts/meaning-vm/concept.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'starts/meaning-vm/concept.hpp')
-rw-r--r--starts/meaning-vm/concept.hpp22
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);