From 375aee2d494b6009433d22029167ec1db36274e9 Mon Sep 17 00:00:00 2001 From: Alexander Kreft <akreft@trineo.org> Date: Thu, 2 Sep 2021 08:48:56 +0000 Subject: [PATCH] ENH: get_value for non-list items --- src/Entity.jl | 62 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 50 insertions(+), 12 deletions(-) diff --git a/src/Entity.jl b/src/Entity.jl index 6fa2c7e..56b56de 100644 --- a/src/Entity.jl +++ b/src/Entity.jl @@ -755,19 +755,57 @@ Return the value of the given `property` """ function get_value(property::Ref{_Property}) - out = Ref{Ptr{UInt8}}(Ptr{UInt8}()) - - err_code = ccall( - (:caosdb_entity_property_get_value, CaosDB.library_name), - Cint, - (Ref{_Property}, Ref{Ptr{UInt8}}), - property, - out, - ) - - CaosDB.Exceptions.evaluate_return_code(err_code) + _caosdb_dtypes = ("INTEGER", "DOUBLE", "BOOLEAN", "TEXT") + + prop_datatype = get_datatype(property) + if prop_datatype[1] in _caosdb_dtypes + + if prop_datatype[1] == "INTEGER" + out = Ref{Cint}(0) + err_code = ccall( + (:caosdb_entity_property_get_int_value, CaosDB.library_name), + Cint, + (Ref{_Property}, Ref{Cint}), + property, + out, + ) + + out = out[] + elseif prop_datatype[1] == "DOUBLE" + out = Ref{Cdouble}(0) + err_code = ccall( + (:caosdb_entity_property_get_double_value, CaosDB.library_name), + Cint, + (Ref{_Property}, Ref{Cdouble}), + property, + out, + ) + out = out[] + elseif prop_datatype[1] == "BOOLEAN" + out = Ref{Cint}(0) + err_code = ccall( + (:caosdb_entity_property_get_boolean_value, CaosDB.library_name), + Cint, + (Ref{_Property}, Ref{Cint}), + property, + out, + ) + out = convert(Bool, out[]) + elseif prop_datatype[1] == "TEXT" + out = Ref{Ptr{UInt8}}(Ptr{UInt8}()) + err_code = ccall( + (:caosdb_entity_property_get_string_value, CaosDB.library_name), + Cint, + (Ref{_Property}, Ref{Ptr{UInt8}}), + property, + out, + ) + out = unsafe_string(out[]) + end + CaosDB.Exceptions.evaluate_return_code(err_code) + end - return unsafe_string(out[]) + return out end """ -- GitLab