131 mc = metaclass(
this);
133 for idx = 1:length(mc.Properties)
138 for pidx = 1:length(varargin)
139 if ~ischar(varargin[pidx])
140 error(
" All input arguments must be strings. ");
143 for idx = 1:length(mc.Properties)
144 if strcmp(mc.Properties[idx].Name,varargin[pidx])
145 p = mc.Properties[idx];
152 error(
" Property %s does not exists in class %s. ",varargin[pidx],mc.Name);
153 elseif ~strcmp(p.GetAccess,
" public ")
154 error(
" Property %s has GetAccess=%s, "" public "" is required for registering. ",p.Name,p.GetAccess);
156 error(
" Property %s is marked Constant. ",p.Name,p.GetAccess);
158 error(
" Transient property %s is not admissible. ",p.Name,p.GetAccess);
159 elseif strcmp(p.SetAccess,
" private ")
160 error(
" Property %s has SetAccess=private, at least "" protected "" is required for registering. ",p.Name,p.GetAccess);
163 key = [p.DefiningClass.Name
" . " p.Name];
164 hlp = strtrim(help(key));
166 n = regexp(hlp,
" @propclass{(?<level>\w*)}\s*(?<text>[^@]*) ",
" names ");
171 error(
" Invalid property class: %s ",n.level);
174 if ~any(strcmp(n.level,
" data "))
176 error(
" Non-passive registered property %s must have the SetObservable flag. ",p.Name);
178 addlistener(
this,p.Name,
" PostSet ",@(src,evd)
this.PropPostSetCallback(src,evd));
181 if ~this.PropertiesChanged.containsKey(key)
186 ps.Default= this.(p.Name);
192 ps.Text= strtrim(n.text);
197 error(
" When registering a property you must define the @propclass{<level>} tag in the properties help text. ");
212 function PropPostSetCallback(unused1,evd) {
214 key = [p.DefiningClass.Name
" . " p.Name];
217 warning("
DPCMObject:warning "," PostSet called on property %s but dict does not contain key ",key);
221 this.
PropertiesChanged(key).DefaultConfirmed = isequal(ps.Default,evd.AffectedObject.(p.Name));
235 obj.WorkspaceVariableName= from.WorkspaceVariableName;
236 if isfield(from,
" PropertiesChanged ") && ~isempty(from.PropertiesChanged)
237 obj.PropertiesChanged= from.PropertiesChanged;
238 keys = obj.PropertiesChanged.Keys;
239 for idx = 1:obj.PropertiesChanged.Count
240 ps = obj.PropertiesChanged(keys[idx]);
241 if ~ps.Changed && ~any(strcmp(ps.Level,
" data "))
242 if isprop(obj,ps.Name)
243 addlistener(obj,ps.Name,
" PostSet ",@(src,evd)obj.PropPostSetCallback(src,evd));
245 warning(
" DPCMObject:load ",
" Property %s of DPCMObject #%s (class %s) does not exist anymore.\nRemoving it from ProperitesChanged dictionary. ",ps.Name,obj.ID,
class(obj));
246 obj.PropertiesChanged.clear(keys[idx]);
251 elseif ~isa(obj,
" DPCMObject ")
252 warning(
" DPCM:loadobj ",
" Argument 'obj' not a DPCMObject instance but no argument to initialize from given! ");
275 static function id = generateID() {
278 cnt = round((sum(clock)+cputime)*1000);
280 id = sprintf(" %d ",cnt);
291 static function
charshort = getHelpShort(
char txt) {
292 pos = regexp(txt,sprintf(
" \n[ ]*\n "));
295 short = txt(1:pos(1)-1);
298 pos = strfind(txt,
char(10));
300 short = txt(1:pos(1)-1);
303 short = strtrim(
short);
WorkspaceVariableName
The workspace variable name of this class. Optional.
function registerProps(varargin)
Call this method at any class that defines DPCM observed properties.
static function obj = loadobj(obj, from)
Re-register any registered change listeners!
DPCMObject: Base object for any class participating in the DPCM system.
DPCMObject()
Creates a new DPCM object.
Matlab's base handle class (documentation generation substitute)
DPCM: Default property change monitoring for MatLab class properties.
A variable number of input arguments.
A basic dictionary of key/value pairs for small to medium amounts of data.
ID
An ID that allows to uniquely identify this DPCMObject (at least within the current MatLab session/co...
static const .cell PropClasses
The known property classes.
PropertiesChanged
The Dictionary containing all the property settings as key/value pairs.
Global configuration class for all KerMor run-time settings.
static function KerMor theinstance = App()
The singleton KerMor instance.
addlistener
Creates a listener for the specified event and assigns a callback function to execute when the event ...