URL: <http://gna.org/patch/?4940>
Summary: Rewrite universal_fulfills_requirement() Project: Freeciv Submitted by: persia Submitted on: Sun 13 Jul 2014 07:39:18 AM JST Category: general Priority: 5 - Normal Status: Ready For Test Privacy: Public Assigned to: persia Originator Email: Open/Closed: Open Discussion Lock: Any Planned Release: 2.6.0 _______________________________________________________ Details: 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. _______________________________________________________ File Attachments: ------------------------------------------------------- Date: Sun 13 Jul 2014 07:39:18 AM JST Name: rewrite-universal_fulfills_requirement.patch Size: 8kB By: persia <http://gna.org/patch/download.php?file_id=21385> _______________________________________________________ Reply to this item at: <http://gna.org/patch/?4940> _______________________________________________ Message sent via/by Gna! http://gna.org/ _______________________________________________ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev