[Xapian-tickets] [Xapian] #332: Avoid const_cast in matcher/queryoptimiser.cc
Xapian
nobody at xapian.org
Mon Feb 16 11:56:09 GMT 2009
#332: Avoid const_cast in matcher/queryoptimiser.cc
---------------------+------------------------------------------------------
Reporter: richard | Owner: olly
Type: defect | Status: new
Priority: normal | Milestone: 1.1.0
Component: Matcher | Version: SVN trunk
Severity: normal | Blockedby:
Platform: All | Blocking:
---------------------+------------------------------------------------------
Currently (as of revision [11838]), matcher/queryoptimiser.cc performs a
const_cast in order to produce a Database object from a "const
Xapian::Database::Internal". The Database object has various non-const
methods on it (notably, reopen() and close()) which must not be called on
the resulting Database object. The object is only supplied to
PostingSource subclasses (via the reset() method), so this is probably not
a problem in practice, but it would certainly be good to tidy this up,
somehow.
I've not come up with a good way to tidy it up, yet. One approach would
be a Database subclass which overrides the non-const methods of Database
to return errors - this would not be terribly tidy, but would at least
allow the API to ensure that non-const methods didn't get called on the
"const Xapian::Database::Internal" object.
Another approach would be to create a "DatabaseSnapshot" class, which
contains all the const methods of Database (which access a constant
version of the database). Then we could make Database into a subclass of
DatabaseSnapshot, or something along those lines.
Better ideas welcomed! Marking as 1.1.0 for now, in case the only
solution we can come up with involves breaking API somewhere.
--
Ticket URL: <http://trac.xapian.org/ticket/332>
Xapian <http://xapian.org/>
Xapian
More information about the Xapian-tickets
mailing list