Skip to content
Snippets Groups Projects
Commit 82d0b952 authored by Marco Luigi Gaibotti's avatar Marco Luigi Gaibotti
Browse files

[design-updates] Converted merge method to read

The merge method was made to merge two different Settings classes
The read method can read from any struct
parent 1a3ac68d
Branches
No related tags found
1 merge request!13[design-updates] ORI critical design
...@@ -37,28 +37,44 @@ classdef Settings < Config & dynamicprops ...@@ -37,28 +37,44 @@ classdef Settings < Config & dynamicprops
varsIn = obj.getConfig(configNames); varsIn = obj.getConfig(configNames);
obj.loadConfig(varsIn); obj.loadConfig(varsIn);
end end
end
function merge(target, source) methods(Static)
function target = read(target, source, targetFields)
arguments arguments
target target {mustBeA(target, {'struct', 'Settings'})}
source source struct
end
arguments (Repeating)
targetFields {mustBeA(targetFields, {'char', 'string'})}
end end
% MERGE - merges two settings classes % MERGE - reads and applies data from a source struct
% Priority is given to the source settings % Usage: settings.read(<struct>, <name of settings field>)
% empty fields are ignored %
% Source fields have priority over settings fields, meaning
% the source will overwrite existing settings with the same
% name
%
% Empty fields in the source struct are ignored
fields = fieldnames(source)'; fields = fieldnames(source)';
if isempty(fields), return; end
if length(targetFields) > 1
target.(targetFields{1}) = Settings.read( ...
target.(targetFields{1}), ...
source, ...
targetFields{2:end});
return;
end
% WIP: fix wrong assignment
targetField = targetFields{1};
for field = fields for field = fields
fd = field{1}; fd = field{1};
if isempty(source.(fd)), continue; end if isempty(source.(fd)), continue; end
if isempty(findprop(target, fd)) target.(targetField).(fd) = source.(fd);
target.addprop(fd);
target.(fd) = source.(fd);
elseif isa(source.(fd), 'Settings')
target.(fd).merge(source.(fd))
else
target.(fd) = source.(fd);
end
end end
end end
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment