[ZOOM] Re: zoom.hh
zzaascs at irwell.mimas.ac.uk
Wed Nov 28 18:52:57 CET 2001
> So I do think we're going to be using references in a lot of places,
> despite my loathing of them. ("foo&" indeed! Pah!)
> So we seem to be agreed that in some circumstances, we want records to
> be "owned" by their result sets, so that we don't have to bother
> explicitly freeing them; and in others, we want the records to be
> fully autonomous, so that we can return them from scopes in which they
> are obtained from transient result sets.
If getRecord() is returning a reference to a record, then to get
your own copy of that record, something like the following is needed.
SUTRSRecord sMyOwnCopy =
dynamic_cast<const SUTRSRecord &>(sResultSet.getRecord (0));
cout << sMyOwnCopy.render () << endl;
cerr << "oops, wasn't a SUTRS record" << endl;
Which I think isn't too cumbersome to write. I think that even if
we were using pointers, you'd still need the dynamic_cast. With
pointers you have to check for a null pointer returned from the
dynamic_cast. With references you have to catch an exception. If
you check the syntax of the record first (with the recsyn()
function) then you should be able to guarantee that you'd never
have to catch a bad_cast exception or look for a null pointer.
But really, I can't see a reason why you would want your own
copy of a record. The resultSet object is already a handy
container for keeping them in.
Ashley Sanders a.sanders at mcc.ac.uk
COPAC: A public bibliographic database from MIMAS, funded by JISC
http://copac.ac.uk/ - copac at mimas.ac.uk
More information about the ZOOM