1st of all setter pattern should look like this:
void setSomeProp(const Type &x) {
if (propertyField != x) {
propertyField = x;
somePropChanged(x);
}
}
void setSomeProp(const Type &x) {
if (propertyField != x) {
propertyField = x;
somePropChanged(x);
}
}
To copy to clipboard, switch view to plain text mode
so you don't signal change when noting changes (this also prevents recursion in many cases).
2nd it is assumed that each property has own setter and getter so in coe you should know what property it is.
If you want save on retyping you can define macro:
#define DefStdSetterRef(_className_, _funcName_, _argType_, _propName_) \
void _className_::_funcName_(const _argType_ &x) { \
if (m##_propName_ != x) { \
m##_propName_ = x; \
_propName_##Changed(x); \
} \
}
#define DefStdSetterRef(_className_, _funcName_, _argType_, _propName_) \
void _className_::_funcName_(const _argType_ &x) { \
if (m##_propName_ != x) { \
m##_propName_ = x; \
_propName_##Changed(x); \
} \
}
To copy to clipboard, switch view to plain text mode
Bookmarks