diff --git a/src/Entity.jl b/src/Entity.jl index da6045a720c4cfe1753bcb974a282b8534e7e01a..22699b7ab33c164098e5a67643e3e1b4cae19dd6 100644 --- a/src/Entity.jl +++ b/src/Entity.jl @@ -724,10 +724,6 @@ function get_unit(property::Ref{_Property}) return unsafe_string(out[]) end -# TODO(henrik,daniel) Replace ccall within the `get_value` function by -# a check of the datatype and then call the correct function in case -# of scalar values or construct a vector and fill it with all values -# in case of list values. """ function get_value(entity::Ref{_Entity}) @@ -735,19 +731,88 @@ Return the value of the given `entity` """ function get_value(entity::Ref{_Entity}) - out = Ref{Ptr{UInt8}}(Ptr{UInt8}()) + _caosdb_dtypes = ("INTEGER", "DOUBLE", "BOOLEAN", "TEXT") - err_code = ccall( - (:caosdb_entity_entity_get_value, CaosDB.library_name), - Cint, - (Ref{_Entity}, Ref{Ptr{UInt8}}), - entity, - out, - ) + ent_datatype = get_datatype(entity) + is_list = ent_datatype[3] + if ent_datatype[1] in _caosdb_dtypes + if !is_list + if ent_datatype[1] == "INTEGER" + out = Ref{Cint}(0) + err_code = ccall( + (:caosdb_entity_entity_get_int_value, CaosDB.library_name), + Cint, + (Ref{_Entity}, Ref{Cint}), + entity, + out, + ) - CaosDB.Exceptions.evaluate_return_code(err_code) + out = out[] + elseif ent_datatype[1] == "DOUBLE" + out = Ref{Cdouble}(0) + err_code = ccall( + (:caosdb_entity_entity_get_double_value, CaosDB.library_name), + Cint, + (Ref{_Entity}, Ref{Cdouble}), + entity, + out, + ) + out = out[] + elseif ent_datatype[1] == "BOOLEAN" + out = Ref{Cint}(0) + err_code = ccall( + (:caosdb_entity_entity_get_boolean_value, CaosDB.library_name), + Cint, + (Ref{_Entity}, Ref{Cint}), + entity, + out, + ) + out = convert(Bool, out[]) + elseif ent_datatype[1] == "TEXT" + out = Ref{Ptr{UInt8}}(Ptr{UInt8}()) + err_code = ccall( + (:caosdb_entity_entity_get_string_value, CaosDB.library_name), + Cint, + (Ref{_Entity}, Ref{Ptr{UInt8}}), + entity, + out, + ) + out = unsafe_string(out[]) + end + else + list_length = get_property_list_length(entity) + if ent_datatype[1] == "INTEGER" + out = Vector{Cint}() + for i::Cint = 1:list_length + temp = get_int_list_value_at(entity, i) + append!(out, temp) + end + elseif ent_datatype[1] == "DOUBLE" + out = Vector{Cdouble}() + for i::Cint = 1:list_length + temp = get_double_list_value_at(entity, i) + append!(out, temp) + end + elseif ent_datatype[1] == "BOOLEAN" + out = Vector{Bool}() + for i::Cint = 1:list_length + temp = get_bool_list_value_at(entity, i) + append!(out, temp) + end + elseif ent_datatype[1] == "TEXT" + out = Vector{String}() + for i::Cint = 1:list_length + temp = get_string_list_value_at(entity, i) + append!(out, [temp]) + end + end + end + if @isdefined err_code + CaosDB.Exceptions.evaluate_return_code(err_code) + end + end - return unsafe_string(out[]) + return out end """