The last step of implementing a library is to provide a class that implements
the library_entry::impl
interface, and most importantly, the
library_entry::impl::readentry
function. There are various possible
implementation strategies: the simplest is to get readentry
to parse
the whole of the library entry, store the name, place notation and so on in
data members, and then have the name
, pn
, etc. functions return
these. This is illustrated below:
class mylibrary : public library_base { class my_library::entry_type : public library_entry::impl { // Do a deep-copy of the entry virtual library_entry::impl* clone() const { return new entry_type(*this); } // Parse the entry virtual bool readentry( library_bas& lb ) { ifstream &ifs = dynamic_cast< cclib& >( lb ).ifs; if (!ifs) return false; // Have we reached the end of file? string entry; getline( ifs, entry ); // Assume the entry is in the format Method Name:Place Notation string::size_type p = linebuf.find(':'); name_ = string( entry, 0, p ); pn_ = string( entry, p+1, string::npos ); return true; } // Access parts of the entry virtual string name() const { return name_; } virtual string pn() const { return pn_; } string name_, pn_; }; ifstream ifs; };
An alternative implementation strategy would be to have readline
store
the whole line in data member (i.e. make entry a data member), and
then get name
and pn
to generate these on-the-fly from the
entry string.