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

ENH: Inserting entities should work now.

parent 68b8cec0
No related branches found
No related tags found
1 merge request!3Full functionality of libcaosdb
Pipeline #12803 failed
......@@ -32,11 +32,13 @@ classdef Entity < handle
% - isList logical
% - isReference logical
% - dtypeName string. Either the atomic datatype or the reference name.
parents_ % Cell array of Parent objects. Struct array with the following fields:
parents_ % Cell array of Parent objects. May be created from a struct array with the
% following fields:
% - id
% - name
% - description
properties_ % Cell array of Property objects. Struct array with the following fields:
properties_ % Cell array of Property objects. May be created from a struct array with the
% following fields:
% - id
% - name
% - description
......@@ -156,6 +158,9 @@ classdef Entity < handle
res.datatype = obj.datatype_;
res.unit = obj.unit;
res.value = obj.value;
if (isempty(res.value) && ~ischar(res.value))
res.value = sparse([]);
end
% parents and properties
res.parents = cellfun(@(x)(x.to_struct()), obj.get_parents());
res.properties = cellfun(@(x)(x.to_struct()), obj.get_properties());
......@@ -163,8 +168,8 @@ classdef Entity < handle
struct_array = res;
end
function display(obj)
disp(struct(obj));
function disp(obj)
disp(obj.to_struct());
end
end
......
......@@ -33,8 +33,12 @@ classdef Message < handle
obj.description = data.description;
end
function display(obj)
disp(["Message:\n" obj.code " - " obj.description]);
function ans = str(obj)
ans = [num2str(obj.code), " - ", obj.description];
end
function disp(obj)
disp(obj.str());
end
end
......
......@@ -16,6 +16,10 @@
% 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/>.
%%
%
% Note: Setting the description has no effect for inserting or updating parents.
classdef Parent < handle
properties
......@@ -48,5 +52,9 @@ classdef Parent < handle
struct_array = res;
end
function disp(obj)
disp(obj.to_struct());
end
end
end
......@@ -59,13 +59,26 @@ classdef Property < handle
res.name = obj.name;
res.description = obj.description;
res.importance = obj.importance;
res.datatype = obj.datatype;
res.datatype = obj.datatype_;
res.unit = obj.unit;
res.value = obj.value;
if (isempty(res.value) && ~ischar(res.value))
res.value = sparse([]);
end
struct_array = res;
end
function disp(obj)
disp(obj.to_struct());
end
% Getters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function result = get_datatype(obj)
result = obj.datatype_;
end
% Setters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function set_datatype(obj, dtype_name, is_reference, is_list)
......
......@@ -425,7 +425,7 @@ auto entitiesFromMx(const mxArray *array, bool for_update, string conn_name)
}
assignEntityDataFromMx(entity, array, index);
entities.push_back(entity);
// TODO (dh) Wtf, why can't I do entities[foo] = bar?
// TODO (dh) Wtf, why can't I do entities[foo] = entity?
}
}
// insert only: No ID, only assign other values ///////////////////////////
......@@ -472,8 +472,16 @@ auto propertiesFromMx(const mxArray *propertiesArray) -> std::vector<ce::Propert
* Convert a struct array to a DataType descriptor object.
*/
auto dataTypeFromMx(const mxArray *datatypeArray) -> ce::DataType {
if (mxIsEmpty(datatypeArray)) {
return ce::DataType();
}
CAOSDB_LOG_TRACE(logger_name) << "dataTypeFromMx";
CAOSDB_LOG_TRACE(logger_name) << "type: " << mxGetClassID(datatypeArray);
if (!mxIsStruct(datatypeArray)) {
throw std::logic_error(
string("Unexpected type for datatype (Class ID ")
+ boost::lexical_cast<std::string>(mxGetClassID(datatypeArray)) + ", expected "
+ boost::lexical_cast<std::string>(mxClassID::mxSTRUCT_CLASS) + ")");
}
auto is_list = mxGetScalarValue<bool>(mxGetField(datatypeArray, 0, "isList"));
auto is_reference = mxGetScalarValue<bool>(mxGetField(datatypeArray, 0, "isReference"));
auto dtype_name = mxGetStdString(mxGetField(datatypeArray, 0, "dtypeName"));
......
......@@ -382,6 +382,10 @@ template <typename Enum> auto mxEnumToString(Enum enum_value) -> mxArray * {
* @details There must be a specialization upstream for each enum type.
*/
template <typename Enum> auto mxStringToEnum(const mxArray *const array) -> Enum {
if (mxIsEmpty(array)) {
auto value = static_cast<Enum>(0); // attempt to use the default value
return value;
}
Enum value = caosdb::utility::getEnumValueFromName<Enum>(mxGetStdString(array));
return value;
}
......
......@@ -40,14 +40,14 @@ using std::string;
#undef CAOSDB_LOG_DEBUG
#undef CAOSDB_LOG_INFO
// #define CAOSDB_LOG_TRACE(name) std::clog << std::endl << "[" << name << "] "
#define CAOSDB_LOG_DEBUG(name) std::clog << std::endl << "[" << name << "] "
#define CAOSDB_LOG_INFO(name) std::clog << std::endl << "[" << name << "] "
// #define CAOSDB_LOG_DEBUG(name) std::clog << std::endl << "[" << name << "] "
// #define CAOSDB_LOG_INFO(name) std::clog << std::endl << "[" << name << "] "
std::ostream nullout(nullptr);
#define CAOSDB_LOG_TRACE(name) nullout
// #define CAOSDB_LOG_DEBUG(name) nullout
// #define CAOSDB_LOG_INFO(name) nullout
#define CAOSDB_LOG_DEBUG(name) nullout
#define CAOSDB_LOG_INFO(name) nullout
auto logger_name = "maox_transaction";
/**
......@@ -89,13 +89,14 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
auto helpText = string("maox_transaction(connection_name, retrieve_ids, queries, inserts, ") +
"updates, deletes)";
try {
CAOSDB_LOG_DEBUG(logger_name) << "maox_transaction(): " << nlhs << " <- " << nrhs << " ( "
CAOSDB_LOG_DEBUG(logger_name) << "maox_transaction(): " << nlhs << " <- " << nrhs << std::endl;
CAOSDB_LOG_DEBUG(logger_name) << " ( "
<< mxGetNumberOfElements(prhs[0]) << ", "
<< mxGetNumberOfElements(prhs[1]) << ", "
<< mxGetNumberOfElements(prhs[2]) << ", "
<< mxGetNumberOfElements(prhs[3]) << ", "
<< mxGetNumberOfElements(prhs[4]) << ", "
<< mxGetNumberOfElements(prhs[5]) << ")";
<< mxGetNumberOfElements(prhs[5]) << ")" << std::endl;
if (nrhs < 2) {
mexErrMsgIdAndTxt("maox:InsufficientArguments",
(string("Need at least 2 arguments: ") + helpText).c_str());
......
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