#pragma once #include "common.hpp" #include "funcs.hpp" #include "../level-0/ref.hpp" #include namespace intellect { namespace level1 { template struct baseref : public level0::baseref { baseref(concept * p) : level0::baseref(p) { } baseref(level0::ref const & other) : baseref(other.ptr()) { } baseref(std::string const & name, concept* allocator = nullptr) : baseref(getnamed(name, allocator)) { } baseref(const char *name, concept* allocator = nullptr) : baseref(std::string(name), allocator) { } baseref(bool b) : baseref(b ? "true" : "false") { } baseref() : baseref("nothing") { } bool isa(ref group) const { return level1::isa(self, group); } bool isan(ref group) const { return isa(group); } std::string name() const { return getname(self); } explicit operator char const *() const { return getname(self)->data.c_str(); } ref operator-(ref other) const { return hyphenate(self, other); } ref operator[](ref subref) const { return self.get(subref); } template void vset(ref const & type, T const & v) { self.set(type, level1::alloc(level0::concepts::allocations(), v)); } template std::function & fun() { return self.template val>(); } template void fun(std::function const & f) { self.val(f); } template void fun(std::function const & f) { self.val(voidtoret(f)); } template void fget(ref const & type) { return self.template vget>(type); } template void fset(ref const & type, std::function f) { self.vset(type, f); } template void fset(ref const & type, std::function f) { fset(type, voidtoret(f)); } template ref operator()(Ref... args) { return self.template fun()(args...); } std::string dump(ref set) { return level1::dump(self, set); }; private: template std::function voidtoret(std::function f) { return [f](Refs... args) -> ref { std::initializer_list({&args...}); f(args...); return "nothing"; }; } }; } }