-
Notifications
You must be signed in to change notification settings - Fork 27
Open
Labels
Description
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
ArchGDAL.jl/src/ogr/feature.jl
Lines 390 to 413 in 8f820c7
| 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 |