Whilst the basic ZOOM API is easy to use, zstream takes the ease of use one step further by providing an interface that will be immediately familiar to C++ programmers who have used iostreams and istream_iterators.
I've put both the ZOOM::zstream and ZOOM::zstream_iterator classes into the ZOOM namespace, which is perhaps not the best idea. Suggestions for an alternative namespace name would be welcome.
If you wanted to process every record in a result set, you might use code as follows:
ZOOM::connection conn ("localhost", 210); ZOOM::zstream zs (conn, simpleQuery ("ti=\"pendon\"")); ZOOM::record r; while (zs >> r) ProcessRecord (r);
You can use manipulators to change the record syntax and element set name for next record to be retrieved:
ZOOM::connection conn ("localhost", 210); ZOOM::zstream zs (conn, simpleQuery ("ti=\"pendon\"")); ZOOM::record r; // Ask for the first record as a full GRS-1 record. zs >> grs1 >> esn("F") >> r; // Ask for the next record as a brief MARC21 record. zs >> marc21 >> esn("B") >> r;
The manipulators set the record syntax and element set name for all subsequent records retrieved. Should a Z39.50 server not be able to deliver a record in the requested syntax or element set name, then the stream will be put into a failed state, ie fail() will return true. You must clear() the failure before you can retrieve further records (and you'll probably want to reset the syntax or element set name as well.)
ZOOM::connection conn ("localhost", 210); ZOOM::zstream zs (conn, simpleQuery ("ti=\"pendon\"")); ZOOM::zstream_iterator zit (zs); ZOOM::zstream_iterator eof; std::vector<ZOOM::record> vec (zit, eof);
If you wanted a list of all the rendered records in a result set then an algorithm and a function object along with a zstream_iterator can be used as follows:
struct render { std::string operator() (const ZOOM::record &r) { return r.render (); } }; ZOOM::connection conn ("localhost", 210); ZOOM::zstream zs (conn, simpleQuery ("ti=\"pendon\"")); ZOOM::zstream_iterator zit (zs); ZOOM::zstream_iterator eof; std::list<std::string> lst; std::transform (zit, eof, std::back_inserter (lst), render ());
Or perhaps you just want to blast the whole result set to standard out:
ZOOM::connection conn ("localhost", 210); ZOOM::zstream zs (conn, simpleQuery ("ti=\"pendon\"")); std::transform ( ZOOM::zstream_iterator (zs), ZOOM::zstream_iterator (), std::ostream_iterator<std::string> (std::cout, "\n"), std::mem_fun_ref (&ZOOM::record::render) );
1.4.3