Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 39 additions & 38 deletions +file/fillConstructor.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,28 @@
functionBody = [functionBody newline() bodyString];
end

functionBody = strjoin({functionBody, ...
sprintf('if strcmp(class(obj), ''%s'')', namespace.getFullClassName(name)), ...
% Build final validation/setup block that executes only for the target class,
% with conditional inclusion of mixin setup and dynamic table validation
constructorElements = {functionBody, ...
'', ...
'% Only execute validation/setup code when called directly in this class''s', ...
'% constructor, not when invoked through superclass constructor chain', ...
sprintf('if strcmp(class(obj), ''%s'') %%#ok<STISA>', namespace.getFullClassName(name)), ...
' cellStringArguments = convertContainedStringsToChars(varargin(1:2:end));', ...
' types.util.checkUnset(obj, unique(cellStringArguments));', ...
'end'}, newline());
' types.util.checkUnset(obj, unique(cellStringArguments));'};

% Include the setup function for the HasUnnamedGroups mixin if applicable
if isa(class, 'file.Group') && class.hasAnonGroups
constructorElements{end+1} = ' obj.setupHasUnnamedGroupsMixin();';
end

% insert check for DynamicTable class and child classes
bodyString = fillCheck(name, namespace);
if ~isempty(bodyString)
functionBody = [functionBody newline() bodyString];
% Add custom validation for DynamicTable and its descendant classes
if isDynamicTableDescendant(name, namespace)
constructorElements{end+1} = ' types.util.dynamictable.checkConfig(obj);';
end

constructorElements{end+1} = 'end';
functionBody = strjoin(constructorElements, newline());

