|
3 | 3 | properties (SetAccess=immutable) |
4 | 4 | ClassName (1,1) string |
5 | 5 | AliasClassName (1,1) string |
| 6 | + TypeURI (1,1) string |
6 | 7 | end |
7 | 8 |
|
8 | 9 | methods |
9 | 10 | function obj = TypesEnumeration(name) |
10 | 11 | obj.ClassName = name; |
11 | 12 | obj.AliasClassName = obj.createAliasClassName(); |
| 13 | + obj.TypeURI = obj.getTypeURI(); |
12 | 14 | end |
13 | 15 | end |
14 | 16 |
|
|
38 | 40 | aliasClassName = strjoin(classNameParts([1,2,end]), '.'); |
39 | 41 | end |
40 | 42 | end |
| 43 | + |
| 44 | + function typeURI = getTypeURI(obj) |
| 45 | + if obj.ClassName == "None" |
| 46 | + typeURI = "None"; |
| 47 | + else |
| 48 | + typeURI = eval(sprintf('%s.X_TYPE', obj.ClassName)); |
| 49 | + end |
| 50 | + end |
41 | 51 | end |
42 | 52 |
|
43 | 53 | methods (Static) |
44 | 54 | function typeEnum = fromClassName(className) |
45 | | - |
46 | | - if ischar(className) |
47 | | - className = string(className); |
| 55 | + % fromClassName - Get a Type enum from a class name |
| 56 | + % |
| 57 | + % Syntax: |
| 58 | + % typeEnum = openminds.enum.Types.fromClassName(className) Converts |
| 59 | + % the provided class name(s) into the appropriate enumeration value (s). |
| 60 | + % |
| 61 | + % Input Arguments: |
| 62 | + % className - A string array representing the class name(s) to be |
| 63 | + % converted. |
| 64 | + % |
| 65 | + % Output Arguments: |
| 66 | + % typeEnum - The corresponding enumeration value(s) from |
| 67 | + % openminds.enum.Types. |
| 68 | + % |
| 69 | + % Example: |
| 70 | + % |
| 71 | + % openminds.enum.Types.fromClassName("openminds.core.Person") |
| 72 | + % |
| 73 | + % ans = |
| 74 | + % |
| 75 | + % Types enumeration |
| 76 | + % |
| 77 | + % Person |
| 78 | + |
| 79 | + arguments |
| 80 | + className (1,:) string |
48 | 81 | end |
49 | 82 |
|
50 | 83 | if numel(className) > 1 |
51 | | - if iscell(className); className = string(className); end |
52 | 84 | typeEnum = arrayfun(@(str) openminds.enum.Types.fromClassName(str), className); |
53 | 85 | return |
54 | 86 | end |
55 | 87 |
|
56 | 88 | splitName = strsplit(className, '.'); |
57 | 89 | typeEnum = openminds.enum.Types(splitName{end}); |
58 | 90 | end |
| 91 | + |
| 92 | + function typeEnum = fromAtType(typeName) |
| 93 | + % fromAtType - Convert an @type string to its corresponding enumeration. |
| 94 | + % |
| 95 | + % Syntax: |
| 96 | + % typeEnum = openminds.enum.Types.fromAtType(typeName) Converts the |
| 97 | + % provided @type string into the appropriate enumeration value. |
| 98 | + % |
| 99 | + % Input Arguments: |
| 100 | + % typeName - A string array representing the @type to be converted. |
| 101 | + % The @type URI is expected to match Base URI for the |
| 102 | + % currently active openMINDS version |
| 103 | + % |
| 104 | + % Output Arguments: |
| 105 | + % typeEnum - The corresponding enumeration value(s) from |
| 106 | + % openminds.enum.Types. |
| 107 | + % |
| 108 | + % Example: |
| 109 | + % |
| 110 | + % openminds.enum.Types.fromAtType("https://openminds.om-i.org/types/Person") |
| 111 | + % |
| 112 | + % ans = |
| 113 | + % |
| 114 | + % Types enumeration |
| 115 | + % |
| 116 | + % Person |
| 117 | + |
| 118 | + arguments |
| 119 | + typeName (1,:) string |
| 120 | + end |
| 121 | + |
| 122 | + assert(all(startsWith(typeName, openminds.constant.BaseURI)), ... |
| 123 | + 'OPENMINDS_MATLAB:Types:InvalidAtType', ... |
| 124 | + 'Expected @type to start with "%s"', openminds.constant.BaseURI) |
| 125 | + |
| 126 | + if numel(typeName) > 1 |
| 127 | + typeEnum = arrayfun(@(str) openminds.enum.Types.fromAtType(str), typeName); |
| 128 | + return |
| 129 | + end |
| 130 | + |
| 131 | + splitName = strsplit(typeName, '/'); |
| 132 | + typeEnum = eval(sprintf('openminds.enum.Types.%s', splitName{end})); |
| 133 | + end |
59 | 134 | end |
60 | 135 | end |
0 commit comments