From fed2ac694bd028d119581ea05a3376e791aee97d Mon Sep 17 00:00:00 2001 From: olpc user Date: Sat, 23 Nov 2019 09:11:28 -0800 Subject: more syntax sugar, building meaning --- starts/meaning-vm/concept.hpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'starts/meaning-vm/concept.hpp') diff --git a/starts/meaning-vm/concept.hpp b/starts/meaning-vm/concept.hpp index e5cddec..c69ff10 100644 --- a/starts/meaning-vm/concept.hpp +++ b/starts/meaning-vm/concept.hpp @@ -15,19 +15,22 @@ struct ref ref(ref const &) = default; concept* operator->() { return ptr; } bool operator==(ref const & that) const { return this->ptr == that.ptr; } + bool operator!=(ref const & that) const { return this->ptr != that.ptr; } bool operator<(ref const &) const { throw std::logic_error("ref has redefined syntax sugar: do not use in containers"); } - // for helpers + // for helpers, mostly names ref(std::string const &); ref(char const * str) : ref(std::string(str)) { } ref(bool b) : ref(b ? "true" : "false") { } ref() : ref("nothing") { } - value & name() const; + value & name() const; // this is a reference so that its char pointer lasts operator const char *() const; - ref operator=(ref other); // helper constructs new concept with this as link - ref operator[](ref links); // helper sets all links from passed concept + // helper linking syntax sugar + ref operator=(ref that); + ref operator<<(ref target); + ref operator[](ref links); bool isa(ref what) const; bool isan(ref what) const; @@ -42,11 +45,13 @@ struct vref value* operator->() { return ptr; } operator T const &() const { return *ptr; } - vref(ref const & other) : ptr(static_cast*>(other.ptr)) { } + vref(T const & val); + + vref(ref const & that) : ptr(static_cast*>(that.ptr)) { } operator ref() { return ptr; } // for use by containers - //bool operator<(ref const & other) const { return ptr < other.ptr; } + //bool operator<(ref const & that) const { return ptr < that.ptr; } value * ptr; }; @@ -60,9 +65,9 @@ struct concept ref id(); bool linked(ref type); bool linked(ref type, ref target); - ref get(ref type); // returns first + ref get(ref type, bool quick = false); // returns first template - vref vget(ref type) { return get(type); } + vref vget(ref type, bool quick = false) { return get(type, quick); } array getAll(ref type); void link(ref type, ref target); void unlink(ref type, ref target); @@ -72,7 +77,7 @@ struct concept template struct value : public concept, public T { - value(T const & val) : T(val) {} + value(T const & val) : T(val) { } value(value const & val) = default; static value& of(ref c) { -- cgit v1.2.3