OgreNewt without boost

rride

09-08-2011 11:11:26

In our project we are not using boost and not even going to do so. OgreNewt uses only boost::function, boost::bind, boost::shared_ptr which are already available in STL for the latest compilers. So I propose to use this patch that will allow you to compile wrapper's code with MSVS 2010 without using the boost.


Index: OgreNewt_Prerequisites.h
===================================================================
--- OgreNewt_Prerequisites.h (revision 2984)
+++ OgreNewt_Prerequisites.h (working copy)
@@ -46,12 +46,30 @@
#endif

#include <Newton.h>
-#include <boost/function.hpp>
-#include <boost/bind.hpp>
-#ifndef OGRENEWT_NO_COLLISION_SHAREDPTR
-# include <boost/shared_ptr.hpp>
+
+#if defined(OGRENEWT_USE_BOOST) || !defined(WIN32) || !defined(_MSC_VER) || _MSC_VER < 1600
+# define OGRENEWT_IMPORTED_NAMESPACE boost
+# include <boost/function.hpp>
+# include <boost/bind.hpp>
+# ifndef OGRENEWT_NO_COLLISION_SHAREDPTR
+# include <boost/shared_ptr.hpp>
+# endif
+#else
+# define OGRENEWT_IMPORTED_NAMESPACE std
+# include <functional>
#endif

+namespace OgreNewt
+{
+ using OGRENEWT_IMPORTED_NAMESPACE::function;
+ using OGRENEWT_IMPORTED_NAMESPACE::bind;
+# ifndef OGRENEWT_NO_COLLISION_SHAREDPTR
+ using OGRENEWT_IMPORTED_NAMESPACE::shared_ptr;
+# endif
+}
+
+#undef OGRENEWT_IMPORTED_NAMESPACE
+
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
# define _CDECL _cdecl
# if defined( _OGRENEWT_EXPORTS ) && defined( _OGRENEWT_DYNAMIC )
@@ -108,7 +126,7 @@
* This function is called, when the object is destroyed. It's only argument is a pointer to the instance currently destroyed
* @warning the pointer to the destroyed class instance is already invalid (the class is already destroyed!)
*/
- typedef boost::function<void(DerivedClass*)> DestructorCallbackFunction;
+ typedef OgreNewt::function<void(DerivedClass*)> DestructorCallbackFunction;

//! constructor
_DestructorCallback() : m_callback(NULL) {}
@@ -130,9 +148,9 @@
* or a static member function, you can simply pass a pointer to the function here.. like this:
* setDestructorCallback( &myCallbackFunction );
*
- * If you want to bind to a class member, you also need to pass a pointer to the class itself, using the boost::bind system, like so:
- * setDestructorCallback( boost::bind( &MyClass::myCallback, (MyClass*)classInstance, _1 ) ); (from outside the class) or:
- * setDestructorCallback( boost::bind( &MyClass::myCallback, this, _1 ) ); (from inside the class).
+ * If you want to bind to a class member, you also need to pass a pointer to the class itself, using the OgreNewt::bind system, like so:
+ * setDestructorCallback( OgreNewt::bind( &MyClass::myCallback, (MyClass*)classInstance, _1 ) ); (from outside the class) or:
+ * setDestructorCallback( OgreNewt::bind( &MyClass::myCallback, this, _1 ) ); (from inside the class).
*
* You can also use:
* setDestructorCallback<>( &MyClass::myCallback, (MyClass*)classInstance ); (from outside the class) or:
@@ -141,9 +159,9 @@
*
*/
void setDestructorCallback( DestructorCallbackFunction fun ) { m_callback = fun; }
- template<class c> void setDestructorCallback( boost::function<void(c*, DerivedClass*)> callback, c *instancedClassPointer )
+ template<class c> void setDestructorCallback( OgreNewt::function<void(c*, DerivedClass*)> callback, c *instancedClassPointer )
{
- setDestructorCallback( boost::bind(callback, instancedClassPointer, _1) );
+ setDestructorCallback( OgreNewt::bind(callback, instancedClassPointer, _1) );
}
private:
DestructorCallbackFunction m_callback;
Index: OgreNewt_Body.h
===================================================================
--- OgreNewt_Body.h (revision 2984)
+++ OgreNewt_Body.h (working copy)
@@ -44,9 +44,9 @@
gravity, etc.

You can set this as the custom force callback for a body by using the setCustomForceCallback() function.
- Using boost::function means OgreNewt can now accept pointers to member functions of specific classes.
+ Using OgreNewt::function means OgreNewt can now accept pointers to member functions of specific classes.
*/
- typedef boost::function<void(OgreNewt::Body*, float timeStep, int threadIndex)> ForceCallback;
+ typedef OgreNewt::function<void(OgreNewt::Body*, float timeStep, int threadIndex)> ForceCallback;


//! node update notify.
@@ -56,9 +56,9 @@
The application can use this function to re calculate relative position of child nodes, or any other depended transform.

