Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
CaosDB Octave library
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
CaosDB Octave library
Commits
1eb3edd2
Commit
1eb3edd2
authored
3 years ago
by
Daniel Hornung
Browse files
Options
Downloads
Patches
Plain Diff
WIP: Entity to octave
parent
d9a3bed4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!2
ENH: Retrieving single entities works on the mex side.
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/lib/maoxdb.cpp
+26
-1
26 additions, 1 deletion
src/lib/maoxdb.cpp
src/lib/maoxdb.hpp
+25
-2
25 additions, 2 deletions
src/lib/maoxdb.hpp
with
51 additions
and
3 deletions
src/lib/maoxdb.cpp
+
26
−
1
View file @
1eb3edd2
...
...
@@ -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"
,
"
message
s"
,
"
error
s"
,
"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
This diff is collapsed.
Click to expand it.
src/lib/maoxdb.hpp
+
25
−
2
View file @
1eb3edd2
...
...
@@ -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 ///////////////////////////////////////////////
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment