|
1 | 1 | function [args, type] = parseAttributes(filename, attributes, context, Blacklist) |
2 | | -%typename is the type of name if it exists. Empty string otherwise |
3 | | -%args is a containers.Map of all valid attributes |
| 2 | +% parseAttributes - Parse an attribute info structure |
| 3 | +% |
| 4 | +% Syntax: |
| 5 | +% [args, type] = io.parseAttributes(filename, attributes, context, Blacklist) |
| 6 | +% This function parses a given attribute info structure and returns a |
| 7 | +% containers.Map of valid attributes along with neurodata type info if it |
| 8 | +% exists. |
| 9 | +% |
| 10 | +% Input Arguments: |
| 11 | +% filename - The name of the file containing attributes. |
| 12 | +% attributes - The attributes to be parsed. |
| 13 | +% context - The context (h5 location) in which the attributes are located. |
| 14 | +% Blacklist - A list of attributes to be excluded from the parsing. |
| 15 | +% |
| 16 | +% Output Arguments: |
| 17 | +% args - A containers.Map of all valid attributes. |
| 18 | +% type - A structure with type information (see io.getNeurodataTypeInfo) |
| 19 | +% |
| 20 | +% See also: io.getNeurodataTypeInfo |
| 21 | + |
4 | 22 | args = containers.Map; |
5 | | -type = struct('namespace', '', 'name', '', 'typename', ''); |
| 23 | +type = io.getNeurodataTypeInfo(attributes); |
| 24 | + |
6 | 25 | if isempty(attributes) |
7 | 26 | return; |
8 | 27 | end |
9 | | -names = {attributes.Name}; |
10 | | - |
11 | | -typeDefMask = strcmp(names, 'neurodata_type'); |
12 | | -hasTypeDef = any(typeDefMask); |
13 | | -if hasTypeDef |
14 | | - typeDef = attributes(typeDefMask).Value; |
15 | | - if iscellstr(typeDef) |
16 | | - typeDef = typeDef{1}; |
17 | | - end |
18 | | - type.name = typeDef; |
19 | | -end |
20 | 28 |
|
21 | | -namespaceMask = strcmp(names, 'namespace'); |
22 | | -hasNamespace = any(namespaceMask); |
23 | | -if hasNamespace |
24 | | - namespace = attributes(namespaceMask).Value; |
25 | | - if iscellstr(namespace) |
26 | | - namespace = namespace{1}; |
27 | | - end |
28 | | - type.namespace = namespace; |
29 | | -end |
| 29 | +names = {attributes.Name}; |
30 | 30 |
|
31 | | -if hasTypeDef && hasNamespace |
32 | | - validNamespace = misc.str2validName(type.namespace); |
33 | | - validName = misc.str2validName(type.name); |
34 | | - type.typename = ['types.' validNamespace '.' validName]; |
35 | | -end |
| 31 | +% We already got type information (if present), so we add type-specific |
| 32 | +% attributes to the blacklist before parsing the rest of the attribute list |
| 33 | +Blacklist.attributes = [Blacklist.attributes, {'neurodata_type', 'namespace'}]; |
36 | 34 |
|
37 | 35 | blacklistMask = ismember(names, Blacklist.attributes); |
38 | | -deleteMask = typeDefMask | namespaceMask | blacklistMask; |
39 | | -attributes(deleteMask) = []; |
| 36 | +attributes(blacklistMask) = []; |
40 | 37 | for i=1:length(attributes) |
41 | 38 | attr = attributes(i); |
42 | 39 |
|
|
0 commit comments