You can set this as the by using the setnNodeUpdateNotify() function.
- Using boost::function means OgreNewt can now accept pointers to member functions of specific classes.
+ Using OgreNewt::function means OgreNewt can now accept pointers to member functions of specific classes.
*/
- typedef boost::function<void(OgreNewt::Body*)> NodeUpdateNotifyCallback;
+ typedef OgreNewt::function<void(OgreNewt::Body*)> NodeUpdateNotifyCallback;


#if 0
@@ -70,8 +70,8 @@
create your own for special cases. you are passed a quaternion (orientation) and vector (position) of the rigid body
in world space.
*/
- //typedef boost::function<void(OgreNewt::Body*, const Ogre::Quaternion&, const Ogre::Vector3&, int threadIndex)> TransformCallback;
- //typedef boost::function<void(OgreNewt::Body*, int threadIndex)> TransformCallback;
+ //typedef OgreNewt::function<void(OgreNewt::Body*, const Ogre::Quaternion&, const Ogre::Vector3&, int threadIndex)> TransformCallback;
+ //typedef OgreNewt::function<void(OgreNewt::Body*, int threadIndex)> TransformCallback;
#endif


@@ -84,7 +84,7 @@
ignore buoyancy for this collision primitive, just return false from the function. otherwise, fill the "retPlane" with your
liquid surface plane, and return true to apply buoyancy to the primitive.
*/
- typedef boost::function<bool(int, OgreNewt::Body*, const Ogre::Quaternion&, const Ogre::Vector3&, Ogre::Plane&)> buoyancyPlaneCallback;
+ typedef OgreNewt::function<bool(int, OgreNewt::Body*, const Ogre::Quaternion&, const Ogre::Vector3&, Ogre::Plane&)> buoyancyPlaneCallback;

//! constructor.
/*!
@@ -159,9 +159,9 @@
This specifies a custom callback to use for applying forces to a body. if you are using a standard non-member function, or a static member function, you can simply pass a pointer to the function here.. like this:
setCustomForceAndTorqueCallback( &myCallbackFunction );

- If you want to bind to a class member, you also need to pass a pointer to the class itself, using the boost::bind system, like so:
- setCustomForceAndTorqueCallback( boost::bind( &MyClass::myCallback, (MyClass*)classInstance, _1 ) ); (from outside the class) or:
- setCustomForceAndTorqueCallback( boost::bind( &MyClass::myCallback, this, _1 ) ); (from inside the class).
+ If you want to bind to a class member, you also need to pass a pointer to the class itself, using the OgreNewt::bind system, like so:
+ setCustomForceAndTorqueCallback( OgreNewt::bind( &MyClass::myCallback, (MyClass*)classInstance, _1 ) ); (from outside the class) or:
+ setCustomForceAndTorqueCallback( OgreNewt::bind( &MyClass::myCallback, this, _1 ) ); (from inside the class).

You can also use:
setCustomForceAndTorqueCallback<>( &MyClass::myCallback, (MyClass*)classInstance ); (from outside the class) or:
@@ -169,9 +169,9 @@
Note: Notice the "<>" after the function name.
*/
void setCustomForceAndTorqueCallback( ForceCallback callback );
- template<class c> void setCustomForceAndTorqueCallback( boost::function<void(c*, Body*, float, int)> callback, c *instancedClassPointer )
+ template<class c> void setCustomForceAndTorqueCallback( OgreNewt::function<void(c*, Body*, float, int)> callback, c *instancedClassPointer )
{
- setCustomForceAndTorqueCallback( boost::bind(callback, instancedClassPointer, _1, _2, _3) );
+ setCustomForceAndTorqueCallback( OgreNewt::bind(callback, instancedClassPointer, _1, _2, _3) );
}

//! remove any force callbacks.
@@ -190,9 +190,9 @@
Control joints like the vehicle an drag dolls use the function to calculate the correct matrix of wheels and body parts.
*/
void setNodeUpdateNotify (NodeUpdateNotifyCallback callback );
- template<class c> void setNodeUpdateNotify (boost::function<void(c*, OgreNewt::Body*)> callback, c *instancedClassPointer )
+ template<class c> void setNodeUpdateNotify (OgreNewt::function<void(c*, OgreNewt::Body*)> callback, c *instancedClassPointer )
{
- setNodeUpdateNotify( boost::bind(callback, instancedClassPointer, _1) );
+ setNodeUpdateNotify( OgreNewt::bind(callback, instancedClassPointer, _1) );
}