functionString = strjoin({...
['function obj = ' name '(varargin)']...
Expand Down Expand Up @@ -169,11 +180,6 @@
fullBody = strjoin(fullBody, newline);
bodystr(end+1:end+length(fullBody)+1) = [newline fullBody];

if isa(class, 'file.Group') && class.hasAnonGroups
% Include the setup function for the HasUnnamedGroups mixin
bodystr = [bodystr, newline, 'obj.setupHasUnnamedGroupsMixin()', newline];
end

parser = {...
'p = inputParser;',...
'p.KeepUnmatched = true;',...
Expand Down Expand Up @@ -209,31 +215,6 @@
bodystr(end+1:end+length(parser)+1) = [newline parser];
end

function checkTxt = fillCheck(name, namespace)
checkTxt = [];

% find if a dynamic table ancestry exists
ancestry = namespace.getRootBranch(name);
isDynamicTableDescendent = false;
for iAncestor = 1:length(ancestry)
ParentRaw = ancestry{iAncestor};
% this is always true, we just use the proper index as typedefs may vary.
typeDefInd = isKey(ParentRaw, namespace.TYPEDEF_KEYS);
isDynamicTableDescendent = isDynamicTableDescendent ...
|| strcmp('DynamicTable', ParentRaw(namespace.TYPEDEF_KEYS{typeDefInd}));
end

if ~isDynamicTableDescendent
return;
end

checkTxt = strjoin({ ...
sprintf('if strcmp(class(obj), ''%s'')', namespace.getFullClassName(name)), ...
' types.util.dynamictable.checkConfig(obj);', ...
'end',...
}, newline);
end

function docString = fillConstructorDocString(name, props, namespace, superClassProps)

classVarName = name; classVarName(1) = lower(classVarName(1));
Expand Down Expand Up @@ -289,6 +270,26 @@
docString = char( strjoin(docString, newline) );
end

function tf = isDynamicTableDescendant(name, namespace)
% Check if name is DynamicTable or if name is for a type that inherits from DynamicTable

tf = false;

if strcmp(name, 'DynamicTable')
tf = true;
return
end

ancestry = namespace.getRootBranch(name);
for iAncestor = 1:length(ancestry)
ParentRaw = ancestry{iAncestor};
% this is always true, we just use the proper index as typedefs may vary.
typeDefInd = isKey(ParentRaw, namespace.TYPEDEF_KEYS);
ancestorName = ParentRaw(namespace.TYPEDEF_KEYS{typeDefInd});
tf = tf || strcmp(ancestorName, 'DynamicTable');
end
end

% Todo: Mostly duplicate code from file.fillProps. Should consolidate
function typeStr = getTypeStr(prop)
if ischar(prop)
Expand Down
10 changes: 7 additions & 3 deletions +tests/+unit/dynamicTableTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,17 @@ function testClearDynamicTableV2_1(testCase)

table = types.core.DynamicTable( ...
'description', 'test table with DynamicTableRegion', ...
'colnames', {'dtr_col_a', 'dtr_col_b'}, ...
'dtr_col_a', 1:4, ...
'dtr_col_b', 5:8, ...
'colnames', {'col_a', 'col_b'}, ...
'col_a', types.core.VectorData('data', (1:4)'), ...
'col_b', types.core.VectorData('data', (5:8)'), ...
'id', types.core.ElementIdentifiers('data', [0; 1; 2; 3]) );

% Verify that vectordata has a length of 2 after adding 2 columns
testCase.verifyEqual(size(table.vectordata), uint64([2,1]))

types.util.dynamictable.clear(table)

% Verify that vectordata has a length of 0 after calling clear
testCase.verifyEqual(size(table.vectordata), uint64([0,1]))

nwbClearGenerated(typesOutputFolder, 'ClearCache',true)
Expand Down
5 changes: 4 additions & 1 deletion +types/+core/AbstractFeatureSeries.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@
misc.parseSkipInvalidName(p, varargin);
obj.feature_units = p.Results.feature_units;
obj.features = p.Results.features;
if strcmp(class(obj), 'types.core.AbstractFeatureSeries')

% Only execute validation/setup code when called directly in this class's
% constructor, not when invoked through superclass constructor chain
if strcmp(class(obj), 'types.core.AbstractFeatureSeries') %#ok<STISA>
cellStringArguments = convertContainedStringsToChars(varargin(1:2:end));
types.util.checkUnset(obj, unique(cellStringArguments));
end
Expand Down
5 changes: 4 additions & 1 deletion +types/+core/AnnotationSeries.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@
p.PartialMatching = false;
p.StructExpand = false;
misc.parseSkipInvalidName(p, varargin);
if strcmp(class(obj), 'types.core.AnnotationSeries')

% Only execute validation/setup code when called directly in this class's
% constructor, not when invoked through superclass constructor chain
if strcmp(class(obj), 'types.core.AnnotationSeries') %#ok<STISA>
cellStringArguments = convertContainedStringsToChars(varargin(1:2:end));
types.util.checkUnset(obj, unique(cellStringArguments));
end
Expand Down
5 changes: 4 additions & 1 deletion +types/+core/BaseImage.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@
addParameter(p, 'description',[]);
misc.parseSkipInvalidName(p, varargin);
obj.description = p.Results.description;
if strcmp(class(obj), 'types.core.BaseImage')

% Only execute validation/setup code when called directly in this class's
% constructor, not when invoked through superclass constructor chain
if strcmp(class(obj), 'types.core.BaseImage') %#ok<STISA>
cellStringArguments = convertContainedStringsToChars(varargin(1:2:end));
types.util.checkUnset(obj, unique(cellStringArguments));
end
Expand Down
8 changes: 5 additions & 3 deletions +types/+core/BehavioralEpochs.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,18 @@
[obj.intervalseries, ivarargin] = types.util.parseConstrained(obj,'intervalseries', 'types.core.IntervalSeries', varargin{:});
varargin(ivarargin) = [];

obj.setupHasUnnamedGroupsMixin()

p = inputParser;
p.KeepUnmatched = true;
p.PartialMatching = false;
p.StructExpand = false;
misc.parseSkipInvalidName(p, varargin);
if strcmp(class(obj), 'types.core.BehavioralEpochs')

% Only execute validation/setup code when called directly in this class's
% constructor, not when invoked through superclass constructor chain
if strcmp(class(obj), 'types.core.BehavioralEpochs') %#ok<STISA>
cellStringArguments = convertContainedStringsToChars(varargin(1:2:end));
types.util.checkUnset(obj, unique(cellStringArguments));
obj.setupHasUnnamedGroupsMixin();
end
end
%% SETTERS
Expand Down
8 changes: 5 additions & 3 deletions +types/+core/BehavioralEvents.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,18 @@
[obj.timeseries, ivarargin] = types.util.parseConstrained(obj,'timeseries', 'types.core.TimeSeries', varargin{:});
varargin(ivarargin) = [];

obj.setupHasUnnamedGroupsMixin()

p = inputParser;
p.KeepUnmatched = true;
p.PartialMatching = false;
p.StructExpand = false;
misc.parseSkipInvalidName(p, varargin);
if strcmp(class(obj), 'types.core.BehavioralEvents')

% Only execute validation/setup code when called directly in this class's
% constructor, not when invoked through superclass constructor chain
if strcmp(class(obj), 'types.core.BehavioralEvents') %#ok<STISA>
cellStringArguments = convertContainedStringsToChars(varargin(1:2:end));
types.util.checkUnset(obj, unique(cellStringArguments));
obj.setupHasUnnamedGroupsMixin();
end
end
%% SETTERS
Expand Down
8 changes: 5 additions & 3 deletions +types/+core/BehavioralTimeSeries.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,18 @@
[obj.timeseries, ivarargin] = types.util.parseConstrained(obj,'timeseries', 'types.core.TimeSeries', varargin{:});
varargin(ivarargin) = [];

obj.setupHasUnnamedGroupsMixin()

p = inputParser;
p.KeepUnmatched = true;
p.PartialMatching = false;
p.StructExpand = false;
misc.parseSkipInvalidName(p, varargin);
if strcmp(class(obj), 'types.core.BehavioralTimeSeries')

% Only execute validation/setup code when called directly in this class's
% constructor, not when invoked through superclass constructor chain
if strcmp(class(obj), 'types.core.BehavioralTimeSeries') %#ok<STISA>
cellStringArguments = convertContainedStringsToChars(varargin(1:2:end));
types.util.checkUnset(obj, unique(cellStringArguments));
obj.setupHasUnnamedGroupsMixin();
end
end
%% SETTERS
Expand Down
5 changes: 4 additions & 1 deletion +types/+core/ClusterWaveforms.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@
obj.waveform_filtering = p.Results.waveform_filtering;
obj.waveform_mean = p.Results.waveform_mean;
obj.waveform_sd = p.Results.waveform_sd;
if strcmp(class(obj), 'types.core.ClusterWaveforms')

% Only execute validation/setup code when called directly in this class's
% constructor, not when invoked through superclass constructor chain
if strcmp(class(obj), 'types.core.ClusterWaveforms') %#ok<STISA>
cellStringArguments = convertContainedStringsToChars(varargin(1:2:end));
types.util.checkUnset(obj, unique(cellStringArguments));
end
Expand Down
5 changes: 4 additions & 1 deletion +types/+core/Clustering.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@
obj.num = p.Results.num;
obj.peak_over_rms = p.Results.peak_over_rms;
obj.times = p.Results.times;
if strcmp(class(obj), 'types.core.Clustering')

% Only execute validation/setup code when called directly in this class's
% constructor, not when invoked through superclass constructor chain
if strcmp(class(obj), 'types.core.Clustering') %#ok<STISA>
cellStringArguments = convertContainedStringsToChars(varargin(1:2:end));
types.util.checkUnset(obj, unique(cellStringArguments));
end
Expand Down
8 changes: 5 additions & 3 deletions +types/+core/CompassDirection.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,18 @@
[obj.spatialseries, ivarargin] = types.util.parseConstrained(obj,'spatialseries', 'types.core.SpatialSeries', varargin{:});
varargin(ivarargin) = [];

obj.setupHasUnnamedGroupsMixin()

p = inputParser;
p.KeepUnmatched = true;
p.PartialMatching = false;
p.StructExpand = false;
misc.parseSkipInvalidName(p, varargin);
if strcmp(class(obj), 'types.core.CompassDirection')

% Only execute validation/setup code when called directly in this class's
% constructor, not when invoked through superclass constructor chain
if strcmp(class(obj), 'types.core.CompassDirection') %#ok<STISA>
cellStringArguments = convertContainedStringsToChars(varargin(1:2:end));
types.util.checkUnset(obj, unique(cellStringArguments));
obj.setupHasUnnamedGroupsMixin();
end
end
%% SETTERS
Expand Down
5 changes: 4 additions & 1 deletion +types/+core/CorrectedImageStack.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@
obj.corrected = p.Results.corrected;
obj.original = p.Results.original;
obj.xy_translation = p.Results.xy_translation;
if strcmp(class(obj), 'types.core.CorrectedImageStack')

% Only execute validation/setup code when called directly in this class's
% constructor, not when invoked through superclass constructor chain
if strcmp(class(obj), 'types.core.CorrectedImageStack') %#ok<STISA>
cellStringArguments = convertContainedStringsToChars(varargin(1:2:end));
types.util.checkUnset(obj, unique(cellStringArguments));
end
Expand Down
5 changes: 4 additions & 1 deletion +types/+core/CurrentClampSeries.m
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@
obj.bias_current = p.Results.bias_current;
obj.bridge_balance = p.Results.bridge_balance;
obj.capacitance_compensation = p.Results.capacitance_compensation;
if strcmp(class(obj), 'types.core.CurrentClampSeries')

% Only execute validation/setup code when called directly in this class's
% constructor, not when invoked through superclass constructor chain
if strcmp(class(obj), 'types.core.CurrentClampSeries') %#ok<STISA>
cellStringArguments = convertContainedStringsToChars(varargin(1:2:end));
types.util.checkUnset(obj, unique(cellStringArguments));
end
Expand Down
5 changes: 4 additions & 1 deletion +types/+core/CurrentClampStimulusSeries.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@
p.PartialMatching = false;
p.StructExpand = false;
misc.parseSkipInvalidName(p, varargin);
if strcmp(class(obj), 'types.core.CurrentClampStimulusSeries')

% Only execute validation/setup code when called directly in this class's
% constructor, not when invoked through superclass constructor chain
if strcmp(class(obj), 'types.core.CurrentClampStimulusSeries') %#ok<STISA>
cellStringArguments = convertContainedStringsToChars(varargin(1:2:end));
types.util.checkUnset(obj, unique(cellStringArguments));
end
Expand Down
5 changes: 4 additions & 1 deletion +types/+core/DecompositionSeries.m
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@
obj.metric = p.Results.metric;
obj.source_channels = p.Results.source_channels;
obj.source_timeseries = p.Results.source_timeseries;
if strcmp(class(obj), 'types.core.DecompositionSeries')

% Only execute validation/setup code when called directly in this class's
% constructor, not when invoked through superclass constructor chain
if strcmp(class(obj), 'types.core.DecompositionSeries') %#ok<STISA>
cellStringArguments = convertContainedStringsToChars(varargin(1:2:end));
types.util.checkUnset(obj, unique(cellStringArguments));
end
Expand Down
5 changes: 4 additions & 1 deletion +types/+core/Device.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@
obj.model_name = p.Results.model_name;
obj.model_number = p.Results.model_number;
obj.serial_number = p.Results.serial_number;
if strcmp(class(obj), 'types.core.Device')

% Only execute validation/setup code when called directly in this class's
% constructor, not when invoked through superclass constructor chain
if strcmp(class(obj), 'types.core.Device') %#ok<STISA>
cellStringArguments = convertContainedStringsToChars(varargin(1:2:end));
types.util.checkUnset(obj, unique(cellStringArguments));
end
Expand Down
5 changes: 4 additions & 1 deletion +types/+core/DeviceModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@
obj.description = p.Results.description;
obj.manufacturer = p.Results.manufacturer;
obj.model_number = p.Results.model_number;
if strcmp(class(obj), 'types.core.DeviceModel')

% Only execute validation/setup code when called directly in this class's
% constructor, not when invoked through superclass constructor chain
if strcmp(class(obj), 'types.core.DeviceModel') %#ok<STISA>
cellStringArguments = convertContainedStringsToChars(varargin(1:2:end));
types.util.checkUnset(obj, unique(cellStringArguments));
end
Expand Down
8 changes: 5 additions & 3 deletions +types/+core/DfOverF.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,18 @@
[obj.roiresponseseries, ivarargin] = types.util.parseConstrained(obj,'roiresponseseries', 'types.core.RoiResponseSeries', varargin{:});
varargin(ivarargin) = [];

obj.setupHasUnnamedGroupsMixin()

p = inputParser;
p.KeepUnmatched = true;
p.PartialMatching = false;
p.StructExpand = false;
misc.parseSkipInvalidName(p, varargin);
if strcmp(class(obj), 'types.core.DfOverF')

% Only execute validation/setup code when called directly in this class's
% constructor, not when invoked through superclass constructor chain
if strcmp(class(obj), 'types.core.DfOverF') %#ok<STISA>
cellStringArguments = convertContainedStringsToChars(varargin(1:2:end));
types.util.checkUnset(obj, unique(cellStringArguments));
obj.setupHasUnnamedGroupsMixin();
end
end
%% SETTERS
Expand Down
5 changes: 4 additions & 1 deletion +types/+core/ElectricalSeries.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@
obj.channel_conversion_axis = p.Results.channel_conversion_axis;
obj.electrodes = p.Results.electrodes;
obj.filtering = p.Results.filtering;
if strcmp(class(obj), 'types.core.ElectricalSeries')

% Only execute validation/setup code when called directly in this class's
% constructor, not when invoked through superclass constructor chain
if strcmp(class(obj), 'types.core.ElectricalSeries') %#ok<STISA>
cellStringArguments = convertContainedStringsToChars(varargin(1:2:end));
types.util.checkUnset(obj, unique(cellStringArguments));
end
Expand Down
5 changes: 4 additions & 1 deletion +types/+core/ElectrodeGroup.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@
obj.device = p.Results.device;
obj.location = p.Results.location;
obj.position = p.Results.position;
if strcmp(class(obj), 'types.core.ElectrodeGroup')

% Only execute validation/setup code when called directly in this class's
% constructor, not when invoked through superclass constructor chain
if strcmp(class(obj), 'types.core.ElectrodeGroup') %#ok<STISA>
cellStringArguments = convertContainedStringsToChars(varargin(1:2:end));
types.util.checkUnset(obj, unique(cellStringArguments));
end
Expand Down
Loading
Loading