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

WIP: Entity to octave

parent d9a3bed4
No related branches found
No related tags found
1 merge request!2ENH: Retrieving single entities works on the mex side.
......@@ -103,6 +103,8 @@ auto mxFromResultSet(const caosdb::transaction::ResultSet &resultSet)
// int num_keys,
// const char ** keys
// )
return nullptr;
}
/**
......@@ -120,13 +122,36 @@ auto mxFromCaosDBEntity(const caosdb::entity::Entity &entity) -> mxArray * {
"value",
"parents",
"properties",
"messages",
"errors",
"warnings",
"infos"
};
std::array<mwSize, 2> dims = {1, (mwSize)keys.size()};
auto * result = mxCreateStructArray (2, dims.data(), keys.size(), keys.data());
// Fill with scalar values
mxSetField(result, 0, "role", mxCreateString(entity.GetRole().c_str()));
mxSetField(result, 0, "id", mxCreateString(entity.GetId().c_str()));
mxSetField(result, 0, "versionId", mxCreateString(entity.GetVersionId().c_str()));
mxSetField(result, 0, "name", mxCreateString(entity.GetName().c_str()));
mxSetField(result, 0, "description", mxCreateString(entity.GetDescription().c_str()));
mxSetField(result, 0, "datatype", mxCreateString(entity.GetDatatype().c_str()));
mxSetField(result, 0, "unit", mxCreateString(entity.GetUnit().c_str()));
// Parse value to proper type.
mxSetField(result, 0, "value", mxScalarFromStringValue(entity));
// Parents and Properties
mxSetField(result, 0, "parents", mxFromCaosDBParents(entity.GetParents()));
return result;
}
// Parents to cell array with structs
auto mxFromCaosDBParents(const caosdb::entity::Parents &parents) -> mxArray * {
for (size_t i = 0; i < parents.Size(); ++i) {
// TODO ///////////////////////////////////////////////////////////////////
mxCreateCell // TODO Continue here...
auto parent = entity.GetParents().At(i);
}
}
} // namespace maoxdb
......@@ -25,7 +25,7 @@
* - description
* - datatype
* - unit
* - value
* - value: A string representation of the value.
* - parents: Struct array with the following fields:
* - id
* - name
......@@ -38,7 +38,7 @@
* - value
* - unit
* - datatype
* - messages: Array of messages (struct of code and description).
* - errors: Array of messages (struct of code and description).
* - warnings: Like messages.
* - infos: Like messages.
*
......@@ -73,6 +73,29 @@ inline auto mxScalarDOUBLE(double value) -> mxArray * {
inline auto mxScalarLOGICAL(bool value) -> mxArray * {
return mxScalar<UINT8_T>(static_cast<unsigned char>(value), mxLOGICAL_CLASS);
}
inline auto mxEmptyDOUBLE() -> mxArray * {
mxArray *array = mxCreateNumericMatrix(1, 0, mxDOUBLE_CLASS, mxREAL);
return array;
}
/**
* @brief Convert the string-typed value in an Entity-like object to a mxArray,
*/
template <class T>
auto mxScalarFromStringValue(const T& entity) -> mxArray * {
mxArray * result = nullptr;
auto dt = entity.GetDatatype();
if (dt.empty()) {
result = mxEmptyDOUBLE();
} else if (dt == "INTEGER") {
result = mxScalarINT64(stol(entity.GetValue()));
} else if (dt == "DOUBLE") {
result = mxScalarDOUBLE(stol(entity.GetValue()));
} else {
std::cerr << "Unknown datatype: " << dt << "." << std::endl;
}
return result;
}
// Exception and error handling ///////////////////////////////////////////////
......
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