Skip to content

Commit 01cf07b

Browse files
committed
Merge branch 'add-mixin-for-type-with-group-properties' into update-tutorials-with-dot-syntax-for-sets
2 parents 6ede4d4 + 0ba9d7a commit 01cf07b

File tree

246 files changed

+8421
-2780
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

246 files changed

+8421
-2780
lines changed

+file/Attribute.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
scalar; %if the value is scalar or an array
1212
dimnames;
1313
shape;
14+
isConstrainedSet;
1415
end
1516

1617
methods
@@ -27,6 +28,8 @@
2728
obj.scalar = true;
2829
obj.shape = {};
2930
obj.dimnames = {};
31+
obj.isConstrainedSet = false; % Always false for attributes
32+
3033

3134
if nargin < 1
3235
return;

+file/Dataset.m

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,15 @@
150150
);
151151

152152
if ~isempty(obj.dtype)
153-
props('data') = obj.dtype;
153+
% Add a value to the props map representing the dataset
154+
% itself. The prop name of a dataset class is always data,
155+
% the type should be empty, and we add a custom doc.
156+
objCopy = obj;
157+
objCopy.name = 'data';
158+
objCopy.isConstrainedSet = false;
159+
objCopy.type = ''; % Reset type, as this now represents a property
160+
objCopy.doc = sprintf('Data property for dataset class (%s)', obj.type);
161+
props('data') = objCopy;
154162
end
155163

156164
if ~isempty(obj.attributes)

+file/Link.m

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
name;
55
required;
66
type;
7+
scalar;
8+
isConstrainedSet
79
end
810

911
methods
@@ -12,14 +14,25 @@
1214
obj.name = [];
1315
obj.required = true;
1416
obj.type = [];
17+
obj.scalar = true;
18+
obj.isConstrainedSet = false;
19+
1520
if nargin < 1
1621
return;
1722
end
23+
24+
% If the name is missing, we use the target type for the name
25+
if isKey(source, 'name')
26+
obj.name = source('name');
27+
else
28+
obj.name = lower(source('target_type'));
29+
obj.isConstrainedSet = true;
30+
end
1831

1932
obj.doc = source('doc');
20-
obj.name = source('name');
2133
obj.type = source('target_type');
2234
obj.required = obj.isRequired(source);
35+
obj.scalar = obj.isScalar(source);
2336
end
2437
end
25-
end
38+
end

+file/fillConstructor.m

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,22 @@
6161
dynamicConstrained = false(size(names));
6262
isAnonymousType = false(size(names));
6363
isAttribute = false(size(names));
64+
isLink = false(size(names));
65+
6466
typenames = repmat({''}, size(names));
65-
varnames = repmat({''}, size(names));
67+
varnames = repmat({''}, size(names)); % necessary? same as names?
6668
for i = 1:length(names)
6769
nm = names{i};
6870
prop = props(nm);
6971

7072
if isa(prop, 'file.Attribute')
7173
isAttribute(i) = true;
72-
continue;
74+
continue
75+
elseif isa(prop, 'file.Link')
76+
isLink(i) = true;
7377
end
7478

75-
if isa(prop, 'file.interface.HasProps')
79+
if isa(prop, 'file.interface.HasProps') || isa(prop, 'file.Link')
7680
isDynamicConstrained = false(size(prop));
7781
isAnon = false(size(prop));
7882
hasType = false(size(prop));
@@ -118,12 +122,32 @@
118122
end
119123
varnames = lower(varnames);
120124

121-
%we delete the entry in varargin such that any conflicts do not show up in inputParser
125+
% We delete parsed elements from varargin such that any conflicts do not
126+
% show up in inputParser
122127
deleteFromVars = 'varargin(ivarargin) = [];';
128+
129+
% Add parsing logic for dynamic constrained links.
130+
% A dynamic constrained link is a subset of dynamic constrained types.
131+
% Their type names are prefixed with 'Link:' to mark them for link-specific
132+
% validation during parsing.
133+
isDynamicConstrainedLink = dynamicConstrained & isLink;
134+
if any(isDynamicConstrainedLink)
135+
constrainedLinkTypes = strcat('Link:', typenames(isDynamicConstrainedLink & ~invalid));
136+
constrainedLinkVars = varnames(isDynamicConstrainedLink & ~invalid);
137+
methodCalls = strcat('[obj.', constrainedLinkVars, ', ivarargin] = ',...
138+
' types.util.parseConstrained(obj, ''', constrainedLinkVars, ''', ''',...
139+
constrainedLinkTypes, ''', varargin{:});');
140+
fullBody = cell(length(methodCalls) * 2,1);
141+
fullBody(1:2:end) = methodCalls;
142+
fullBody(2:2:end) = {deleteFromVars};
143+
fullBody = strjoin(fullBody, newline);
144+
bodystr(end+1:end+length(fullBody)+1) = [newline fullBody];
145+
end
146+
123147
%if constrained/anon sets exist, then check for nonstandard parameters and add as
124148
%container.map
125-
constrainedTypes = typenames(dynamicConstrained & ~invalid);
126-
constrainedVars = varnames(dynamicConstrained & ~invalid);
149+
constrainedTypes = typenames(dynamicConstrained & ~isLink & ~invalid);
150+
constrainedVars = varnames(dynamicConstrained & ~isLink & ~invalid);
127151
methodCalls = strcat('[obj.', constrainedVars, ', ivarargin] = ',...
128152
' types.util.parseConstrained(obj,''', constrainedVars, ''', ''',...
129153
constrainedTypes, ''', varargin{:});');
@@ -135,7 +159,6 @@
135159

136160
%if anonymous values exist, then check for nonstandard parameters and add
137161
%as Anon
138-
139162
anonTypes = typenames(isAnonymousType & ~invalid);
140163
anonVars = varnames(isAnonymousType & ~invalid);
141164
methodCalls = strcat('[obj.', anonVars, ',ivarargin] = ',...

+file/fillExport.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,14 @@
171171
elisionpath = ['[fullpath ''/' elisions ''']'];
172172
end
173173

174-
if (isa(prop, 'file.Group') || isa(prop, 'file.Dataset')) && prop.isConstrainedSet
174+
if isprop(prop, 'isConstrainedSet') && prop.isConstrainedSet
175175
% is a sub-object (with an export function)
176176
dataExportString = ['refs = obj.' name '.export(fid, ' elisionpath ', refs);'];
177177
elseif isa(prop, 'file.Link') || isa(prop, 'file.Group') ||...
178178
(isa(prop, 'file.Dataset') && ~isempty(prop.type))
179179
% obj, loc_id, path, refs
180180
dataExportString = ['refs = obj.' name '.export(fid, ' fullpath ', refs);'];
181-
elseif isa(prop, 'file.Dataset') %untyped dataset
181+
elseif isa(prop, 'file.Dataset') % untyped dataset
182182
options = {};
183183

184184
% special case due to unique behavior of file_create_date
@@ -210,7 +210,7 @@
210210
[sprintf(' %s(fid, %s, %s);', writerStr, fullpath, nameArgs)]...
211211
'end'...
212212
}, newline);
213-
else
213+
else % Attribute
214214
if prop.scalar
215215
forceArrayFlag = '';
216216
else

0 commit comments

Comments
 (0)