Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider turning the enums into types for dispatch #246

Open
yeesian opened this issue Sep 30, 2021 · 0 comments · May be fixed by #266
Open

Consider turning the enums into types for dispatch #246

yeesian opened this issue Sep 30, 2021 · 0 comments · May be fixed by #266

Comments

@yeesian
Copy link
Owner

yeesian commented Sep 30, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants