Skip to content

Consider turning the enums into types for dispatch #246

@yeesian

Description

@yeesian

See e.g. https://discourse.julialang.org/t/style-recommendation-for-enum-as-type/46078/5 and https://www.juliabloggers.com/julia-dispatching-enum-versus-type/ for a discussion.

This is helpful for e.g. dispatching on OGRFIELDTYPE in

const _FETCHFIELD = Dict{OGRFieldType,Function}(
OFTInteger => asint,
OFTIntegerList => asintlist,
OFTReal => asdouble,
OFTRealList => asdoublelist,
OFTString => asstring,
OFTStringList => asstringlist,
OFTBinary => asbinary,
OFTDate => asdatetime,
OFTTime => asdatetime,
OFTDateTime => asdatetime,
OFTInteger64 => asint64,
OFTInteger64List => asint64list,
)
function getfield(feature::Feature, i::Integer)
return if isfieldset(feature, i)
_fieldtype = gettype(getfielddefn(feature, i))
_fetchfield = get(_FETCHFIELD, _fieldtype, getdefault)
_fetchfield(feature, i)
else
getdefault(feature, i)
end
end

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions