Boost C++ Libraries

Next

Chapter 1. Factory

Tor Brede Vekterli

Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

Table of Contents

Overview
Introduction
Getting the code
Running the unit tests
Supported compilers
Known issues
Factory
Tutorial
Examples
Reference
Abstract Factory
Tutorial
Examples
Reference
Performance
Differences to Alexandrescu's Loki library
Change log
Acknowledgements

Documentation work in progress

The Factory library is an implementation of the factory patterns outlined by Andrei Alexandrescu in his book Modern C++ Design, but using Boost libraries and with several functional enhancements (for those familiar with the book and its patterns built on top of Loki, there is a section outlining the biggest differences between the two). Only concepts from Loki are used, there is no Loki code in this library.

This library comes with two different flavors of factory patterns, based on what the task at hand requires. They are both flexible and extensible through the use of optional policies, so it should be easy to adapt them to both generic and specific situations.

Patterns

Factory

For when you have a single abstract base types whose concrete classes you wish to instantiate at runtime based on some identifier.

Abstract Factory

For when you have multiple (possibly completely independent) abstract base classes whose concrete classes you wish to instantiate at runtime.

[Important] Important

This library has not been officially reviewed, and is not a part of Boost (at least not yet). As such, it is likely that parts of it will be changed around in the future if feedback and/or code issues warrant it. The name Boost.Factory is also not official

The current version of the code is 1.2.3 and can be downloaded from

http://arcticinteractive.com/static/upload/files/2010/01/factory_1_2_3.zip

Requires Boost libraries 1.37 or higher to compile (might work with Boost 1.36, but untested).

Any and all feedback, tips on code improvements etc. would be greatly appreciated!

[Tip] Tip

The library package follows the Boost conventions where the headers are located in the boost/factory subfolder, with documentation and unit tests in libs/factory. A copy of this documentation is located at libs/factory/doc/html/index.html

If you want to ensure the library works on your compiler, you can run the accompanying unit tests. Before running the unit tests, you must first ensure the BOOST_ROOT environment variable is set and Boost.Build has been set up (which should be the case if you've compiled Boost from source). Then you can simply cd into the libs/factory/test directory and run

bjam

Which should compile and run the two test files and hopefully pass them both. If they should happen to fail, feel free to contact me with the error log and compiler vendor/version and I'll take a look at it.

This library uses a lot of template metaprogramming and should require a conforming compiler. Currently only a very few compiler vendors/versions have been tested, so these lists will expand in the future

Compilers known to work:

  • Visual C++ 9.0, 10.0
  • GCC 3.4.4, 4.3.2
  • ICC 11.1

Compilers known not to work:

  • TODO, but probably many older compilers
  • Due to the amount of preprocessor work and number of template instantiations, compilation times can be fairly high. This appears to be more of an issue on GCC than Visual C++
  • The library does not yet support C++1x-specific features explicitly, but will as soon as the libraries it depends on do as well. Note: it should still be possible to use features like lambda with regular factories, as these are represented as anonymous function objects and require no particular support from the library at all. The C++1x limitations are primarily with a lack of support for perfect forwarding, although the current implementation gets around that in other ways.

Last revised: December 13, 2009 at 23:17:00 +0100


Next