Skip to content

Commit c963f18

Browse files
authored
Add HasControlledInstance mixin class for use with types that have controlled instances (#38)
* Simplify listInstances function * Update listControlledInstances - Renamed variables - Added arguments block * Add InstanceLibrary singleton * Remove listInstances replaces with InstanceLibrary * remove extra whitespace * Create HasControlledInstance.m
1 parent 26ba40c commit c963f18

File tree

6 files changed

+321
-190
lines changed

6 files changed

+321
-190
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
classdef HasControlledInstance < handle
2+
methods (Static)
3+
function instanceNames = listInstances(type)
4+
% listInstances - List controlled instances of given type
5+
instanceTable = openminds.internal.listControlledInstances(type);
6+
instanceNames = instanceTable.InstanceName;
7+
end
8+
9+
function instance = fromName(name, type)
10+
% fromName - Create metadata object from name of controlled instance
11+
arguments
12+
name (1,1) string
13+
type (1,1) openminds.enum.Types
14+
end
15+
instances = openminds.internal.listControlledInstances(type);
16+
isMatch = instances.InstanceName==string(name);
17+
if any(isMatch)
18+
data = jsondecode(fileread(instances.Filepath(isMatch)));
19+
end
20+
instance = feval(type.ClassName, data);
21+
end
22+
end
23+
end
24+
25+
% Include in subclasses
26+
% methods (Static)
27+
% function instance = fromName(name)
28+
% typeName = mfilename('classname');
29+
% instance = openminds.internal.mixin.HasControlledInstance.fromName(name, typeName);
30+
% end
31+
% function instanceNames = listInstances()
32+
% typeName = mfilename('classname');
33+
% instanceNames = openminds.internal.mixin.HasControlledInstance.listInstances(typeName);
34+
% end
35+
% end

code/internal/+openminds/+internal/+utility/+dir/listInstances.m

Lines changed: 0 additions & 143 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function map = getPluralToSingluarTypeMap()
2+
map = struct(...
3+
"brainAtlasVersions", "BrainAtlasVersion", ...
4+
"brainAtlases", "BrainAtlas", ...
5+
"commonCoordinateSpaceVersions", "CommonCoordinateSpaceVersion", ...
6+
"commonCoordinateSpaces", "CommonCoordinateSpace", ...
7+
"contentTypes", "ContentType", ...
8+
"licenses", "License", ...
9+
"parcellationEntities", "parcellationEntity", ...
10+
"parcellationEntityVersions", "parcellationEntityVersion" ...
11+
);
12+
map = containers.Map(fieldnames(map), struct2cell(map));
13+
end

0 commit comments

Comments
 (0)