classdef MyClass < nelson.mixin.indexing.RedefinesDot
| Parameter | Description |
|---|---|
| obj | an object of a class deriving from nelson.mixin.indexing.RedefinesDot. |
| Parameter | Description |
|---|---|
| obj | an object supporting customized dot indexing. |
Derive from nelson.mixin.indexing.RedefinesDot to give a class its own dot indexing behavior for names that are not declared properties or methods. A subclass implements the protected methods dotReference(obj, indexOp) (value of obj.name), dotAssign(obj, indexOp, value) (obj.name = value) and dotListLength(obj, indexOp, indexContext).
indexOp is a nelson.indexing.IndexingOperation whose Name property holds the accessed name. Declared properties and methods keep their normal behavior; only unknown names call dotReference/dotAssign.
classdef Bag < nelson.mixin.indexing.RedefinesDot
properties (Access = private)
Store
end
methods
function obj = Bag()
obj.Store = struct();
end
end
methods (Access = protected)
function varargout = dotReference(obj, indexOp)
varargout{1} = obj.Store.(indexOp.Name);
end
function obj = dotAssign(obj, indexOp, val)
obj.Store.(indexOp.Name) = val;
end
function n = dotListLength(obj, indexOp, ctx)
n = 1;
end
end
end
| Version | Description |
|---|---|
| 2.0.0 | initial version |