Bullet and Namespaces
Posted: Sat Nov 05, 2011 10:21 pm
Hi Erwin,
I know in the past the use of namespaces has been rejected as adding unnecessary complications for library users but I'd like to explain a use case where this is proving a problem.
One of the advantages of using Bullet is being able to modify the library itself to support specific requirements. However, if a modified Bullet is used to build a plugin for another application (eg. Houdini) this will cause issues if another plugin then links against it's own static build of Bullet. In the forthcoming Houdini 12, Sidefx are packaging their own Bullet based plugin, and the concern is this will clash with our own build.
In an ideal world, it would be possible to specify the namespace used by bullet as a compile time option so that multiple differing builds can safely coexist. So something like:
#ifdef BTUSENAMESPACE
#define BTNAMESPACE Bullet
#define BTNAMESPACEBEGIN namespace BTNAMESPACE {
#define BTNAMESPACEEND }
#define BTNAMESPACEUSING using namespace BTNAMESPACE;
#else
#define BTNAMESPACEBEGIN
#define BTNAMESPACEEND
#define BTNAMESPACEUSING
#endif
Then surround all headers with BTNAMESPACEBEGIN/BTNAMESPACEND and put BTNAMESPACEUSING at the top of implementation files. That way the default behaviour would be to still not use namespaces but it would also be simple to create a safely namespaced custom build.
Unfortunately the layout of some of the headers at the moment mean it won't be simple to automatically add this with a script (predeclaring bullet classes before includes), so there would need to be some tidying up first. I'd like to know if this is an approach you'd be interested in adopting.
Cheers.
I know in the past the use of namespaces has been rejected as adding unnecessary complications for library users but I'd like to explain a use case where this is proving a problem.
One of the advantages of using Bullet is being able to modify the library itself to support specific requirements. However, if a modified Bullet is used to build a plugin for another application (eg. Houdini) this will cause issues if another plugin then links against it's own static build of Bullet. In the forthcoming Houdini 12, Sidefx are packaging their own Bullet based plugin, and the concern is this will clash with our own build.
In an ideal world, it would be possible to specify the namespace used by bullet as a compile time option so that multiple differing builds can safely coexist. So something like:
#ifdef BTUSENAMESPACE
#define BTNAMESPACE Bullet
#define BTNAMESPACEBEGIN namespace BTNAMESPACE {
#define BTNAMESPACEEND }
#define BTNAMESPACEUSING using namespace BTNAMESPACE;
#else
#define BTNAMESPACEBEGIN
#define BTNAMESPACEEND
#define BTNAMESPACEUSING
#endif
Then surround all headers with BTNAMESPACEBEGIN/BTNAMESPACEND and put BTNAMESPACEUSING at the top of implementation files. That way the default behaviour would be to still not use namespaces but it would also be simple to create a safely namespaced custom build.
Unfortunately the layout of some of the headers at the moment mean it won't be simple to automatically add this with a script (predeclaring bullet classes before includes), so there would need to be some tidying up first. I'd like to know if this is an approach you'd be interested in adopting.
Cheers.