This repository has been archived by the owner on Apr 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 167
/
toolkit_version.m
77 lines (57 loc) · 2.08 KB
/
toolkit_version.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
function version = toolkit_version(compare)
% toolkit_version Version information for the toolkit, compare
% versions
%
% Returns version information for the toolkit.
%
% Input:
% - compare (string, optional): a version to compare against, if set
% then the string is parsed and compared against toolkit version,
% -1 is returned if it is lower, 1 if higher and 0 if equal.
%
% Output:
% - version (structure): Structure containing version information.
% - major (integer): Major version of the toolkit
% - minor (integer): Minor version of the toolkit
% - patch (integer): Patch version of the toolkit
version = get_global_variable('toolkit_version');
if isempty(version)
version = struct('major', 0, 'minor', 0, 'patch', 0);
try
root = fileparts(mfilename('fullpath'));
tokens = strsplit(fileread(fullfile(root, 'VERSION')), '.');
version.major = int32(str2double(tokens{1}));
version.minor = int32(str2double(tokens{2}));
version.patch = int32(str2double(tokens{3}));
set_global_variable('toolkit_version', version);
catch
error('Unable to parse version file');
end
end;
if nargin > 0
tokens = strsplit(strtrim(compare), '.');
compare = struct('major', 0, 'minor', 0, 'patch', 0);
if numel(compare) < 1
error('Illegal version');
end;
try
if numel(tokens) > 0
compare.major = int32(str2double(tokens{1}));
end
if numel(tokens) > 1
compare.minor = int32(str2double(tokens{2}));
end
if numel(tokens) > 2
compare.patch = int32(str2double(tokens{3}));
end
catch
error('Unable to parse version string');
end
if version.major > compare.major; version = -1; return; end;
if version.major < compare.major; version = 1; return; end;
if version.minor > compare.minor; version = -1; return; end;
if version.minor < compare.minor; version = 1; return; end;
if version.patch > compare.patch; version = -1; return; end;
if version.patch < compare.patch; version = 1; return; end;
version = 0;
end