simon-git: spigot (master): Simon Tatham
Commits to Tartarus CVS repository.
tartarus-commits at lists.tartarus.org
Fri May 1 19:57:31 BST 2015
TL;DR:
848fa4c Refactor communication with baseout.cpp.
6dc1e63 Rewrite continued fraction output modes as OutputGenerators.
Repository: git://git.tartarus.org/simon/spigot.git
On the web: http://tartarus.org/~simon-git/gitweb/?p=spigot.git
Branch updated: master
Committer: Simon Tatham <anakin at pobox.com>
Date: 2015-05-01 19:57:31
commit 848fa4cc07f3c80fab66fd045945fd1d2a87221a
web diff http://tartarus.org/~simon-git/gitweb/?p=spigot.git;a=commitdiff;h=848fa4cc07f3c80fab66fd045945fd1d2a87221a;hp=a6e7c6536138d5e8cdae0e089fc74329b92373ae
Author: Simon Tatham <anakin at pobox.com>
Date: Fri May 1 19:21:13 2015 +0100
Refactor communication with baseout.cpp.
Previously I had BaseOutputGenerator be a completely opaque type
outside baseout.cpp, and provided three externally visible wrapper
functions taking a pointer to a BaseOutputGenerator whose purpose was
to call three of its methods without having to tediously expose the
whole class definition in the header file and break incremental
rebuilding.
I now realise that the marginally more sensible approach is to expose
an abstract base class containing a pure virtual function for each of
the three methods I want to be externally visible, and then derive
BaseOutputGenerator from that. That still hides all the implementation
detail, but now means I don't have to be quite so silly in the client
code elsewhere in the program.
Also, more importantly than the aesthetics, it means I can have other
derivatives of the new OutputGenerator class, defined in other files,
and treat them identically in main().
baseout.cpp | 39 ++++++++++++---------------------------
baseout.h | 34 +++++++++++++---------------------
main.cpp | 20 ++++++++++----------
python/pyspig.cpp | 36 ++++++++++++++++++------------------
spigot.h | 13 +++++++++++++
5 files changed, 66 insertions(+), 76 deletions(-)
commit 6dc1e63ea6838ee1aa86fa9a74fd5358a2ca13ad
web diff http://tartarus.org/~simon-git/gitweb/?p=spigot.git;a=commitdiff;h=6dc1e63ea6838ee1aa86fa9a74fd5358a2ca13ad;hp=848fa4cc07f3c80fab66fd045945fd1d2a87221a
Author: Simon Tatham <anakin at pobox.com>
Date: Fri May 1 19:43:32 2015 +0100
Rewrite continued fraction output modes as OutputGenerators.
Now that we've got the OutputGenerator base class, it actually makes
more sense to arrange that *every* output mode spigot has is
implemented by some subclass of it. All the modes not based on
BaseOutputGenerator have in common that they use the continued
fraction of the input number, either to output directly or to turn
into rational convergents (and then perhaps only print the last
convergent, in -R mode). So I've now introduced a subclass of
OutputGenerator that includes the same continued-fraction logic that
CfracGenerator uses, and passes it down to some concrete subclasses in
turn that do the same formatting that main() used to do directly.
This lets me simplify main() greatly - now we only have one switch on
the output mode, to decide what kind of OutputGenerator to construct,
and all the actual generation of output thereafter can use exactly the
same code that was previously shared by the base output modes. Also,
it lays groundwork for implementing tentative output in the continued
fraction modes (because now it will just be a matter of making the
get_tentative_output method return something).
CfracGenerator itself still exists, partly because the Python API uses
it, and also because it's still used in a few spigot internals as the
easiest way to get a number's integer part (having first ruled out
exactness hazards, of course).
A few small bug fixes come for free with this refactoring:
- -C now reports an error for a negative -d value
- -R reports an error for _any_ use of -d at all
- -R mode now honours -n.
Makefile.am | 5 +-
bi_gmp.h | 2 +
bi_internal.h | 30 +++++--
cfracout.cpp | 262 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
cfracout.h | 13 +++
main.cpp | 199 +++++++++++--------------------------------
spigot.h | 2 +
7 files changed, 354 insertions(+), 159 deletions(-)
More information about the tartarus-commits
mailing list