//! remove any transform callbacks.
@@ -422,9 +422,9 @@
\param buoyancyPlaneCallback user function that returns the plane equation for the fluid at the current location. pass NULL to assume the body is fully immersed in fluid. see the setCustomForceAndTorqueCallback() docs to info on how to bind class member functions.
*/
void addBouyancyForce( Ogre::Real fluidDensity, Ogre::Real fluidLinearViscosity , Ogre::Real fluidAngularViscosity , const Ogre::Vector3& gravity, buoyancyPlaneCallback callback );
- template<class c> void addBouyancyForce( Ogre::Real fluidDensity, Ogre::Real fluidLinearViscosity , Ogre::Real fluidAngularViscosity , const Ogre::Vector3& gravity, boost::function<bool(c*, int, Body*, const Ogre::Quaternion&, const Ogre::Vector3&, Ogre::Plane&)> callback, c *instancedClassPointer )
+ template<class c> void addBouyancyForce( Ogre::Real fluidDensity, Ogre::Real fluidLinearViscosity , Ogre::Real fluidAngularViscosity , const Ogre::Vector3& gravity, OgreNewt::function<bool(c*, int, Body*, const Ogre::Quaternion&, const Ogre::Vector3&, Ogre::Plane&)> callback, c *instancedClassPointer )
{
- addBouyancyForce( fluidDensity, fluidLinearViscosity, fluidAngularViscosity, gravity, boost::bind(callback, instancedClassPointer, _1, _2, _3, _4, _5) );
+ addBouyancyForce( fluidDensity, fluidLinearViscosity, fluidAngularViscosity, gravity, OgreNewt::bind(callback, instancedClassPointer, _1, _2, _3, _4, _5) );
}


Index: OgreNewt_BodyInAABBIterator.h
===================================================================
--- OgreNewt_BodyInAABBIterator.h (revision 2984)
+++ OgreNewt_BodyInAABBIterator.h (working copy)
@@ -34,7 +34,7 @@
/*!
This function will be called for every body iterated. you can put any functionality you might want inside this function.
*/
- typedef boost::function<void(const Body*, void* userdata)> IteratorCallback;
+ typedef OgreNewt::function<void(const Body*, void* userdata)> IteratorCallback;

//! perform an iteration
/*!
@@ -43,9 +43,9 @@
\warning you cannot call this functions from different threads at the same time
*/
void go( const Ogre::AxisAlignedBox &aabb, IteratorCallback callback, void* userdata) const;
- template <class c> void go( const Ogre::AxisAlignedBox &aabb, boost::function<void(c*, Body*)> callback, c* instancedClassPointer ) const
+ template <class c> void go( const Ogre::AxisAlignedBox &aabb, OgreNewt::function<void(c*, Body*)> callback, c* instancedClassPointer ) const
{
- go ( aabb, boost::bind(callback, instancedClassPointer, _1) );
+ go ( aabb, OgreNewt::bind(callback, instancedClassPointer, _1) );
}

protected:
Index: OgreNewt_Collision.h
===================================================================
--- OgreNewt_Collision.h (revision 2984)
+++ OgreNewt_Collision.h (working copy)
@@ -160,8 +160,8 @@
typedef Collision* CollisionPtr;
typedef ConvexCollision* ConvexCollisionPtr;
#else
-typedef boost::shared_ptr<Collision> CollisionPtr;
-typedef boost::shared_ptr<ConvexCollision> ConvexCollisionPtr;
+typedef OgreNewt::shared_ptr<Collision> CollisionPtr;
+typedef OgreNewt::shared_ptr<ConvexCollision> ConvexCollisionPtr;
#endif


Index: OgreNewt_stdafx.h
===================================================================
--- OgreNewt_stdafx.h (revision 2984)
+++ OgreNewt_stdafx.h (working copy)
@@ -38,12 +38,8 @@
#include <dQuaternion.h>
#include <NewtonCustomJoint.h>

- #include <boost/function.hpp>
- #include <boost/bind.hpp>
-
- #ifndef OGRENEWT_NO_COLLISION_SHAREDPTR
- # include <boost/shared_ptr.hpp>
- #endif
-
+
+ #include "OgreNewt_Prerequisites.h"
+
#endif

Index: OgreNewt_World.h
===================================================================
--- OgreNewt_World.h (revision 2984)
+++ OgreNewt_World.h (working copy)
@@ -85,7 +85,7 @@

callback binding to member classes is exactly the same as the various callbacks for the Body class.
*/
- typedef boost::function<void(OgreNewt::Body*, int threadIndex)>
+ typedef OgreNewt::function<void(OgreNewt::Body*, int threadIndex)>
LeaveWorldCallback;

public:
@@ -354,10 +354,10 @@
sets the callback to be used when a Body leaves the World limits.
*/
void setLeaveWorldCallback(LeaveWorldCallback callback);
- template<class c> void setLeaveWorldCallback(boost::function<void(
+ template<class c> void setLeaveWorldCallback(OgreNewt::function<void(
c*, Body*, int)> callback, c *instancedClassPointer)
{
- setLeaveWorldCallback(boost::bind(callback,
+ setLeaveWorldCallback(OgreNewt::bind(callback,
instancedClassPointer, _1, _2));
}