17GadgetImpl::~GadgetImpl()
21GadgetImpl::gadget_flags (uint64_t setbits, uint64_t mask)
23 gadget_flags_ &= mask;
24 gadget_flags_ |= setbits;
39GadgetImpl::fallback_name ()
const
45GadgetImpl::canonify_key (
const String &input)
48 if (key.size() && key[0] ==
'.')
56 const String ckey = canonify_key (key);
57 return session_data_[ckey];
63 const String ckey = canonify_key (key);
65 session_data_[ckey] = v;
66 emit_event (
"data", ckey);
71GadgetImpl::type_nick ()
const
73 String tname = Jsonipc::rtti_typename (*
this);
75 if (colon != ssize_t (tname.npos))
76 tname = tname.
substr (colon + 1);
82static CustomDataKey<String> gadget_name_key;
85GadgetImpl::name ()
const
88 return fallback_name();
108 return { begin (props_), end (props_) };
116 emit_event (
"object",
"removed");
135 for (
const PropertyP &prop : props)
144 if (p->ident() == ident)
153 return prop ? prop->value() :
Value {};
160 return prop && prop->value (v);
164 const char *member_typeid_name =
nullptr;
165 ptrdiff_t memb_offset = -1;
167 GadgetImpl::MemberInfosP infosp =
nullptr;
174 const char *class_typeid_name =
nullptr;
176 GadgetImpl::MemberClassT classtest =
nullptr;
184 return fnv1a_consthash64 (m.class_typeid_name);
186 static auto gcml_equal = [] (
const GadgetClassMemberList &a,
const GadgetClassMemberList &b) {
187 return !
strcmp (a.class_typeid_name, b.class_typeid_name);
189 using MemberAccessorSet =
std::unordered_set<GadgetClassMemberList,
decltype (gcml_hash),
decltype (gcml_equal)>;
190 static MemberAccessorSet mas (0, gcml_hash, gcml_equal);
195GadgetImpl::requires_accessor (
const char *ot,
const char *mt, ptrdiff_t offset)
197 auto &cml = cml_set();
198 const GadgetClassMemberList key { .class_typeid_name = ot };
199 auto it = cml.
find (key);
201 for (
const MemberAccessor *maf : it->members)
202 if (!
strcmp (mt, maf->member_typeid_name)) {
210GadgetImpl::register_accessor (
const char *ot,
const char *mt, ptrdiff_t offset, MemberClassT classtest,
211 const Param::ExtraVals &ev, MemberAccessF &&accessfunc,
212 MemberInfosP infosp, uint64_t flags)
214 auto &cml = cml_set();
215 auto [celement, inserted] = cml.emplace (ot, classtest);
217 GadgetClassMemberList *element =
const_cast<GadgetClassMemberList*
> (&*celement);
218 element->members.push_back (
new MemberAccessor {mt, offset, std::move (accessfunc), infosp, ev, flags});
223GadgetImpl::create_properties ()
229 auto &cml = cml_set();
230 for (
const GadgetClassMemberList &ml : cml)
231 if (ml.classtest (*this))
232 for (const MemberAccessor *m : ml.members) {
233 PropertyGetter getter = [
this,m] (Value &value) { m->func (
this,
nullptr, &value); };
234 PropertySetter setter = [
this,m] (
const Value &value) {
return m->func (
this, &value,
nullptr); };
237 String hints = kvpairs_fetch (infos,
"hints");
238 if (m->flags & MemberDetails::READABLE)
240 if (m->flags & MemberDetails::WRITABLE)
242 if (m->flags & MemberDetails::STORAGE)
244 if (m->flags & MemberDetails::GUI)
246 kvpairs_assign (infos,
"hints=" + hints);
247 Param param { .extras = m->ev, .metadata = infos };
248 this->props_.push_back (PropertyImpl::make_shared (param, getter, setter, lister));
T get_custom_data(CustomDataKey< T > *key) const
Retrieve contents of the custom keyed data member, returns DataKey::fallback if nothing was set.
bool has_custom_data(CustomDataKey< T > *key) const
Retrieve wether contents of the custom keyed data member exists.
bool del_custom_data(CustomDataKey< T > *key)
Delete the current contents of the custom keyed data member, invokes DataKey::destroy.
void set_custom_data(CustomDataKey< T > *key, T data)
Assign data to the custom keyed data member, deletes any previously set data.
void emit_notify(const String &detail) override
Emit notify:detail, multiple notifications maybe coalesced if a CoalesceNotifies instance exists.
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.
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.
String string_strip(const String &input)
Strip whitespaces from the left and right of 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.