Skip to content
Snippets Groups Projects
Commit eaabf17a authored by Daniel Hornung's avatar Daniel Hornung
Browse files

FIX: Packing values for C++ interaction is much more robust now.

parent f81f7d0c
No related branches found
No related tags found
1 merge request!3Full functionality of libcaosdb
Pipeline #12840 failed
...@@ -162,9 +162,11 @@ classdef Entity < handle ...@@ -162,9 +162,11 @@ classdef Entity < handle
res.datatype = obj.datatype_; res.datatype = obj.datatype_;
res.unit = obj.unit; res.unit = obj.unit;
if (isempty(obj.datatype_)) if (isempty(obj.datatype_))
warning(["Trying to transmit an Entity with value but without Datatype. List-iness is", ... if ~isempty(obj.value)
" unknown, so the value will be omitted."]) warning(["Trying to transmit an Entity with value but without Datatype. List-iness", ...
res.datatype = struct("dtypeName", "UNSPECIFIED", "isList", false, "isReference", false) " is unknown, so the value will be omitted."])
end
% res.datatype = struct("dtypeName", "UNSPECIFIED", "isList", false, "isReference", false);
res.value = sparse([]); res.value = sparse([]);
else else
res.value = maox_pack_value(obj.value, obj.datatype_.isList); res.value = maox_pack_value(obj.value, obj.datatype_.isList);
......
...@@ -62,9 +62,11 @@ classdef Property < handle ...@@ -62,9 +62,11 @@ classdef Property < handle
res.datatype = obj.datatype_; res.datatype = obj.datatype_;
res.unit = obj.unit; res.unit = obj.unit;
if (isempty(obj.datatype_)) if (isempty(obj.datatype_))
warning(["Trying to transmit an Entity with value but without Datatype. List-iness is", ... if ~isempty(obj.value)
" unknown, so the value will be omitted."]) warning(["Trying to transmit an Entity with value but without Datatype. List-iness", ...
res.datatype = struct("dtypeName", "UNSPECIFIED", "isList", false, "isReference", false) " is unknown, so the value will be omitted."])
end
% res.datatype = struct("dtypeName", "UNSPECIFIED", "isList", false, "isReference", false);
res.value = sparse([]); res.value = sparse([]);
else else
res.value = maox_pack_value(obj.value, obj.datatype_.isList); res.value = maox_pack_value(obj.value, obj.datatype_.isList);
......
% This file is a part of the CaosDB Project.
%
% Copyright (C) 2021 IndiScale GmbH <info@indiscale.com>
% Copyright (C) 2021 Daniel Hornung <d.hornung@indiscale.com>
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU Affero General Public License as
% published by the Free Software Foundation, either version 3 of the
% License, or (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU Affero General Public License for more details.
%
% You should have received a copy of the GNU Affero General Public License
% along with this program. If not, see <https://www.gnu.org/licenses/>.
%% Pack the value for handling by maoxdb
%
% This means that the value will be packed into a cell array if it is considered a list.
function result = maox_pack_value(value, isList)
% Pack list values into a 1x1 cell array
if isList
if (isempty(value) && ~ischar(value)) % empty list
result = {};
else
result = {value};
end
else % test if value looks scalar
if iscellstr(value) || (isnumeric(value) && numel(value) > 1)
error("caosdb:valueError", "Value looks list-like, but it must be scalar.");
end
% handle empty scalar value
if (isempty(value) && ~ischar(value))
result = sparse([]);
else
result = value;
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment