-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added types.untyped.Ref to handle references. Fixed gitignore
Showing
13 changed files
with
354 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
classdef DynamicClass < handle & matlab.mixin.CustomDisplay | ||
properties(Access=protected) | ||
map; | ||
validators; | ||
allowAddProp; | ||
end | ||
|
||
methods | ||
function obj = DynamicClass | ||
obj.map = containers.Map; | ||
obj.schema = containers.Map; | ||
obj.allowAddProp = false; | ||
end | ||
|
||
function validate_property(obj, name, val) | ||
if isKey(obj.schema, name) | ||
feval(obj.schema(name), val); | ||
elseif ~obj.allowAddProp | ||
error('This class does not allow adding properties.'); | ||
end | ||
end | ||
|
||
function export(~, loc_id) | ||
%write namespace and class name | ||
[path, classname, ~] = fileparts(mfilename('fullpath')); | ||
[~, namespacename, ~] = fileparts(path); | ||
h5util.writeAttribute(loc_id, 'namespace', namespacename(2:end), 'string'); | ||
h5util.writeAttribute(loc_id, 'neurodata_type', classname(2:end), 'string'); | ||
end | ||
end | ||
|
||
methods(Sealed, Access=protected) | ||
%% Subsref/Subsasgn Overrides | ||
|
||
function varargout = subsref(obj, s) | ||
if strcmp('{}', s(1).type) | ||
error('subcont only supports ''.'' and ''()'' indexing'); | ||
end | ||
|
||
if length(s) > 1 | ||
[varargout{1:nargout}] = subsref(obj.map(s(1).subs), s(2:end)); | ||
else | ||
varargout{1} = obj.map(s.subs); | ||
end | ||
end | ||
|
||
function obj = subsasgn(obj, s, varargin) | ||
if strcmp('{}', s(1).type) | ||
error('subcont only supports ''.'' and ''()'' indexing'); | ||
end | ||
|
||
if strcmp('()', s(1).type) | ||
obj.validate_property(s.subs, varargin{1}); | ||
obj.map(s.subs{:}) = varargin{1}; | ||
else | ||
if length(s) > 1 | ||
obj.map(s(1).subs) = subsasgn(obj.map(s(1).subs), s(2:end), varargin); | ||
else | ||
obj.validate_property(s.subs, varargin{1}); | ||
obj.map(s.subs) = varargin{1}; | ||
end | ||
end | ||
end | ||
|
||
%% Custom Display Overrides | ||
function displayScalarObject(obj) | ||
if isempty(obj.map) | ||
disp(matlab.mixin.CustomDisplay.getSimpleHeader(obj)); | ||
else | ||
disp([' ' matlab.mixin.CustomDisplay.getClassNameForHeader(obj)... | ||
' with properties:' newline]); | ||
mk = keys(obj.map); | ||
maxwordlen = 0; | ||
for i=1:length(mk) | ||
mklen = length(mk{i}); | ||
if mklen > maxwordlen | ||
maxwordlen = mklen; | ||
end | ||
end | ||
|
||
for i=1:length(mk) | ||
mknm = mk{i}; | ||
val = obj.map(mknm); | ||
if ischar(val) | ||
val = ['''' val '''']; | ||
end | ||
disp([repmat(' ', 1, (maxwordlen - length(mknm)) + 4)... | ||
mknm ': ' strtrim(evalc('disp(val)'))]); | ||
end | ||
disp(' '); | ||
end | ||
end | ||
|
||
function displayNonScalarObject(obj) | ||
disp([strjoin(size(obj), 'x') ' ' getClassNameForHeader(obj)]); | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,70 @@ | ||
classdef Link | ||
properties | ||
filename = ''; | ||
path; | ||
ref; | ||
end | ||
|
||
methods | ||
function obj = Link(path, filename, ref) | ||
obj.path = path; | ||
|
||
if nargin > 1 | ||
obj.filename = filename; | ||
end | ||
|
||
if nargin > 2 | ||
obj.ref = ref; | ||
end | ||
classdef Link < handle | ||
|
||
properties(SetAccess=immutable) | ||
nwb; %nwbfile into which link should be searching | ||
filename; | ||
end | ||
|
||
properties | ||
path; | ||
end | ||
|
||
properties(Hidden, SetAccess=immutable) | ||
type; %type constraint, used by file generation | ||
end | ||
|
||
function export(obj, loc_id, nm) | ||
plist = 'H5P_DEFAULT'; | ||
if isempty(obj.filename) | ||
H5L.create_soft(obj.path, loc_id, nm, plist, plist); | ||
else | ||
H5L.create_external(obj.filename, obj.path, loc_id, nm, plist, plist); | ||
end | ||
methods | ||
function obj = Link(path, context, type) | ||
obj.path = path; | ||
|
||
%if context is char, then it's an external link | ||
%if context is nwbfile then it's a softlink | ||
if ischar(context) | ||
obj.filename = context; | ||
obj.nwb = []; | ||
elseif isa(context, 'nwbfile') | ||
obj.filename = ''; | ||
obj.nwb = context; | ||
else | ||
error('Argument `context` must either be a filename for external links, or a nwbfile for soft links'); | ||
end | ||
|
||
if nargin >= 3 | ||
if ~ischar(type) | ||
error('Argument `type` must be a char array specifying type'); | ||
end | ||
obj.type = type; | ||
end | ||
obj.deref(); | ||
end | ||
|
||
function set.path(obj, val) | ||
if ~ischar(val) | ||
error('Property `path` should be a char array'); | ||
end | ||
obj.path = val; | ||
end | ||
|
||
function refobj = deref(obj) | ||
if isempty(obj.filename) | ||
refobj = io.resolvePath(obj.nwb, obj.path); | ||
if ~isa(refobj, obj.type) | ||
error('Expected link to point to a `%s`. Got `%s`.', obj.type, class(refobj)); | ||
end | ||
else | ||
%there are no guarantees regarding external links so just | ||
%resolve as HDF5 dataset. | ||
refobj = h5read(obj.filename, obj.path); | ||
end | ||
end | ||
|
||
function export(obj, loc_id, nm) | ||
plist = 'H5P_DEFAULT'; | ||
if isempty(obj.filename) | ||
H5L.create_soft(obj.path, loc_id, nm, plist, plist); | ||
else | ||
H5L.create_external(obj.filename, obj.path, loc_id, nm, plist, plist); | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.