[ZOOM] Re: zoom.hh

Mike Taylor mike at tecc.co.uk
Thu Nov 29 10:49:15 CET 2001

> Date: Wed, 28 Nov 2001 17:52:57 +0000
> From: Ashley Sanders <zzaascs at irwell.mimas.ac.uk>
> If getRecord() is returning a reference to a record, then to get
> your own copy of that record, something like the following is
> needed.
>   try
>     {
>       SUTRSRecord sMyOwnCopy =
>          dynamic_cast<const SUTRSRecord &>(sResultSet.getRecord (0));
>       cout << sMyOwnCopy.render () << endl;
>     }
>   catch (bad_cast)
>     {
>       cerr << "oops, wasn't a SUTRS record" << endl;
>     }

Hmm.  Speaking as a C programmer: Bleuuuururuuugughghchg!

> 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.

Indeed.  I guess that's how I imagined it working -- so the
dynamic_cast monstrosity is really just another level of paranoia that
people can employ if they wish, but isn't needed to write correct ZOOM
C++ code.  OK, that's not so awful then.

> 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.

Again, the reason you might want this is if the resultSet object is
transient, so the record is supposed to live longer than it.  For
example, if you were writing a Zthes browsing application, you might
want a function that returns the record with a specified termId:
[WARNING: untested code ahead!]

	record *recordByTermId(conncetion *conn, char *termId) {
	    char buf[100];
	    sprintf(buf, "@attr util 1=4 \"%s\"", termId);
	    resultSet rs(conn, RPNQuery(buf));
	    return rs.getRecord(0);
	    // ... and rs is automatically destructed

I have the sense that we're going around in circles a bit here!

 _/|_	 _______________________________________________________________
/o ) \/  Mike Taylor   <mike at miketaylor.org.uk>   www.miketaylor.org.uk
)_v__/\  "If you really want to be a writer, develop calluses on your
	 pride" -- Adrian Bedford.

More information about the ZOOM mailing list