Summary: Rewrite universal_fulfills_requirement()
Submitted by: persia
Submitted on: Sun 13 Jul 2014 07:39:18 AM JST
Priority: 5 - Normal
Status: Ready For Test
Assigned to: persia
Discussion Lock: Any
Planned Release: 2.6.0
Patch #4558 introduced universal_fulfills_requirement(), which I've found very
useful for patch #4822, bug #14210, and patch #4885 . However, the more I use
this, the more I become frustrated with the volume of boilerplate required.
The attached patch rewrites the implementation so the callers may use a
locally-scoped universal, rather than a malloc()'d universals_u, and
determines the name of the item_found function via a switch statement, rather
than encoding the function name in the caller. I've chosen to return ITF_YES
for unimplemented requirement kinds, given that callers are static, but for
safety these could be adjusted to include an fc_assert().
Most of the assertions have also been removed, mostly because I prefer both
assert-before use and assignment-in-declarations, which aren't entirely
compatible. If others think these assertions are important, I suggest that
the appropriate places are a single assert to the passed pointer in
requirement_fulfilled_by_foo(), and a single assert on reqs in
universal_fulfills_requirement() (and would be happy to add them in another
revision of this patch).
The result is 8 lines less that need be added to requirements.c for each new
requirement kind, with more lines safe for copy and paste.
Date: Sun 13 Jul 2014 07:39:18 AM JST Name:
rewrite-universal_fulfills_requirement.patch Size: 8kB By: persia
Reply to this item at:
Message sent via/by Gna!
Freeciv-dev mailing list