Skip to content

Commit

Permalink
Create local validator function for reftype in file.fillProps
Browse files Browse the repository at this point in the history
- Simplify logic in fillExport
  • Loading branch information
ehennestad committed Nov 8, 2024
1 parent ef2c592 commit 0c0671f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 30 deletions.
10 changes: 3 additions & 7 deletions +file/fillExport.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
for i = 1:length(propertyNames)
propertyName = propertyNames{i};
pathProps = traverseRaw(propertyName, RawClass);
if isempty(pathProps)
keyboard;
end
prop = pathProps{end};
elideProps = pathProps(1:end-1);
elisions = cell(length(elideProps),1);
Expand Down Expand Up @@ -84,11 +81,10 @@
path = {};

if isa(RawClass, 'file.Dataset')
if isempty(RawClass.attributes)
return;
if ~isempty(RawClass.attributes)
matchesAttribute = strcmp({RawClass.attributes.name}, propertyName);
path = {RawClass.attributes(matchesAttribute)};
end
matchesAttribute = strcmp({RawClass.attributes.name}, propertyName);
path = {RawClass.attributes(matchesAttribute)};
return;
end

Expand Down
40 changes: 20 additions & 20 deletions +file/fillProps.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,14 @@
typeStr = ['Table with columns: (', strjoin(columnDocStr, ', '), ')'];
elseif isa(prop, 'file.Attribute')
if isa(prop.dtype, 'containers.Map')
switch prop.dtype('reftype')
case 'region'
refTypeName = 'Region';
case 'object'
refTypeName = 'Object';
otherwise
error('NWB:ClassGenerator:InvalidRefType', ...
'Invalid reftype found while filling description for class property "%s".', propName);
end
typeStr = sprintf('%s Reference to %s', refTypeName, prop.dtype('target_type'));
assertValidRefType(prop.dtype('reftype'))
typeStr = sprintf('%s reference to %s', capitalize(prop.dtype('reftype')), prop.dtype('target_type'));
else
typeStr = prop.dtype;
end
elseif isa(prop, 'containers.Map')
switch prop('reftype')
case 'region'
refTypeName = 'region';
case 'object'
refTypeName = 'object';
otherwise
error('NWB:ClassGenerator:InvalidRefType', ...
'Invalid reftype found while filling description for class property "%s".', propName);
end
typeStr = sprintf('%s Reference to %s', refTypeName, prop('target_type'));
assertValidRefType(prop('reftype'))
typeStr = sprintf('%s reference to %s', capitalize(prop('reftype')), prop('target_type'));
elseif isa(prop, 'file.interface.HasProps')
typeStrCell = cell(size(prop));
for iProp = 1:length(typeStrCell)
Expand Down Expand Up @@ -108,4 +92,20 @@
if nargin >= 2
propStr = [propName ' = ' propStr];
end
end

function assertValidRefType(referenceType)
arguments
referenceType (1,1) string
end
assert( ismember(referenceType, ["region", "object"]), ...
'NWB:ClassGenerator:InvalidRefType', ...
'Invalid reftype found while filling description for class properties.')
end

function word = capitalize(word)
arguments
word (1,:) char
end
word(1) = upper(word(1));
end
2 changes: 1 addition & 1 deletion +types/+hdmf_common/DynamicTableRegion.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

% OPTIONAL PROPERTIES
properties
table; % (Object Reference to DynamicTable) Reference to the DynamicTable object that this region applies to.
table; % (Object reference to DynamicTable) Reference to the DynamicTable object that this region applies to.
end

methods
Expand Down
2 changes: 1 addition & 1 deletion +types/+hdmf_common/VectorIndex.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

% OPTIONAL PROPERTIES
properties
target; % (Object Reference to VectorData) Reference to the target dataset that this index applies to.
target; % (Object reference to VectorData) Reference to the target dataset that this index applies to.
end

methods
Expand Down
2 changes: 1 addition & 1 deletion +types/+hdmf_experimental/EnumData.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

% OPTIONAL PROPERTIES
properties
elements; % (Object Reference to VectorData) Reference to the VectorData object that contains the enumerable elements
elements; % (Object reference to VectorData) Reference to the VectorData object that contains the enumerable elements
end

methods
Expand Down

0 comments on commit 0c0671f

Please sign in to comment.