Next: , Previous: The library_base const_iterator class, Up: Library framework



5.3.3 library internals

— Constructor: library::library (void);

Default constructs a library holding a NULL library_base pointer.

— Constructor: library::library (const string& filename);

This constructor attempts to automatically detect what type of library filename is, and create an appropriate library_base to interpret it. For a library type to be correctly auto-detected a function of type library::init_function must be registered with library::addtype. After constructing a library, the library::good function can be used see if auto-detection succeeded.

— Constructor: library::library (library_base* lb);

This constructor is provided to allow libraries the flexibility not to use the auto-detection mechanism. The argument, lb, must have allocated by new and gets deleted by the library's destructor. For more information on how to use this, see Alternative creation mechanisms.

— Typedef: typedef library_base* (* library::init_function ) (const string& filename);

Functions with this signature are used by the library construtor to attempt to load a library. Each derived library class that supports auto-detection should register a function of this signature with the library class by calling the library::addtype function. When these functions get called, filename is the name of the library file. If a library can read the file it should return a pointer to a class derived from library_base allocated with new; otherwise the function should return NULL.

— Function: static void library::addtype (library::init_function lt)

This is used to register a specific (derived) library class to the list of classes that can be auto-detected. This function is typically called by the static function registerlib in the derived classes.

— Typedef: typedef library_base::const_iterator library::const_iterator;
— Function: library::const_iterator library::begin (void) const;
— Function: library::const_iterator library::end (void) const;

If the library holds a library_base, these function call down to the corresponding functions on that, otherwise both functions return a default constructed const_iterator.

— Function: bool library_base::good (void) const;

This function returns true if the library is valid, and false otherwise.

— Function: virtual method library::load (const char* name, int stage) const;
— Function: virtual int library::dir (list<string>& result) const;
— Function: virtual int library::mdir (list<method>& result) const;
— Function: virtual bool library::writeable (void) const;
— Function: virtual bool library::save (const method& m);
— Function: virtual bool library::rename_method (const string& name1, const string& name2);
— Function: virtual bool library::remove (const string& name);

These functions all call down to the corresponding functions on the library_base; see The library_base class for details. They must not be called if library::good() is false.