1 | function config = override(config,update) |
---|
2 | % OVERRIDE Override structure subset |
---|
3 | % CONFIG = OVERRIDE(CONFIG, UPDATE) copies recursively the fileds of |
---|
4 | % the structure UPDATE to the corresponding fields of the struture |
---|
5 | % CONFIG. |
---|
6 | % |
---|
7 | % While CONFIG and UPDATE can be any structure, typicall CONFIG |
---|
8 | % is used to store the default configration of some object, and |
---|
9 | % UPDATE is used to update only a specific subset of it. |
---|
10 | |
---|
11 | % AUTORIGHTS |
---|
12 | % Copyright (C) 2006 Andrea Vedaldi |
---|
13 | % |
---|
14 | % This file is part of VLUtil. |
---|
15 | % |
---|
16 | % VLUtil is free software; you can redistribute it and/or modify |
---|
17 | % it under the terms of the GNU General Public License as published by |
---|
18 | % the Free Software Foundation; either version 2, or (at your option) |
---|
19 | % any later version. |
---|
20 | % |
---|
21 | % This program is distributed in the hope that it will be useful, |
---|
22 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
23 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
24 | % GNU General Public License for more details. |
---|
25 | % |
---|
26 | % You should have received a copy of the GNU General Public License |
---|
27 | % along with this program; if not, write to the Free Software Foundation, |
---|
28 | % Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
29 | |
---|
30 | if ~isstruct(config) |
---|
31 | config = update ; |
---|
32 | return ; |
---|
33 | end |
---|
34 | |
---|
35 | fields = fieldnames(update) ; |
---|
36 | for i=1:length(fields) |
---|
37 | f=fields{i} ; |
---|
38 | if(isfield(config, f)) |
---|
39 | config.(f) = override(config.(f), update.(f)) ; |
---|
40 | else |
---|
41 | config.(f) = update.(f) ; |
---|
42 | end |
---|
43 | end |
---|