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);
74 String current_name = name();
75 if (xs.
in_save() && current_name != fallback_name())
76 xs[
"name"] & current_name;
77 if (xs.
in_load() && xs.has (
"name"))
80 xs[
"name"] & new_name;
81 if (current_name != new_name)
89 const String hints = p->hints();
109 if (f.name[0] !=
'_' && f.value)
110 cdata[f.name] = *f.value;
112 xs[
"custom_data"] & cdata;
117 xs[
"custom_data"] & cdata;
125GadgetImpl::type_nick ()
const
127 String tname = Jsonipc::rtti_typename (*
this);
129 if (colon != ssize_t (tname.npos))
130 tname = tname.
substr (colon + 1);
136static CustomDataKey<String> gadget_name_key;
139GadgetImpl::name ()
const
142 return fallback_name();
162 return { begin (props_), end (props_) };
181 for (
const PropertyP &prop : props)
190 if (p->ident() == ident)
199 return prop ? prop->value() :
Value {};
206 return prop && prop->value (v);
210 const char *member_typeid_name =
nullptr;
211 ptrdiff_t memb_offset = -1;
213 GadgetImpl::MemberInfosP infosp =
nullptr;
220 const char *class_typeid_name =
nullptr;
222 GadgetImpl::MemberClassT classtest =
nullptr;
230 return fnv1a_consthash64 (m.class_typeid_name);
232 static auto gcml_equal = [] (
const GadgetClassMemberList &a,
const GadgetClassMemberList &b) {
233 return !
strcmp (a.class_typeid_name, b.class_typeid_name);
235 using MemberAccessorSet =
std::unordered_set<GadgetClassMemberList,
decltype (gcml_hash),
decltype (gcml_equal)>;
236 static MemberAccessorSet mas (0, gcml_hash, gcml_equal);
241GadgetImpl::requires_accessor (
const char *ot,
const char *mt, ptrdiff_t offset)
243 auto &cml = cml_set();
244 const GadgetClassMemberList key { .class_typeid_name = ot };
245 auto it = cml.
find (key);
247 for (
const MemberAccessor *maf : it->members)
248 if (!
strcmp (mt, maf->member_typeid_name)) {
256GadgetImpl::register_accessor (
const char *ot,
const char *mt, ptrdiff_t offset, MemberClassT classtest,
257 const Param::ExtraVals &ev, MemberAccessF &&accessfunc,
258 MemberInfosP infosp, uint64_t flags)
260 auto &cml = cml_set();
261 auto [celement, inserted] = cml.emplace (ot, classtest);
263 GadgetClassMemberList *element =
const_cast<GadgetClassMemberList*
> (&*celement);
264 element->members.push_back (
new MemberAccessor {mt, offset, std::move (accessfunc), infosp, ev, flags});
269GadgetImpl::create_properties ()
275 auto &cml = cml_set();
276 for (
const GadgetClassMemberList &ml : cml)
277 if (ml.classtest (*this))
278 for (const MemberAccessor *m : ml.members) {
279 PropertyGetter getter = [
this,m] (Value &value) { m->func (
this,
nullptr, &value); };
280 PropertySetter setter = [
this,m] (
const Value &value) {
return m->func (
this, &value,
nullptr); };
283 String hints = kvpairs_fetch (infos,
"hints");
284 if (m->flags & MemberDetails::READABLE)
286 if (m->flags & MemberDetails::WRITABLE)
288 if (m->flags & MemberDetails::STORAGE)
290 if (m->flags & MemberDetails::GUI)
292 kvpairs_assign (infos,
"hints=" + hints);
293 Param param { .extras = m->ev, .metadata = infos };
294 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.
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.
void serialize(WritNode &xs) override
Serialize members and childern.
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.
virtual void serialize(WritNode &xs)=0
Serialize members and childern.
One entry in a Writ serialization document.
bool in_load() const
Return true during deserialization.
bool in_save() const
Return true during serialization.
#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.
bool string_option_check(const String &optionlist, const String &feature)
Check if an option is set/unset in an options list string.
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.