VVContactRepository::mailingLabels
The invocation of the mailingLabels() member function on //18 above does most of the work in this tutorial. The source code of this member function, from the file conrep.cpp is shown here:
 
VVContactRepository&
VVContactRepository::mailingLabels (ostream& o,
const RWDBCriterion& criterion) //1
{
RWDBReader aReader = reader(criterion); //2
VVContact aContact; //3
while (aReader()) { //4
aReader >> aContact; //5
aContact.mailingLabel (o); //6
o << endl << endl; //7
}
return *this; //8
}
//1 This line defines the mailingLabels() member function for the class VVContactRepository. It receives an output stream as its first argument and an RWDBCriterion as its second argument.
//2 The reader() member function of the class VVContactRepository is invoked here. It receives an RWDBCriterion as its argument and returns an RWDBReader. This reader is associated with a stream of information coming from the server that returns only the records that match the criterion. The reader() method is described in detail in VVContactRepository::reader.
//3 The database table used in this tutorial has fields that match the instance variables in the class VVContact. This routine is about to start reading data from the table, and an instance of VVContact is a made-to-order place to store information from the table. This line creates an instance of VVContact to serve as a temporary variable for storing a single row from the table.
//4 A reader is like an iterator. It must be advanced to the next row. Invoking the reader with the operator() member function advances the reader to the next row. If there are no more rows, then operator() returns a zero value and the loop terminates.
//5 A reader is also like a stream. Here an entire row of data flows from the reader into the instance of VVContact. An explanation of this can be found in operator>>() for VVContact.
//6 Since the instance of VVContact is complete, its own member functions can be called. The mailingLabel() member function simply outputs the instance variables for this customer in a form acceptable to the U.S. Postal Service.
//7 The mailing labels need to be delimited in some manner, so we add two blank lines.
//8 This routine needs to return an instance of VVContactRepository, so it returns itself. At this point, destructors for the VVContact instance and the RWDBReader instance are called. There were no pending rows from the RWDBReader. If there were, they would have been quietly and automatically discarded.