From: Marco Costalba (mcostalba_at_[hidden])
Date: 2008-01-26 09:35:42
I have uploaded in Vault a new version of dynamic object factory that
I consider much cleaner and nicer then previous one.
Vault file name is factory_25_1_2008.zip
An object factory it's a facility that gives you an object of a given
class when requested to do so.
A dynamic object factory it's a factory where the class of object to
be created together with it's c'tor arguments are passed to the
factory as run-time variables, populated as example reading from a
file or listening on a net connection.
The main difference with a static factory is that the latter falls
short when at compile time there is not enough information about what
and how many objects will be instantiated at run-time because it
depends, typically, on some form of external information.
The aims of this dynamic factory implementation are
- Simplicity and clear code
- Flexibility in number and types of c'tor arguments
- Type safe both at compile time and run time
- Fall back on static factory behaviour when object information is
known at compile time. In this case query for object is 100% compile
time resolved with zero runtime overhead and with complete compile
time type checking
- Full mimic of native new operator, in particular implicit
conversions of c'tor arguments are fully supported according to C++
Tough factory would need some boost libraries I have implemented in
the included file util.hpp a (very) stripped down versions of the few
traits and type list facility needed. The goal is to let user to check
the factory without requiring boost although function names strictly
resembles the boost ones. A side effect is a greatly reduced compile
time (and very fast because factory is really small)
Factory in itself is 100% pure C++, absolutely no libraries are
required, even no libstd++, only local headers are used. Actually
test.cpp driver program uses <iostream> and <string> but just for the
Please read test.cpp for usage documentation, although I hope that
factory code is so simple that is self-documenting.
Finally I have tested with success factory implementation on gcc3.4,
gcc4.2, Intel 10.1, MSVC 2008 and even Comeau C++ Online :-) versions
4.3.1 and later.
Of course comments are welcomed.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk