forked from NeurodataWithoutBorders/matnwb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateExtension.m
35 lines (33 loc) · 1.3 KB
/
generateExtension.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function generateExtension(varargin)
% GENERATEEXTENSION Generate Matlab classes from NWB extension schema file
% GENERATEEXTENSION(extension_path...) Generate classes
% (Matlab m-files) from one or more NWB:N schema extension namespace
% files. A registry of already generated core types is used to resolve
% dependent types.
%
% A cache of schema data is generated in the 'namespaces' subdirectory in
% the current working directory. This is for allowing cross-referencing
% classes between multiple namespaces.
%
% Output files are generated placed in a '+types' subdirectory in the
% current working directory.
%
% Example:
% generateExtension('schema\myext\myextension.namespace.yaml', 'schema\myext2\myext2.namespace.yaml');
%
% See also GENERATECORE
for i = 1:length(varargin)
source = varargin{i};
validateattributes(source, {'char', 'string'}, {'scalartext'});
[localpath, ~, ~] = fileparts(source);
assert(2 == exist(source, 'file'),...
'NWB:GenerateExtension:FileNotFound', 'Path to file `%s` could not be found.', source);
fid = fopen(source);
namespaceText = fread(fid, '*char') .';
fclose(fid);
Namespace = spec.generate(namespaceText, localpath);
spec.saveCache(Namespace);
file.writeNamespace(Namespace.name);
rehash();
end
end