17GadgetImpl::~GadgetImpl()
21GadgetImpl::gadget_flags (uint64_t setbits, uint64_t mask)
23 gadget_flags_ &= mask;
24 gadget_flags_ |= setbits;
39GadgetImpl::canonify_key (
const String &input)
42 if (key.
size() && key[0] ==
'.')
50 const String ckey = canonify_key (key);
51 return session_data_[ckey];
57 const String ckey = canonify_key (key);
59 session_data_[ckey] = v;
60 emit_event (
"data", ckey);
65GadgetImpl::type_nick ()
const
67 String tname = Jsonipc::rtti_typename (*
this);
69 if (colon != ssize_t (tname.npos))
70 tname = tname.
substr (colon + 1);
81 return { begin (props_), end (props_) };
89 emit_event (
"object",
"removed");
114 for (
const PropertyP &prop : props)
123 if (p->ident() == ident)
132 return prop ? prop->value() :
Value {};
139 return prop && prop->value (v);
143 const char *member_typeid_name =
nullptr;
144 ptrdiff_t memb_offset = -1;
146 GadgetImpl::MemberInfosP infosp =
nullptr;
153 const char *class_typeid_name =
nullptr;
155 GadgetImpl::MemberClassT classtest =
nullptr;
163 return fnv1a_consthash64 (m.class_typeid_name);
165 static auto gcml_equal = [] (
const GadgetClassMemberList &a,
const GadgetClassMemberList &b) {
166 return !
strcmp (a.class_typeid_name, b.class_typeid_name);
168 using MemberAccessorSet =
std::unordered_set<GadgetClassMemberList,
decltype (gcml_hash),
decltype (gcml_equal)>;
169 static MemberAccessorSet mas (0, gcml_hash, gcml_equal);
174GadgetImpl::requires_accessor (
const char *ot,
const char *mt, ptrdiff_t offset)
176 auto &cml = cml_set();
177 const GadgetClassMemberList key { .class_typeid_name = ot };
178 auto it = cml.
find (key);
180 for (
const MemberAccessor *maf : it->members)
181 if (!
strcmp (mt, maf->member_typeid_name)) {
189GadgetImpl::register_accessor (
const char *ot,
const char *mt, ptrdiff_t offset, MemberClassT classtest,
190 const Param::ExtraVals &ev, MemberAccessF &&accessfunc,
191 MemberInfosP infosp, uint64_t flags)
193 auto &cml = cml_set();
194 auto [celement, inserted] = cml.emplace (ot, classtest);
196 GadgetClassMemberList *element =
const_cast<GadgetClassMemberList*
> (&*celement);
197 element->members.push_back (
new MemberAccessor {mt, offset, std::move (accessfunc), infosp, ev, flags});
202GadgetImpl::create_properties ()
208 auto &cml = cml_set();
209 for (
const GadgetClassMemberList &ml : cml)
210 if (ml.classtest (*this))
211 for (const MemberAccessor *m : ml.members) {
212 PropertyGetter getter = [
this,m] (Value &value) { m->func (
this,
nullptr, &value); };
213 PropertySetter setter = [
this,m] (
const Value &value) {
return m->func (
this, &value,
nullptr); };
216 String hints = kvpairs_fetch (infos,
"hints");
217 if (m->flags & MemberDetails::READABLE)
219 if (m->flags & MemberDetails::WRITABLE)
221 if (m->flags & MemberDetails::STORAGE)
223 if (m->flags & MemberDetails::GUI)
225 kvpairs_assign (infos,
"hints=" + hints);
226 Param param { .extras = m->ev, .metadata = infos };
227 this->props_.push_back (PropertyImpl::make_shared (param, getter, setter, lister));
Base type for classes that have a Property.
void remove_self() override
Remove self from parent container.
PropertyS access_properties() override
Retrieve handles for all properties.
Value get_data(const String &key) const override
Retrieve session data.
bool set_data(const String &key, const Value &v) override
Assign session data, prefix ephemerals with '_'.
void _set_parent(GadgetImpl *parent) override
Assign parent container.
Base type for classes that have a Property.
virtual StringS list_properties()
List all property identifiers.
virtual PropertyP access_property(String ident)
Retrieve handle for a Property.
virtual PropertyS access_properties()=0
Retrieve handles for all properties.
ProjectImpl * _project() const
Find Project in parent ancestry.
virtual GadgetImpl * _parent() const =0
Retrieve parent container.
virtual StringS read_only_properties() const
List x()/x (v) properties that this object can't change, their setters ignore the value or warn.
Value get_value(String ident)
Get native property value.
bool set_value(String ident, const Value &v)
Set native property value.
#define assert_return(expr,...)
Return from the current function if expr is unmet and issue an assertion warning.
#define return_unless(cond,...)
Return silently if cond does not evaluate to true with return value ...
The Anklang C++ API namespace.
std::vector< String > StringS
Convenience alias for a std::vector<std::string>.
std::function< ChoiceS(const ParameterProperty &)> PropertyLister
Function type to list Choice Property values.
const String & string_set_a2z()
Returns a string containing all of a-z.
std::string String
Convenience alias for std::string.
String string_canonify(const String &string, const String &valid_chars, const String &substitute)
Enforce a canonical charset for a string.
const String & string_set_A2Z()
Returns a string containing all of A-Z.
std::function< void(Value &)> PropertyGetter
Function type for Property value getters.
bool string_endswith(const String &string, const String &fragment)
Returns whether string ends with fragment.
std::function< bool(const Value &)> PropertySetter
Function type for Property value setters.
Value type used to interface with various property types.