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

[msa-refactoring][classes] Updated loadConfig in Component Class

Added the possibility to save data from loadConfig
or to use existing data to avoid continously loading files
parent 599d51fe
No related branches found
No related tags found
1 merge request!2Final data structure
classdef (Abstract) Component < Config classdef Component < Config
%COMPONENT Summary of this class goes here %COMPONENT Summary of this class goes here
% Detailed explanation goes here % Detailed explanation goes here
...@@ -7,21 +7,66 @@ classdef (Abstract) Component < Config ...@@ -7,21 +7,66 @@ classdef (Abstract) Component < Config
mission Mission mission Mission
end end
methods
function obj = Component(mission)
arguments (Input)
mission Mission = Mission()
end
obj.mission = mission;
if nargin == 0, return; end
obj.loadConfig();
obj.loadData();
end
end
methods(Access = protected) methods(Access = protected)
function loadConfig(obj) function [outputVariables] = loadConfig(obj, varargin)
%This method loads desired config data by running the
%corresponding script.
% The script name is specified as the "configName" for each
% subclass of "Config"
%
% Syntax
% obj.loadConfig() - To load from a config file
% obj.loadConfig(data) - To load from given data
%
% data = obj.loadConfig() - To save loaded data
if nargin > 2, error('Too many input arguments.'); end
fileName = obj.configName; fileName = obj.configName;
filePath = obj.mission.configPath; varName = strtok(fileName,'C');
if nargin == 1
filePath = obj.mission.configPath;
if ~isfile(fullfile(filePath, fileName)) if ~isfile(fullfile(filePath, fileName))
error(strcat("File not found inside the config folder: ", filePath)); error(strcat("File not found inside the config folder: ", fileName));
end end
varName = strtok(fileName,'C');
variables = [who(); "variables"];
run(fileName); run(fileName);
loadedVariables = who();
loadedVariables(ismember(loadedVariables, variables)) = [];
configObj = eval(varName); configObj = eval(varName);
else
configObj = varargin{1}.(varName);
end
fields = obj.getAvailableProperties(); fields = obj.getAvailableProperties();
for j = 1:size(fields, 2), obj.(fields{j}) = configObj.(fields{j}); end for j = 1:size(fields, 2), obj.(fields{j}) = configObj.(fields{j}); end
%% Saving data
if nargout > 0
outputVariables = struct();
for i = 1:length(loadedVariables)
outputVariables.(loadedVariables{i}) = eval(loadedVariables{i});
end end
end end
end end
end
methods(Static, Access = protected)
function loadData(), end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment