|
| 1 | +% nix.File class grants access to all NIX operations. |
| 2 | +% |
| 3 | +% A File represents a specific data source of a NIX back-end for example an NIX HDF5 file. |
| 4 | +% All entities of the nix data model (except the Value entity) must exist in the context |
| 5 | +% of an open File object. Therefore NIX entities cannot be initialized via their |
| 6 | +% constructors but only through the factory methods of their respective parent entity. |
| 7 | +% |
| 8 | +% When a file variable is cleared, the handle to the file will be automatically closed. |
| 9 | +% |
| 10 | +% nix.File properties: |
| 11 | +% blocks access to all nix.Block child entities. |
| 12 | +% sections access to all first level nix.Section child entities. |
| 13 | +% |
| 14 | +% See also nix.Block, nix.Section. |
| 15 | +% |
| 16 | +% |
1 | 17 | % Copyright (c) 2016, German Neuroinformatics Node (G-Node)
|
2 | 18 | %
|
3 | 19 | % All rights reserved.
|
|
7 | 23 | % LICENSE file in the root of the Project.
|
8 | 24 |
|
9 | 25 | classdef File < nix.Entity
|
10 |
| - % File nix File object |
11 | 26 |
|
12 |
| - properties(Hidden) |
13 |
| - % namespace reference for nix-mx functions |
14 |
| - alias = 'File' |
| 27 | + properties (Hidden) |
| 28 | + alias = 'File' % nix-mx namespace to access File specific nix backend functions. |
15 | 29 | end
|
16 | 30 |
|
17 | 31 | methods
|
18 | 32 | function obj = File(path, mode)
|
| 33 | + % File constructor used to open or create a nix.File. |
| 34 | + % |
| 35 | + % path (char): path to a file to open or create. |
| 36 | + % mode (char): requires a valid nix.FileMode. Defaults to |
| 37 | + % nix.FileMode.ReadWrite if no FileMode is provided. |
| 38 | + % |
| 39 | + % Returns: (nix.File). |
| 40 | + % |
| 41 | + % See also nix.FileMode. |
| 42 | + |
19 | 43 | if (~exist('mode', 'var'))
|
20 |
| - mode = nix.FileMode.ReadWrite; %default to ReadWrite |
| 44 | + mode = nix.FileMode.ReadWrite; % default to ReadWrite |
21 | 45 | end
|
22 | 46 | h = nix_mx('File::open', path, mode);
|
23 | 47 |
|
24 | 48 |
|
25 |
| - % assign relations |
| 49 | + % assign child entites |
26 | 50 | nix.Dynamic.addGetChildEntities(obj, 'blocks', @nix.Block);
|
27 | 51 | nix.Dynamic.addGetChildEntities(obj, 'sections', @nix.Section);
|
28 | 52 | end
|
29 | 53 |
|
30 | 54 | % braindead...
|
31 | 55 | function r = isOpen(obj)
|
| 56 | + % Check if the file is currently open. |
| 57 | + % |
| 58 | + % Returns: (logical) True if the file is open, False otherwise. |
| 59 | + |
32 | 60 | fname = strcat(obj.alias, '::isOpen');
|
33 | 61 | r = nix_mx(fname, obj.nixhandle);
|
34 | 62 | end
|
35 | 63 |
|
36 | 64 | function r = fileMode(obj)
|
| 65 | + % Get the mode in which the file has been opened. |
| 66 | + % |
| 67 | + % Returns: (nix.FileMode). |
| 68 | + % |
| 69 | + % See also nix.FileMode. |
| 70 | + |
37 | 71 | fname = strcat(obj.alias, '::fileMode');
|
38 | 72 | r = nix_mx(fname, obj.nixhandle);
|
39 | 73 | end
|
40 | 74 |
|
41 | 75 | function r = validate(obj)
|
| 76 | + % Runs a backend validator over all contained entities and returns a |
| 77 | + % custom struct with warnings and error messages, if the current content |
| 78 | + % of the file violates the NIX datamodel as well as the ids of the |
| 79 | + % offending entities. |
| 80 | + % |
| 81 | + % Returns: (struct) Custom warning/error struct. |
| 82 | + |
42 | 83 | fname = strcat(obj.alias, '::validate');
|
43 | 84 | r = nix_mx(fname, obj.nixhandle);
|
44 | 85 | end
|
|
48 | 89 | % ----------------
|
49 | 90 |
|
50 | 91 | function r = createBlock(obj, name, type)
|
| 92 | + % Create a new nix.Block entity, that is immediately persisted to the file. |
| 93 | + % |
| 94 | + % name (char): the name of the Block, has to be unique within the file. |
| 95 | + % read only Block property. |
| 96 | + % type (char): the type of the Block, required. |
| 97 | + % Type can be used to give semantic meaning to an entity |
| 98 | + % and expose it to search methods in a broader context. |
| 99 | + % read/write Block property. |
| 100 | + % |
| 101 | + % Returns: (nix.Block) The newly created Block. |
| 102 | + % |
| 103 | + % Example: newBlock = f.createBlock('trial1', 'ephys'); |
| 104 | + % |
| 105 | + % See also nix.Block. |
| 106 | + |
51 | 107 | fname = strcat(obj.alias, '::createBlock');
|
52 | 108 | h = nix_mx(fname, obj.nixhandle, name, type);
|
53 | 109 | r = nix.Utils.createEntity(h, @nix.Block);
|
54 | 110 | end
|
55 | 111 |
|
56 | 112 | function r = blockCount(obj)
|
| 113 | + % Get the number of Blocks in the file. |
| 114 | + % |
| 115 | + % Returns: (uint) The number of Blocks. |
| 116 | + % |
| 117 | + % Example: bc = f.blockCount(); |
| 118 | + % |
| 119 | + % See also nix.Block. |
| 120 | + |
57 | 121 | r = nix.Utils.fetchEntityCount(obj, 'blockCount');
|
58 | 122 | end
|
59 | 123 |
|
60 | 124 | function r = hasBlock(obj, idName)
|
| 125 | + % Check if a Block exists in the file. |
| 126 | + % |
| 127 | + % idName (char): Name or ID of the Block. |
| 128 | + % |
| 129 | + % Returns: (logical) True if the Block exists, false otherwise. |
| 130 | + % |
| 131 | + % Example: check = f.hasBlock('23bb8a99-1812-4bc6-a52c-45e96864756b'); |
| 132 | + % check = f.hasBlock('trial1'); |
| 133 | + % |
| 134 | + % See also nix.Block. |
| 135 | + |
61 | 136 | r = nix.Utils.fetchHasEntity(obj, 'hasBlock', idName);
|
62 | 137 | end
|
63 | 138 |
|
64 | 139 | function r = openBlock(obj, idName)
|
| 140 | + % Retrieves an existing Block from the file. |
| 141 | + % |
| 142 | + % idName (char): Name or ID of the Block. |
| 143 | + % |
| 144 | + % Returns: (nix.Block) The nix.Block or an empty cell, |
| 145 | + % if the Block was not found. |
| 146 | + % |
| 147 | + % Example: getBlock = f.openBlock('23bb8a99-1812-4bc6-a52c-45e96864756b'); |
| 148 | + % getBlock = f.openBlock('trial1'); |
| 149 | + % |
| 150 | + % See also nix.Block. |
| 151 | + |
65 | 152 | r = nix.Utils.openEntity(obj, 'openBlock', idName, @nix.Block);
|
66 | 153 | end
|
67 | 154 |
|
68 | 155 | function r = openBlockIdx(obj, index)
|
| 156 | + % Retrieves an existing Block from the file, accessed by index. |
| 157 | + % |
| 158 | + % index (double): The index of the Block to read. |
| 159 | + % |
| 160 | + % Returns: (nix.Block) The Block at the given index. |
| 161 | + % |
| 162 | + % Example: getBlock = f.openBlockIdx(1); |
| 163 | + % |
| 164 | + % See also nix.Block. |
| 165 | + |
69 | 166 | idx = nix.Utils.handleIndex(index);
|
70 | 167 | r = nix.Utils.openEntity(obj, 'openBlockIdx', idx, @nix.Block);
|
71 | 168 | end
|
72 | 169 |
|
73 |
| - function r = deleteBlock(obj, del) |
74 |
| - r = nix.Utils.deleteEntity(obj, 'deleteBlock', del, 'nix.Block'); |
| 170 | + function r = deleteBlock(obj, idNameEntity) |
| 171 | + % Deletes a Block from the file. |
| 172 | + % |
| 173 | + % When a Block is deleted, all its content (DataArray, Tags, Sources, etc) |
| 174 | + % will be deleted from the file as well. |
| 175 | + % |
| 176 | + % idNameEntity (char/nix.Block): Name or id of the entity to |
| 177 | + % be deleted or the entity itself. |
| 178 | + % |
| 179 | + % Returns: (logical) True if the Block has been removed, false otherwise. |
| 180 | + % |
| 181 | + % Example: check = f.deleteBlock('23bb8a99-1812-4bc6-a52c-45e96864756b'); |
| 182 | + % check = f.deleteBlock('trial1'); |
| 183 | + % check = f.deleteBlock(newBlock); |
| 184 | + % |
| 185 | + % See also nix.Block. |
| 186 | + |
| 187 | + r = nix.Utils.deleteEntity(obj, 'deleteBlock', idNameEntity, 'nix.Block'); |
75 | 188 | end
|
76 | 189 |
|
77 | 190 | function r = filterBlocks(obj, filter, val)
|
| 191 | + % Get a filtered cell array of all Blocks within this file. |
| 192 | + % |
| 193 | + % filter (nix.Filter): the nix.Filter to be applied. Supports |
| 194 | + % the filters 'acceptall', 'id', 'ids', |
| 195 | + % 'name' and 'type'. |
| 196 | + % val (char): Value that is applied with the selected |
| 197 | + % filter. |
| 198 | + % |
| 199 | + % Returns: ([nix.Block]) A cell array of Blocks filtered according |
| 200 | + % to the applied nix.Filter. |
| 201 | + % |
| 202 | + % Example: getBlocks = f.filterBlocks(nix.Filter.type, 'ephys'); |
| 203 | + % |
| 204 | + % See also nix.Block, nix.Filter. |
| 205 | + |
78 | 206 | r = nix.Utils.filter(obj, 'blocksFiltered', filter, val, @nix.Block);
|
79 | 207 | end
|
80 | 208 |
|
|
83 | 211 | % ----------------
|
84 | 212 |
|
85 | 213 | function r = createSection(obj, name, type)
|
| 214 | + % Create a new nix.Section entity, that is immediately persisted to the file. |
| 215 | + % |
| 216 | + % name (char): the name of the Section, has to be unique within the file. |
| 217 | + % read only Section property. |
| 218 | + % type (char): the type of the Section, required. |
| 219 | + % Type can be used to give semantic meaning to an entity |
| 220 | + % and expose it to search methods in a broader context. |
| 221 | + % read/write Section property. |
| 222 | + % |
| 223 | + % Returns: (nix.Section) The newly created Section. |
| 224 | + % |
| 225 | + % Example: newSec = f.createSection('settings1', 'ephys'); |
| 226 | + % |
| 227 | + % See also nix.Section. |
| 228 | + |
86 | 229 | fname = strcat(obj.alias, '::createSection');
|
87 | 230 | h = nix_mx(fname, obj.nixhandle, name, type);
|
88 | 231 | r = nix.Utils.createEntity(h, @nix.Section);
|
89 | 232 | end
|
90 | 233 |
|
91 | 234 | function r = sectionCount(obj)
|
| 235 | + % Get the number of root Sections in the file. |
| 236 | + % |
| 237 | + % Returns: (uint) The number of root (non nested) Sections. |
| 238 | + % |
| 239 | + % Example: sc = f.sectionCount(); |
| 240 | + % |
| 241 | + % See also nix.Section. |
| 242 | + |
92 | 243 | r = nix.Utils.fetchEntityCount(obj, 'sectionCount');
|
93 | 244 | end
|
94 | 245 |
|
95 | 246 | function r = hasSection(obj, idName)
|
| 247 | + % Check if a Section exists as a direct child of the file. |
| 248 | + % |
| 249 | + % idName (char): Name or ID of the Section. |
| 250 | + % |
| 251 | + % Returns: (logical) True if the Section exists, false otherwise. |
| 252 | + % |
| 253 | + % Example: check = f.hasSection('23bb8a99-1812-4bc6-a52c-45e96864756b'); |
| 254 | + % check = f.hasSection('settings1'); |
| 255 | + % |
| 256 | + % See also nix.Section. |
| 257 | + |
96 | 258 | r = nix.Utils.fetchHasEntity(obj, 'hasSection', idName);
|
97 | 259 | end
|
98 | 260 |
|
99 | 261 | function r = openSection(obj, idName)
|
| 262 | + % Retrieves an existing Section from the file. |
| 263 | + % |
| 264 | + % idName (char): Name or ID of the Section. |
| 265 | + % |
| 266 | + % Returns: (nix.Section) The nix.Section or an empty cell, |
| 267 | + % if the Section was not found. |
| 268 | + % |
| 269 | + % Example: getSec = f.openSection('23bb8a99-1812-4bc6-a52c-45e96864756b'); |
| 270 | + % getSec = f.openSection('settings1'); |
| 271 | + % |
| 272 | + % See also nix.Section. |
| 273 | + |
100 | 274 | r = nix.Utils.openEntity(obj, 'openSection', idName, @nix.Section);
|
101 | 275 | end
|
102 | 276 |
|
103 | 277 | function r = openSectionIdx(obj, index)
|
| 278 | + % Retrieves an existing Section from the file, accessed by index. |
| 279 | + % |
| 280 | + % index (double): The index of the Section to read. |
| 281 | + % |
| 282 | + % Returns: (nix.Section) The Section at the given index. |
| 283 | + % |
| 284 | + % Example: getSec = f.openSectionIdx(1); |
| 285 | + % |
| 286 | + % See also nix.Section. |
| 287 | + |
104 | 288 | idx = nix.Utils.handleIndex(index);
|
105 | 289 | r = nix.Utils.openEntity(obj, 'openSectionIdx', idx, @nix.Section);
|
106 | 290 | end
|
107 | 291 |
|
108 |
| - function r = deleteSection(obj, del) |
109 |
| - r = nix.Utils.deleteEntity(obj, 'deleteSection', del, 'nix.Section'); |
| 292 | + function r = deleteSection(obj, idNameEntity) |
| 293 | + % Deletes a Section from the file. |
| 294 | + % |
| 295 | + % When a Section is deleted, all of its child Sections, Properties and |
| 296 | + % Values will be deleted from the file as well. |
| 297 | + % |
| 298 | + % idNameEntity (char/nix.Section): Name or id of the entity to |
| 299 | + % be deleted or the entity itself. |
| 300 | + % |
| 301 | + % Returns: (logical) True if the Section has been removed, false otherwise. |
| 302 | + % |
| 303 | + % Example: check = f.deleteSection('23bb8a99-1812-4bc6-a52c-45e96864756b'); |
| 304 | + % check = f.deleteSection('settings1'); |
| 305 | + % check = f.deleteSection(newSec); |
| 306 | + % |
| 307 | + % See also nix.Section. |
| 308 | + |
| 309 | + r = nix.Utils.deleteEntity(obj, 'deleteSection', idNameEntity, 'nix.Section'); |
110 | 310 | end
|
111 | 311 |
|
112 | 312 | function r = filterSections(obj, filter, val)
|
| 313 | + % Get a filtered cell array of all root Sections within this file. |
| 314 | + % |
| 315 | + % filter (nix.Filter): the nix.Filter to be applied. Supports |
| 316 | + % the filters 'acceptall', 'id', 'ids', |
| 317 | + % 'name' and 'type'. |
| 318 | + % val (char): Value that is applied with the selected |
| 319 | + % filter. |
| 320 | + % |
| 321 | + % Returns: ([nix.Section]) A cell array of Sections filtered according |
| 322 | + % to the applied nix.Filter. |
| 323 | + % |
| 324 | + % Example: getSecs = f.filterSections(nix.Filter.type, 'ephys'); |
| 325 | + % |
| 326 | + % See also nix.Section, nix.Filter. |
| 327 | + |
113 | 328 | r = nix.Utils.filter(obj, 'sectionsFiltered', filter, val, @nix.Section);
|
114 | 329 | end
|
115 | 330 |
|
116 |
| - % maxdepth is an index |
117 | 331 | function r = findSections(obj, maxDepth)
|
| 332 | + % Get all Sections and their child Sections in this file recursively. |
| 333 | + % |
| 334 | + % This method traverses the trees of all Sections in the file and adds all |
| 335 | + % Sections to the resulting cell array, until the maximum depth of the nested |
| 336 | + % Sections has been reached. The traversal is accomplished via breadth first |
| 337 | + % and adds the Sections accordingly. |
| 338 | + % |
| 339 | + % maxDepth (double): The maximum depth of traversal to retrieve nested |
| 340 | + % Sections. Should be handled like an index. |
| 341 | + % |
| 342 | + % Example: allSec = f.findSections(2); |
| 343 | + % % will add all Sections until including the 2nd layer of Sections. |
| 344 | + % |
| 345 | + % See also nix.Section. |
| 346 | + |
118 | 347 | r = obj.filterFindSections(maxDepth, nix.Filter.acceptall, '');
|
119 | 348 | end
|
120 | 349 |
|
121 |
| - % maxdepth is an index |
122 | 350 | function r = filterFindSections(obj, maxDepth, filter, val)
|
| 351 | + % Get all Sections in this file recursively. |
| 352 | + % |
| 353 | + % This method traverses the trees of all Sections in the file. The traversal |
| 354 | + % is accomplished via breadth first and can be limited in depth. On each |
| 355 | + % node or Section a nix.Filter is applied. If the filter returns true, the |
| 356 | + % respective Section will be added to the result list. |
| 357 | + % |
| 358 | + % maxDepth (double): The maximum depth of traversal to retrieve nested |
| 359 | + % Sections. Should be handled like an index. |
| 360 | + % filter (nix.Filter): the nix.Filter to be applied. Supports |
| 361 | + % the filters 'acceptall', 'id', 'ids', |
| 362 | + % 'name' and 'type'. |
| 363 | + % val (char): Value that is applied with the selected |
| 364 | + % filter. |
| 365 | + % |
| 366 | + % Example: allSec = f.filterFindSections(2, nix.Filter.type, 'ephys'); |
| 367 | + % |
| 368 | + % See also nix.Section, nix.Filter. |
| 369 | + |
123 | 370 | r = nix.Utils.find(obj, 'findSections', maxDepth, filter, val, @nix.Section);
|
124 | 371 | end
|
125 | 372 | end
|
|
0 commit comments