[ZOOM] pointers

Ashley Sanders zzaascs at irwell.mimas.ac.uk
Thu Nov 1 12:44:57 CET 2001


> I may be in trouble for my lack of STL knowledge. But if you'd
> like a pointer to a resultSet you can do that with new operator (on the
> constructor or resultSet). What I'm saying is that if you want them
> you can have them. If want a local object you can do that too.

Okay, by changing

  resultSet *rs = c->search(q); 
  resultSet *rs = new resultSet(c, q);

we can have both ways. Fair enough -- if Mike is willing to
change the spec.  It also opens up the way for defining
operator[], so you could say

  resultSet rs (c, q);
  const record *rec = rs[0];

Which brings us on to who owns the record objects. I would like
them to be owned by the resultSet unless copied using clone() (or
some other method.) Mike, are you suggesting that every time I
get a record with getRecord() that it returns a new object that I
have to delete when I've finished with it?

So, if I want to print the title of each record in a
result set I have to do:

   for (size_t sz = 0; sz < rs.size (); ++sz)
        record *ps = rs.getRecord (sz);
        cout << ps->field ("title") << endl;
        delete ps;

whereas, if getRecord() returned a const pointer to a record
owned by the resultSet, I could just say:

   for (size_t sz = 0; sz < rs.size (); ++sz)
      cout << rs.getRecord (sz)->field ("title") << endl;

What am I missing this time?


Mike, I don't think a searchStatic() function should be
considered at all.

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 mailing list