Skip to content
Snippets Groups Projects
Commit 12eaa7fa authored by florian's avatar florian
Browse files

ENH: Use enums for role and importance

parent c181530c
No related branches found
No related tags found
1 merge request!13ENH: Use new value and datatype structs
Pipeline #13890 failed
...@@ -82,11 +82,6 @@ using CaosDB ...@@ -82,11 +82,6 @@ using CaosDB
# especially in case of a property which I might want to specify by # especially in case of a property which I might want to specify by
# name, add a value, append it to a Record, and then insert it and # name, add a value, append it to a Record, and then insert it and
# might expect the server to care for the datatype. # might expect the server to care for the datatype.
#
# Also, how much do we want to support them with typos. Currently, C
# and C++ only understand all-capital strings for datatypes,
# importances, roles. What about user input like "record_type",
# "RecordType", "recordtype"?
""" """
Struct containing a pointer to the wrapped cpp entity Struct containing a pointer to the wrapped cpp entity
object. Meant for internal use; use `CaosDB.Entity.create_entity` to object. Meant for internal use; use `CaosDB.Entity.create_entity` to
...@@ -291,7 +286,7 @@ function create_recordtype(name::AbstractString = "") ...@@ -291,7 +286,7 @@ function create_recordtype(name::AbstractString = "")
record_type = create_entity(name) record_type = create_entity(name)
set_role(record_type, "RECORD_TYPE") set_role(record_type, CaosDB.Constants.ROLE.RECORD_TYPE)
return record_type return record_type
...@@ -307,7 +302,7 @@ function create_record(name::AbstractString = "") ...@@ -307,7 +302,7 @@ function create_record(name::AbstractString = "")
record = create_entity(name) record = create_entity(name)
set_role(record, "RECORD") set_role(record, CaosDB.Constants.ROLE.RECORD)
return record return record
...@@ -336,7 +331,7 @@ function create_property_entity(; ...@@ -336,7 +331,7 @@ function create_property_entity(;
property = create_entity(name) property = create_entity(name)
set_role(property, "PROPERTY") set_role(property, CaosDB.Constants.ROLE.PROPERTY)
if datatype != "" if datatype != ""
set_datatype(property, datatype, is_list = is_list, is_reference = is_reference) set_datatype(property, datatype, is_list = is_list, is_reference = is_reference)
...@@ -432,7 +427,7 @@ function create_file_entity(; ...@@ -432,7 +427,7 @@ function create_file_entity(;
end end
file_entity = create_entity(name) file_entity = create_entity(name)
set_role(file_entity, "FILE") set_role(file_entity, CaosDB.Constants.ROLE.FILE)
set_local_path(file_entity, local_path) set_local_path(file_entity, local_path)
set_remote_path(file_entity, remote_path) set_remote_path(file_entity, remote_path)
...@@ -739,7 +734,9 @@ function get_role(entity::Ref{_Entity}) ...@@ -739,7 +734,9 @@ function get_role(entity::Ref{_Entity})
CaosDB.Exceptions.evaluate_return_code(err_code) CaosDB.Exceptions.evaluate_return_code(err_code)
return unsafe_string(out[]) rolename = unsafe_string(out[])
role = getproperty(CaosDB.Constants.ROLE, Symbol(rolename))
return role
end end
""" """
...@@ -1279,14 +1276,16 @@ function get_importance(property::Ref{_Property}) ...@@ -1279,14 +1276,16 @@ function get_importance(property::Ref{_Property})
err_code = ccall( err_code = ccall(
(:caosdb_entity_property_get_importance, CaosDB.library_name), (:caosdb_entity_property_get_importance, CaosDB.library_name),
Cint, Cint,
(Ref{_Entity}, Ref{Ptr{UInt8}}), (Ref{_Property}, Ref{Ptr{UInt8}}),
property, property,
out, out,
) )
CaosDB.Exceptions.evaluate_return_code(err_code) CaosDB.Exceptions.evaluate_return_code(err_code)
return unsafe_string(out[]) imp_name = unsafe_string(out[])
imp = getproperty(CaosDB.Constants.IMPORTANCE, Symbol(imp_name))
return imp
end end
""" """
...@@ -1776,17 +1775,17 @@ function set_id(property::Ref{_Property}, id::AbstractString) ...@@ -1776,17 +1775,17 @@ function set_id(property::Ref{_Property}, id::AbstractString)
end end
""" """
function set_role(entity::Ref{_Entity}, role::AbstractString) function set_role(entity::Ref{_Entity}, role::CaosDB.Constants.ROLE._ROLE)
Set the role of the given `entity` object. Set the role of the given `entity` object.
""" """
function set_role(entity::Ref{_Entity}, role::AbstractString) function set_role(entity::Ref{_Entity}, role::CaosDB.Constants.ROLE._ROLE)
err_code = ccall( err_code = ccall(
(:caosdb_entity_entity_set_role, CaosDB.library_name), (:caosdb_entity_entity_set_role, CaosDB.library_name),
Cint, Cint,
(Ref{_Entity}, Cstring), (Ref{_Entity}, Cstring),
entity, entity,
role, string(role),
) )
CaosDB.Exceptions.evaluate_return_code(err_code) CaosDB.Exceptions.evaluate_return_code(err_code)
...@@ -1887,7 +1886,7 @@ function set_datatype( ...@@ -1887,7 +1886,7 @@ function set_datatype(
is_reference::Bool = false, is_reference::Bool = false,
) )
if get_role(entity) != "PROPERTY" if get_role(entity) != CaosDB.Constants.ROLE.PROPERTY
throw( throw(
CaosDB.Exceptions.ClientException( CaosDB.Exceptions.ClientException(
"Only entities with role PROPERTY can be assigned a datatype.", "Only entities with role PROPERTY can be assigned a datatype.",
...@@ -1994,7 +1993,7 @@ function set_value( ...@@ -1994,7 +1993,7 @@ function set_value(
value::Union{AbstractString,Number,Bool,Vector{T}}, value::Union{AbstractString,Number,Bool,Vector{T}},
) where {T<:Union{AbstractString,Number,Bool}} ) where {T<:Union{AbstractString,Number,Bool}}
if get_role(entity) != "PROPERTY" if get_role(entity) != CaosDB.Constants.ROLE.PROPERTY
throw( throw(
CaosDB.Exceptions.ClientException( CaosDB.Exceptions.ClientException(
"Only entites with role PROPERTY may be assigned a value.", "Only entites with role PROPERTY may be assigned a value.",
...@@ -2040,17 +2039,23 @@ function set_value( ...@@ -2040,17 +2039,23 @@ function set_value(
end end
""" """
function set_importance(property::Ref{_Property}, importance::AbstractString) function set_importance(
property::Ref{_Property},
importance::CaosDB.Constants.IMPORTANCE._IMPORTANCE
)
Set the importance of the given `property` object. Set the importance of the given `property` object.
""" """
function set_importance(property::Ref{_Property}, importance::AbstractString) function set_importance(
property::Ref{_Property},
importance::CaosDB.Constants.IMPORTANCE._IMPORTANCE,
)
err_code = ccall( err_code = ccall(
(:caosdb_entity_property_set_importance, CaosDB.library_name), (:caosdb_entity_property_set_importance, CaosDB.library_name),
Cint, Cint,
(Ref{_Property}, Cstring), (Ref{_Property}, Cstring),
property, property,
importance, string(importance),
) )
CaosDB.Exceptions.evaluate_return_code(err_code) CaosDB.Exceptions.evaluate_return_code(err_code)
......
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