A registry mapping keys to factory functions. More...
#include <factory.hh>
Classes | |
struct | bad_key |
Exception to indicate nonexistent key. More... | |
class | iterator |
Iterator for accessing client-supplied arbitrary data. More... | |
Public Types | |
typedef iterator | const_iterator |
Read-only iterators. More... | |
Static Public Member Functions | |
static bool | add (K k, F f, D d=null_type()) |
Register a factory and optional data. More... | |
static F | get_factory (K k) |
Retrieve the factory function for a class. More... | |
static D | get_data (K k) |
Retrieve the user-supplied arbitrary data for a class. More... | |
static const_iterator | begin () |
Obtain read-only iterator to first data item. More... | |
static const_iterator | end () |
Obtain read-only iterator to one past last data item. More... | |
static std::pair < const_iterator, const_iterator > | range () |
Pack begin and end iterators in an STL pair. More... | |
A registry mapping keys to factory functions.
This class implements a singleton map that holds the subclass factory functions (type F) for classes in a hierarchy identified by keys of type K. In addition to the factory functions, it can also hold arbitrary data of type D.
The factory functions are used by the factory class defined in this file. However, the optional arbitrary data is only held and can be used by client classes in whatever way they see fit. In minxlib, this is usually used for the pythonize functions; see event.hh (for example).
typedef iterator minxlib::factory_map< K, F, D >::const_iterator |
Read-only iterators.
This class's iterators are already read-only. Therefore, the const_iterator type is the same as the iterator type.
|
inlinestatic |
Register a factory and optional data.
k | The key identifying a class in some hierarchy. |
f | The factory function for the class identified by k. |
d | Optional data to be stored along with the class's factory. |
This function is meant to be used by subclasses in a class hierarchy that is to be instantiated with an object factory. The typical usage pattern would be for each subclass in the hierarchy to define a static bool data member and call this function in that data member's initializer.
|
static |
Obtain read-only iterator to first data item.
When some function wants to iterate over all the arbitrary data items supplied during the registration of the various subclass factories, it can request an iterator to the first item of the underlying sequence using this function.
|
static |
Obtain read-only iterator to one past last data item.
When some function wants to iterate over all the arbitrary data items supplied during the registration of the various subclass factories, it can request an iterator to one-past the last item of the underlying sequence using this function.
|
inlinestatic |
Retrieve the user-supplied arbitrary data for a class.
k | They key identifying the class whose user data we want. |
This function is meant to be called by clients so they can get the arbitrary data they supplied when registering their factories. Typically, however, clients will iterate over the map and use the data values through that process.
|
inlinestatic |
Retrieve the factory function for a class.
k | They key identifying the class whose factory we want. |
This function is meant to be called by the minxlib::factory class. Other clients should have little use for it.
|
inlinestatic |
Pack begin and end iterators in an STL pair.
This function is meant to be used in conjunction with BOOST_FOREACH. Here is an illustrative (albeit non-buildable) example: