📄 bvqxinifile.m
字号:
namsettings{namecount} ...
);
continue;
end
end
% for non-struct value, try conversion
if ~isstruct(fvalue)
try
% for special character arrays ([...], {...})
if ischar(fvalue) && ...
tconvert && ...
~isempty(fvalue) && ...
((fvalue(1) == '[' && ...
fvalue(end) == ']') || ...
(fvalue(1) == '{' && ...
fvalue(end) == '}'))
fvalue = any2ascii(fvalue);
% for exact double conversion
elseif tconvert == 2 && ...
isa(fvalue, 'double') && ...
isreal(fvalue) && ...
any(floor(fvalue(:)) ~= fvalue(:))
fvalue = any2ascii(fvalue, 'exact');
% otherwise, for non chars
elseif ~ischar(fvalue)
fvalue = any2ascii(fvalue);
end
% if conversion fails, log error and continue
catch
if issave
error( ...
'BVQXinifile:ConversionFailed', ...
'Bad value for %s.%s (%s).', ...
sectname, ...
namsettings{namecount}, ...
lasterr ...
);
else
warning( ...
'BVQXinifile:ConversionFailed', ...
'Bad value for %s.%s (%s).', ...
sectname, ...
namsettings{namecount}, ...
lasterr ...
);
continue;
end
end
% in case of a struct, insert into special array
else
extralarge{end + 1} = namsettings{namecount};
% print cell2struct line for other structs
fvalfields = fieldnames(fvalue);
fvalue = sprintf('[cell2struct(cell(%.0f,%.0f,%.0f),%s,3)]', ...
size(fvalue, 1), ...
size(fvalue, 2), ...
numel(fvalfields), ...
any2ascii(fvalfields));
end
% put Fieldname = <Value> line into soutput
sdispout = [sdispout indent ...
namsettings{namecount} equalchar fvalue lineout];
end
% do we have any structs in section?
if ~isempty(extralarge)
% iterate over structs
for namecount = 1:length(extralarge)
% try conversion and log error if failure
try
sdispout = [sdispout lineout ...
i_dispxl( ...
[sectname '.' extralarge{namecount}], ...
csection.(extralarge{namecount}), ...
indent, ...
lineout, ...
equalchar, ...
tconvert ...
)];
catch
if issave
error( ...
'BVQXinifile:ConversionFailed', ...
'Bad struct for %s.%s (%s).', ...
sectname, ...
extralarge{namecount}, ...
lasterr ...
);
else
warning( ...
'BVQXinifile:ConversionFailed', ...
'Bad struct for %s.%s (%s).', ...
sectname, ...
extralarge{namecount}, ...
lasterr ...
);
continue;
end
end
end
end
% insert section output into global out
dispout = [dispout sdispout lineout];
end
% for base class we show a list of files with IDs
else
% print nice header
dispout = ['Currently active ini files (' ...
num2str(length(bvqxinif.matrix)) '):' lineout lineout];
dispout = [dispout '-------------------------------------------------------------------------' lineout];
dispout = [dispout 'OBJECT_FID (PARENT_FID) C P Caller Filename ' lineout];
dispout = [dispout '-------------------------------------------------------------------------' lineout];
% iterate over all loaded IniFiles
for fiter = 1:numel(bvqxinif.matrix)
fifid = bvqxinif.matrix(fiter);
% get conversion and protection states, parent ID, and caller
if bvqxinic(fiter).convert
isconv = 'y';
else
isconv = 'n';
end
protstat = bvqxinic(fiter).readwrite;
if isempty(bvqxinic(fiter).parent)
p_id = '( -- )';
else
p_id = sprintf('(%10.0f)', bvqxinic(fiter).parent(1));
end
fcaller = bvqxinic(fiter).caller;
if length(fcaller) > 30
fcaller = ['...' fcaller(end-26:end)];
end
% show ID, matrix position, and settings
% file contents can then be obtained via BVQXinifile(ID)
dispout = [dispout ...
sprintf('%10.0f %12s %s %s %-30s %s', ...
fifid, p_id, isconv, protstat, fcaller, ...
bvqxinic(fiter).filename) lineout];
end
end
% replace varargout{1} and display if should be displayed!
varargout{1} = [dispout filepost];
if nargout == 0
disp(dispout);
end
% get name of caller
case {'getcaller'}
varargout{1} = cfile.caller;
% get list of children IDs
case {'getchildren'}
varargout{1} = cfile.children;
% give complete IniFile contents as struct
case {'getcomplete'}
varargout{1} = cfile.icontent;
% give filename of object
case {'getfilename'}
% set file name
varargout{1} = cfile.filename;
% get file footer
case {'getfoot'}
% get footer
varargout{1} = strrep(cfile.postfile, bvqxinif.fterm, '');
% remove extra linefeeds...
while numel(varargout{1}) > 0 && ...
(varargout{1}(1) == char(10) || ...
varargout{1}(1) == char(13))
varargout{1}(1) = [];
end
% get file header
case {'gethead'}
varargout{1} = cfile.prefile;
% give id of object
case {'getid'}
varargout{1} = hIniFile.L;
% give filename of object
case {'getinistring'}
% set file name
varargout{1} = BVQXinifile(hIniFile, 'display', 'saveinifile');
% get list of parent IDs
case {'getparents'}
% initialize parent ID list
loparents = [];
tfid = cfid;
% iterate until no more parent found
while ~isempty(bvqxinic(tfid).parent)
loparents(end + 1) = bvqxinic(tfid).parent;
tfid = find(bvqxinif.matrix == loparents(end));
% bail out if parent disappeared
if isempty(tfid)
error( ...
'BVQXinifile:InvalidFileID', ...
'Parent object disappeared, memory glitch?' ...
);
end
end
% return list
varargout{1} = loparents;
% give id of object
case {'getprotection'}
varargout{1} = cfile.readwrite;
% give one section of IniFile as struct
case {'getsection'}
% check for section field in call
if nargin < 3 || ...
~ischar(varargin{3}) || ...
isempty(varargin{3})
error( ...
'BVQXinifile:CallingConvention', ...
'GetIniSection needs a CHAR section name in call.' ...
);
end
% if section doesn't exist
if ~isfield(cfile.icontent, varargin{3}(:)')
error( ...
'BVQXinifile:InvalidSection', ...
'Invalid section in call: %s in file %s.', ...
varargin{3}(:)', ...
cfile.filename ...
);
end
varargout{1} = cfile.icontent.(varargin{3}(:)');
% return sections names
case {'getsections'}
varargout{1} = fieldnames(cfile.icontent);
% return section's setting names
case {'getsectionsettings'}
% check for section field in call
if nargin < 3 || ...
~ischar(varargin{3}) || ...
isempty(varargin{3})
error( ...
'BVQXinifile:CallingConvention', ...
'IniSectionSettings needs a CHAR section name in call.' ...
);
end
% if section doesn't exist, return empty list
if ~isfield(cfile.icontent, varargin{3}(:)')
error( ...
'BVQXinifile:InvalidSection', ...
'The given section (%s) is not part of this file.', ...
varargin{3}(:)' ...
);
end
% get section and if it's struct get fieldnames
csection = cfile.icontent.(strCmd.section);
if isstruct(csection)
varargout{1} = fieldnames(csection);
else
varargout{1} = {'Value'};
end
% give one setting in section of IniFile
case {'getsetting'}
% check for section and setting fields in call
if nargin < 4 || ...
~ischar(varargin{3}) || ...
~ischar(varargin{4}) || ...
isempty(varargin{3}) || ...
isempty(varargin{4})
error( ...
'BVQXinifile:CallingConvention', ...
'GetIniSetting needs two CHAR arguments in call.' ...
);
end
% if section doesn't exist and no parent is available
if ~isfield(cfile.icontent, varargin{3}(:)') && ...
isempty(cfile.parent)
error( ...
'BVQXinifile:InvalidSection', ...
'Invalid section in call: %s in file %s.', ...
strCmd.section, ...
bvqxinic(cfid).filename ...
);
end
% try to retrieve section
if isfield(cfile.icontent, varargin{3}(:)')
csection = cfile.icontent.(varargin{3}(:)');
if ~isstruct(csection)
varargout{1} = csection;
return;
end
else
csection = struct;
end
% if we didn't succeed, check parents
if ~isfield(csection, varargin{4}(:)')
snotfound = true;
tfid = cfid;
% follow parents until found or no more parent
while snotfound && ...
~isempty(cfile.parent)
% lookup parent ID
tfid = find(bvqxinif.matrix == bvqxinic(tfid).parent(1));
% if not found, bail out
if isempty(tfid)
error( ...
'BVQXinifile:InvalidFileId', ...
'Parent object disappeared, memory glitch?' ...
);
end
% try to retrieve section from parent
if isfield(bvqxinic(tfid).icontent, varargin{3}(:)')
tsection = bvqxinic(tfid).icontent.(varargin{3}(:)');
if ~isstruct(tsection)
if ~iscell(tsection)
tsection = struct('Value', tsection);
else
tsection = struct('Value', {tsection});
end
end
else
tsection = struct;
end
% if setting exists, leave loop
if isfield(tsection, varargin{4}(:)')
sfound = tsection.(varargin{4}(:)');
snotfound = false;
end
end
% setting still not found?
if snotfound
error( ...
'BVQXinifile:InvalidSetting', ...
'Invalid setting in call: %s.%s in file %s.', ...
varargin{3}(:)', ...
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -