mirror of
https://github.com/alkoleft/yaxunit-addin.git
synced 2026-06-16 07:35:40 +02:00
Simpile adding of properties
Co-authored-by: infactum <infactum@gmail.com>
This commit is contained in:
+3
-6
@@ -282,14 +282,11 @@ bool Component::ExternalEvent(const std::string &src, const std::string &msg, co
|
||||
}
|
||||
|
||||
void Component::AddProperty(const std::wstring &alias, const std::wstring &alias_ru,
|
||||
bool is_readable, bool is_writable,
|
||||
std::function<std::shared_ptr<variant_t>(void)> getter,
|
||||
std::function<void(variant_t &&)> setter) {
|
||||
|
||||
if ((is_readable && !getter) || (is_writable && !setter)) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool is_readable = static_cast<bool>(getter);
|
||||
bool is_writable = static_cast<bool>(setter);
|
||||
PropertyMeta meta{alias, alias_ru, is_readable, is_writable, std::move(getter), std::move(setter)};
|
||||
properties_meta.push_back(std::move(meta));
|
||||
|
||||
@@ -302,7 +299,7 @@ void Component::AddProperty(const std::wstring &alias, const std::wstring &alias
|
||||
return;
|
||||
}
|
||||
|
||||
AddProperty(alias, alias_ru, true, true,
|
||||
AddProperty(alias, alias_ru,
|
||||
[storage]() { // getter
|
||||
return storage;
|
||||
},
|
||||
|
||||
@@ -104,7 +104,6 @@ protected:
|
||||
bool ExternalEvent(const std::string &src, const std::string &msg, const std::string &data);
|
||||
|
||||
void AddProperty(const std::wstring &alias, const std::wstring &alias_ru,
|
||||
bool is_readable, bool is_writable,
|
||||
std::function<std::shared_ptr<variant_t>(void)> getter = nullptr,
|
||||
std::function<void(variant_t &&)> setter = nullptr);
|
||||
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ SampleAddIn::SampleAddIn() {
|
||||
AddProperty(L"SampleProperty", L"ОбразецСвойства", sample_property);
|
||||
|
||||
// Full featured property registration example
|
||||
AddProperty(L"Version", L"ВерсияКомпоненты", true, false, [&]() {
|
||||
AddProperty(L"Version", L"ВерсияКомпоненты", [&]() {
|
||||
auto s = std::string(Version);
|
||||
return std::make_shared<variant_t>(std::move(s));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user